-extending flat code compiler to a more general compiler -reducing all gates to multiplication gates only in the R1CS description of a program.pull/8/head
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<module type="WEB_MODULE" version="4"> |
||||
|
<component name="NewModuleRootManager"> |
||||
|
<content url="file://$MODULE_DIR$" /> |
||||
|
<orderEntry type="inheritedJdk" /> |
||||
|
<orderEntry type="sourceFolder" forTests="false" /> |
||||
|
</component> |
||||
|
</module> |
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project version="4"> |
||||
|
<component name="JavaScriptSettings"> |
||||
|
<option name="languageLevel" value="ES6" /> |
||||
|
</component> |
||||
|
</project> |
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project version="4"> |
||||
|
<component name="ProjectModuleManager"> |
||||
|
<modules> |
||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/go-snark.iml" filepath="$PROJECT_DIR$/.idea/go-snark.iml" /> |
||||
|
</modules> |
||||
|
</component> |
||||
|
</project> |
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project version="4"> |
||||
|
<component name="VcsDirectoryMappings"> |
||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" /> |
||||
|
</component> |
||||
|
</project> |
@ -0,0 +1,552 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project version="4"> |
||||
|
<component name="ChangeListManager"> |
||||
|
<list default="true" id="63e1f2c4-8982-42df-a3f2-1673aa7aec22" name="Default Changelist" comment="-initial commit, -extending flat code compiler to a more general compiler -reducing all gates to multiplication gates only in the R1CS description of a program."> |
||||
|
<change afterPath="$PROJECT_DIR$/.idea/go-snark.iml" afterDir="false" /> |
||||
|
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> |
||||
|
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" /> |
||||
|
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" /> |
||||
|
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> |
||||
|
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" /> |
||||
|
<change beforePath="$PROJECT_DIR$/circuitcompiler/Programm.go" beforeDir="false" afterPath="$PROJECT_DIR$/circuitcompiler/Programm.go" afterDir="false" /> |
||||
|
<change beforePath="$PROJECT_DIR$/circuitcompiler/Programm_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/circuitcompiler/Programm_test.go" afterDir="false" /> |
||||
|
<change beforePath="$PROJECT_DIR$/circuitcompiler/circuit.go" beforeDir="false" afterPath="$PROJECT_DIR$/circuitcompiler/circuit.go" afterDir="false" /> |
||||
|
<change beforePath="$PROJECT_DIR$/snark_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/snark_test.go" afterDir="false" /> |
||||
|
</list> |
||||
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> |
||||
|
<option name="SHOW_DIALOG" value="false" /> |
||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" /> |
||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> |
||||
|
<option name="LAST_RESOLUTION" value="IGNORE" /> |
||||
|
</component> |
||||
|
<component name="FileEditorManager"> |
||||
|
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> |
||||
|
<file pinned="false" current-in-tab="true"> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/Programm.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="325"> |
||||
|
<caret line="31" column="48" selection-start-line="31" selection-start-column="48" selection-end-line="31" selection-end-column="48" /> |
||||
|
<folding> |
||||
|
<element signature="e#25#92#0" expanded="true" /> |
||||
|
<element signature="n#!!block;n#addFunction#0" /> |
||||
|
</folding> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
</file> |
||||
|
<file pinned="false" current-in-tab="false"> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/Programm_test.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="318"> |
||||
|
<caret line="30" column="19" selection-start-line="30" selection-start-column="19" selection-end-line="30" selection-end-column="19" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
</file> |
||||
|
<file pinned="false" current-in-tab="false"> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/circuit.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="145"> |
||||
|
<caret line="91" selection-start-line="91" selection-end-line="91" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
</file> |
||||
|
<file pinned="false" current-in-tab="false"> |
||||
|
<entry file="file:///usr/local/go/src/testing/testing.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="193"> |
||||
|
<caret line="791" selection-start-line="791" selection-end-line="791" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
</file> |
||||
|
<file pinned="false" current-in-tab="false"> |
||||
|
<entry file="file:///usr/local/go/src/runtime/panic.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="185"> |
||||
|
<caret line="512" selection-start-line="512" selection-end-line="512" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
</file> |
||||
|
<file pinned="false" current-in-tab="false"> |
||||
|
<entry file="file:///usr/local/go/src/runtime/mbitmap.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="193"> |
||||
|
<caret line="910" selection-start-line="910" selection-end-line="910" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
</file> |
||||
|
<file pinned="false" current-in-tab="false"> |
||||
|
<entry file="file:///usr/local/go/src/runtime/malloc.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="193"> |
||||
|
<caret line="932" selection-start-line="932" selection-end-line="932" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
</file> |
||||
|
<file pinned="false" current-in-tab="false"> |
||||
|
<entry file="file://$PROJECT_DIR$/cli/main.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="225"> |
||||
|
<caret line="15" column="25" selection-start-line="15" selection-start-column="25" selection-end-line="15" selection-end-column="25" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
</file> |
||||
|
<file pinned="false" current-in-tab="false"> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/lexer.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="2715"> |
||||
|
<caret line="185" selection-start-line="185" selection-end-line="185" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
</file> |
||||
|
<file pinned="false" current-in-tab="false"> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/parser.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="163"> |
||||
|
<caret line="60" selection-start-line="60" selection-end-line="60" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
</file> |
||||
|
</leaf> |
||||
|
</component> |
||||
|
<component name="FindInProjectRecents"> |
||||
|
<findStrings> |
||||
|
<find>arnaucube</find> |
||||
|
<find>oneConst</find> |
||||
|
<find>getmain</find> |
||||
|
<find>opera</find> |
||||
|
</findStrings> |
||||
|
<replaceStrings> |
||||
|
<replace>mottla</replace> |
||||
|
</replaceStrings> |
||||
|
</component> |
||||
|
<component name="GOROOT" path="/usr/local/go" /> |
||||
|
<component name="Git.Settings"> |
||||
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> |
||||
|
</component> |
||||
|
<component name="GoLibraries"> |
||||
|
<option name="indexEntireGoPath" value="false" /> |
||||
|
</component> |
||||
|
<component name="IdeDocumentHistory"> |
||||
|
<option name="CHANGED_PATHS"> |
||||
|
<list> |
||||
|
<option value="$PROJECT_DIR$/bn128/bn128.go" /> |
||||
|
<option value="$PROJECT_DIR$/bn128/g1.go" /> |
||||
|
<option value="$PROJECT_DIR$/bn128/g2.go" /> |
||||
|
<option value="$PROJECT_DIR$/cli/main.go" /> |
||||
|
<option value="$PROJECT_DIR$/r1csqap/r1csqap.go" /> |
||||
|
<option value="$PROJECT_DIR$/r1csqap/r1csqap_test.go" /> |
||||
|
<option value="$PROJECT_DIR$/snark.go" /> |
||||
|
<option value="$PROJECT_DIR$/circuitcompiler/circuit_test.go" /> |
||||
|
<option value="$PROJECT_DIR$/circuitcompiler/lexer.go" /> |
||||
|
<option value="$PROJECT_DIR$/snark_test.go" /> |
||||
|
<option value="$PROJECT_DIR$/README.md" /> |
||||
|
<option value="$PROJECT_DIR$/circuitcompiler/parser.go" /> |
||||
|
<option value="$PROJECT_DIR$/circuitcompiler/temp" /> |
||||
|
<option value="$PROJECT_DIR$/circuitcompiler/Programm_test.go" /> |
||||
|
<option value="$PROJECT_DIR$/circuitcompiler/circuit.go" /> |
||||
|
<option value="$PROJECT_DIR$/circuitcompiler/Programm.go" /> |
||||
|
</list> |
||||
|
</option> |
||||
|
</component> |
||||
|
<component name="ProjectFrameBounds" extendedState="6"> |
||||
|
<option name="x" value="65" /> |
||||
|
<option name="y" value="-4" /> |
||||
|
<option name="width" value="1855" /> |
||||
|
<option name="height" value="1012" /> |
||||
|
</component> |
||||
|
<component name="ProjectView"> |
||||
|
<navigator proportions="" version="1"> |
||||
|
<foldersAlwaysOnTop value="true" /> |
||||
|
</navigator> |
||||
|
<panes> |
||||
|
<pane id="Scope" /> |
||||
|
<pane id="ProjectPane"> |
||||
|
<subPane> |
||||
|
<expand> |
||||
|
<path> |
||||
|
<item name="go-snark" type="b2602c69:ProjectViewProjectNode" /> |
||||
|
<item name="go-snark" type="462c0819:PsiDirectoryNode" /> |
||||
|
</path> |
||||
|
<path> |
||||
|
<item name="go-snark" type="b2602c69:ProjectViewProjectNode" /> |
||||
|
<item name="go-snark" type="462c0819:PsiDirectoryNode" /> |
||||
|
<item name="circuitcompiler" type="462c0819:PsiDirectoryNode" /> |
||||
|
</path> |
||||
|
<path> |
||||
|
<item name="go-snark" type="b2602c69:ProjectViewProjectNode" /> |
||||
|
<item name="go-snark" type="462c0819:PsiDirectoryNode" /> |
||||
|
<item name="cli" type="462c0819:PsiDirectoryNode" /> |
||||
|
</path> |
||||
|
</expand> |
||||
|
<select /> |
||||
|
</subPane> |
||||
|
</pane> |
||||
|
</panes> |
||||
|
</component> |
||||
|
<component name="PropertiesComponent"> |
||||
|
<property name="GO_FMT" value="true" /> |
||||
|
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" /> |
||||
|
<property name="WebServerToolWindowFactoryState" value="false" /> |
||||
|
<property name="go.gopath.indexing.explicitly.defined" value="true" /> |
||||
|
<property name="go.import.settings.migrated" value="true" /> |
||||
|
<property name="go.sdk.automatically.set" value="true" /> |
||||
|
<property name="last_opened_file_path" value="$PROJECT_DIR$/circuitcompiler" /> |
||||
|
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" /> |
||||
|
<property name="nodejs_npm_path_reset_for_default_project" value="true" /> |
||||
|
</component> |
||||
|
<component name="RecentsManager"> |
||||
|
<key name="CopyFile.RECENT_KEYS"> |
||||
|
<recent name="$PROJECT_DIR$/circuitcompiler" /> |
||||
|
</key> |
||||
|
</component> |
||||
|
<component name="RunDashboard"> |
||||
|
<option name="ruleStates"> |
||||
|
<list> |
||||
|
<RuleState> |
||||
|
<option name="name" value="ConfigurationTypeDashboardGroupingRule" /> |
||||
|
</RuleState> |
||||
|
<RuleState> |
||||
|
<option name="name" value="StatusDashboardGroupingRule" /> |
||||
|
</RuleState> |
||||
|
</list> |
||||
|
</option> |
||||
|
</component> |
||||
|
<component name="RunManager"> |
||||
|
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true"> |
||||
|
<module name="go-snark" /> |
||||
|
<working_directory value="$PROJECT_DIR$/circuitcompiler" /> |
||||
|
<framework value="gotest" /> |
||||
|
<kind value="PACKAGE" /> |
||||
|
<package value="github.com/mottla/go-snark/circuitcompiler" /> |
||||
|
<directory value="$PROJECT_DIR$/" /> |
||||
|
<filePath value="$PROJECT_DIR$/" /> |
||||
|
<pattern value="^TestNewProgramm$" /> |
||||
|
<method v="2" /> |
||||
|
</configuration> |
||||
|
<recent_temporary> |
||||
|
<list> |
||||
|
<item itemvalue="Go Test.TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" /> |
||||
|
</list> |
||||
|
</recent_temporary> |
||||
|
</component> |
||||
|
<component name="TestHistory"> |
||||
|
<history-entry file="TestNewProgramm_in_github_com_mottla_go-snark_circuitcompiler - 2019.05.13 at 18h 44m 54s.xml"> |
||||
|
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" configurationId="GoTestRunConfiguration" /> |
||||
|
</history-entry> |
||||
|
<history-entry file="TestNewProgramm_in_github_com_mottla_go-snark_circuitcompiler - 2019.05.13 at 18h 53m 19s.xml"> |
||||
|
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" configurationId="GoTestRunConfiguration" /> |
||||
|
</history-entry> |
||||
|
<history-entry file="TestNewProgramm_in_github_com_mottla_go-snark_circuitcompiler - 2019.05.13 at 19h 01m 05s.xml"> |
||||
|
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" configurationId="GoTestRunConfiguration" /> |
||||
|
</history-entry> |
||||
|
<history-entry file="TestNewProgramm_in_github_com_mottla_go-snark_circuitcompiler - 2019.05.13 at 19h 01m 16s.xml"> |
||||
|
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" configurationId="GoTestRunConfiguration" /> |
||||
|
</history-entry> |
||||
|
<history-entry file="TestNewProgramm_in_github_com_mottla_go-snark_circuitcompiler - 2019.05.13 at 19h 05m 45s.xml"> |
||||
|
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" configurationId="GoTestRunConfiguration" /> |
||||
|
</history-entry> |
||||
|
<history-entry file="TestNewProgramm_in_github_com_mottla_go-snark_circuitcompiler - 2019.05.13 at 19h 05m 47s.xml"> |
||||
|
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" configurationId="GoTestRunConfiguration" /> |
||||
|
</history-entry> |
||||
|
<history-entry file="TestNewProgramm_in_github_com_mottla_go-snark_circuitcompiler - 2019.05.13 at 19h 07m 14s.xml"> |
||||
|
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" configurationId="GoTestRunConfiguration" /> |
||||
|
</history-entry> |
||||
|
<history-entry file="TestNewProgramm_in_github_com_mottla_go-snark_circuitcompiler - 2019.05.13 at 19h 15m 18s.xml"> |
||||
|
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" configurationId="GoTestRunConfiguration" /> |
||||
|
</history-entry> |
||||
|
<history-entry file="TestNewProgramm_in_github_com_mottla_go-snark_circuitcompiler - 2019.05.13 at 19h 16m 13s.xml"> |
||||
|
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" configurationId="GoTestRunConfiguration" /> |
||||
|
</history-entry> |
||||
|
<history-entry file="TestNewProgramm_in_github_com_mottla_go-snark_circuitcompiler - 2019.05.13 at 19h 17m 48s.xml"> |
||||
|
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" configurationId="GoTestRunConfiguration" /> |
||||
|
</history-entry> |
||||
|
</component> |
||||
|
<component name="TodoView" selected-index="4"> |
||||
|
<todo-panel id="selected-file"> |
||||
|
<is-autoscroll-to-source value="true" /> |
||||
|
</todo-panel> |
||||
|
<todo-panel id="all"> |
||||
|
<are-packages-shown value="true" /> |
||||
|
<is-autoscroll-to-source value="true" /> |
||||
|
</todo-panel> |
||||
|
</component> |
||||
|
<component name="ToolWindowManager"> |
||||
|
<frame x="64" y="-11" width="1857" height="1020" extended-state="6" /> |
||||
|
<layout> |
||||
|
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.14206745" /> |
||||
|
<window_info id="Structure" order="1" side_tool="true" weight="0.25" /> |
||||
|
<window_info id="Favorites" order="2" side_tool="true" /> |
||||
|
<window_info anchor="bottom" id="Message" order="0" /> |
||||
|
<window_info anchor="bottom" id="Find" order="1" weight="0.32893288" /> |
||||
|
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32893288" /> |
||||
|
<window_info anchor="bottom" id="Debug" order="3" weight="0.39933994" /> |
||||
|
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> |
||||
|
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> |
||||
|
<window_info anchor="bottom" id="TODO" order="6" weight="0.19031903" /> |
||||
|
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" /> |
||||
|
<window_info anchor="bottom" id="Database Changes" order="8" /> |
||||
|
<window_info anchor="bottom" id="Version Control" order="9" /> |
||||
|
<window_info anchor="bottom" id="Terminal" order="10" /> |
||||
|
<window_info anchor="bottom" id="Event Log" order="11" side_tool="true" /> |
||||
|
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" /> |
||||
|
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" /> |
||||
|
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" /> |
||||
|
<window_info anchor="right" id="Database" order="3" /> |
||||
|
</layout> |
||||
|
</component> |
||||
|
<component name="TypeScriptGeneratedFilesManager"> |
||||
|
<option name="version" value="1" /> |
||||
|
</component> |
||||
|
<component name="VcsManagerConfiguration"> |
||||
|
<MESSAGE value="-initial commit, -extending flat code compiler to a more general compiler -reducing all gates to multiplication gates only in the R1CS description of a program." /> |
||||
|
<option name="LAST_COMMIT_MESSAGE" value="-initial commit, -extending flat code compiler to a more general compiler -reducing all gates to multiplication gates only in the R1CS description of a program." /> |
||||
|
</component> |
||||
|
<component name="XDebuggerManager"> |
||||
|
<breakpoint-manager> |
||||
|
<breakpoints> |
||||
|
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> |
||||
|
<url>file://$PROJECT_DIR$/circuitcompiler/Programm.go</url> |
||||
|
<line>75</line> |
||||
|
<properties /> |
||||
|
<option name="timeStamp" value="2" /> |
||||
|
</line-breakpoint> |
||||
|
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> |
||||
|
<url>file://$PROJECT_DIR$/circuitcompiler/Programm.go</url> |
||||
|
<line>82</line> |
||||
|
<properties /> |
||||
|
<option name="timeStamp" value="3" /> |
||||
|
</line-breakpoint> |
||||
|
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> |
||||
|
<url>file://$PROJECT_DIR$/circuitcompiler/Programm.go</url> |
||||
|
<line>66</line> |
||||
|
<properties /> |
||||
|
<option name="timeStamp" value="4" /> |
||||
|
</line-breakpoint> |
||||
|
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> |
||||
|
<url>file://$PROJECT_DIR$/circuitcompiler/parser.go</url> |
||||
|
<line>60</line> |
||||
|
<properties /> |
||||
|
<option name="timeStamp" value="10" /> |
||||
|
</line-breakpoint> |
||||
|
</breakpoints> |
||||
|
</breakpoint-manager> |
||||
|
</component> |
||||
|
<component name="editorHistoryManager"> |
||||
|
<entry file="file://$PROJECT_DIR$/bn128/bn128.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="90"> |
||||
|
<caret line="6" column="25" selection-start-line="6" selection-start-column="25" selection-end-line="6" selection-end-column="25" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/bn128/bn128_test.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state> |
||||
|
<folding> |
||||
|
<element signature="e#15#96#0" expanded="true" /> |
||||
|
</folding> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/bn128/g1.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="16"> |
||||
|
<caret line="5" column="25" selection-start-line="5" selection-start-column="25" selection-end-line="5" selection-end-column="25" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/bn128/g1_test.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor" /> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/bn128/g2.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="16"> |
||||
|
<caret line="5" column="25" selection-start-line="5" selection-start-column="25" selection-end-line="5" selection-end-column="25" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/bn128/g2_test.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor" /> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/fields/fq.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="-59" /> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/fields/fq2.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="-59" /> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/fields/fq6.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="-59" /> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/fields/fq12.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="-59" /> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/fields/fqn_test.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="-59" /> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/.gitignore"> |
||||
|
<provider selected="true" editor-type-id="text-editor" /> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/build-cli.sh"> |
||||
|
<provider selected="true" editor-type-id="text-editor" /> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/go.mod"> |
||||
|
<provider selected="true" editor-type-id="text-editor" /> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/go.sum"> |
||||
|
<provider selected="true" editor-type-id="text-editor" /> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/snark_test.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="-72"> |
||||
|
<caret line="5" column="25" selection-start-line="5" selection-start-column="25" selection-end-line="5" selection-end-column="25" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/snark.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="91"> |
||||
|
<caret line="10" column="25" selection-start-line="10" selection-start-column="25" selection-end-line="10" selection-end-column="25" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/r1csqap/r1csqap_test.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="-13"> |
||||
|
<caret line="7" column="25" selection-start-line="7" selection-start-column="25" selection-end-line="7" selection-end-column="25" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/r1csqap/r1csqap.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="-28"> |
||||
|
<caret line="6" column="25" selection-start-line="6" selection-start-column="25" selection-end-line="6" selection-end-column="25" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/r1csqap/README.md"> |
||||
|
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]"> |
||||
|
<state split_layout="SPLIT"> |
||||
|
<first_editor /> |
||||
|
<second_editor /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/README.md"> |
||||
|
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]"> |
||||
|
<state split_layout="SPLIT"> |
||||
|
<first_editor relative-caret-position="135"> |
||||
|
<caret line="9" column="19" selection-start-line="9" selection-start-column="19" selection-end-line="9" selection-end-column="19" /> |
||||
|
</first_editor> |
||||
|
<second_editor /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/circuit_test.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="1815"> |
||||
|
<caret line="128" selection-start-line="128" selection-end-line="128" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/lexer.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="2715"> |
||||
|
<caret line="185" selection-start-line="185" selection-end-line="185" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/cli/main.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="225"> |
||||
|
<caret line="15" column="25" selection-start-line="15" selection-start-column="25" selection-end-line="15" selection-end-column="25" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file:///usr/local/go/src/runtime/mbitmap.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="193"> |
||||
|
<caret line="910" selection-start-line="910" selection-end-line="910" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file:///usr/local/go/src/runtime/malloc.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="193"> |
||||
|
<caret line="932" selection-start-line="932" selection-end-line="932" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/temp"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="15"> |
||||
|
<caret line="1" selection-start-line="1" selection-end-line="1" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file:///usr/local/go/src/testing/testing.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="193"> |
||||
|
<caret line="791" selection-start-line="791" selection-end-line="791" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file:///usr/local/go/src/runtime/panic.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="185"> |
||||
|
<caret line="512" selection-start-line="512" selection-end-line="512" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/parser.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="163"> |
||||
|
<caret line="60" selection-start-line="60" selection-end-line="60" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/Programm_test.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="318"> |
||||
|
<caret line="30" column="19" selection-start-line="30" selection-start-column="19" selection-end-line="30" selection-end-column="19" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/circuit.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="145"> |
||||
|
<caret line="91" selection-start-line="91" selection-end-line="91" /> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
<entry file="file://$PROJECT_DIR$/circuitcompiler/Programm.go"> |
||||
|
<provider selected="true" editor-type-id="text-editor"> |
||||
|
<state relative-caret-position="325"> |
||||
|
<caret line="31" column="48" selection-start-line="31" selection-start-column="48" selection-end-line="31" selection-end-column="48" /> |
||||
|
<folding> |
||||
|
<element signature="e#25#92#0" expanded="true" /> |
||||
|
<element signature="n#!!block;n#addFunction#0" /> |
||||
|
</folding> |
||||
|
</state> |
||||
|
</provider> |
||||
|
</entry> |
||||
|
</component> |
||||
|
</project> |
@ -0,0 +1,382 @@ |
|||||
|
package circuitcompiler |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"github.com/mottla/go-snark/r1csqap" |
||||
|
"math/big" |
||||
|
) |
||||
|
|
||||
|
type Program struct { |
||||
|
functions map[string]*Circuit |
||||
|
signals []string |
||||
|
globalInputs []*Constraint |
||||
|
R1CS struct { |
||||
|
A [][]*big.Int |
||||
|
B [][]*big.Int |
||||
|
C [][]*big.Int |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (p *Program) PrintContraintTrees() { |
||||
|
for k, v := range p.functions { |
||||
|
fmt.Println(k) |
||||
|
PrintTree(v.root) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (p *Program) BuildConstraintTrees() { |
||||
|
|
||||
|
functionRootMap := make(map[string]*gate) |
||||
|
for _, circuit := range p.functions { |
||||
|
circuit.addConstraint(p.oneConstraint()) |
||||
|
fName := composeNewFunction(circuit.Name, circuit.Inputs) |
||||
|
root := &gate{value: circuit.constraintMap[fName]} |
||||
|
functionRootMap[fName] = root |
||||
|
circuit.root = root |
||||
|
} |
||||
|
|
||||
|
for _, circuit := range p.functions { |
||||
|
|
||||
|
buildTree(circuit.constraintMap, circuit.root) |
||||
|
|
||||
|
} |
||||
|
|
||||
|
return |
||||
|
|
||||
|
} |
||||
|
|
||||
|
func buildTree(con map[string]*Constraint, g *gate) { |
||||
|
if _, ex := con[g.value.Out]; ex { |
||||
|
if g.OperationType()&(IN|CONST) != 0 { |
||||
|
return |
||||
|
} |
||||
|
} else { |
||||
|
panic(fmt.Sprintf("undefined variable %s", g.value.Out)) |
||||
|
} |
||||
|
if g.OperationType() == FUNC { |
||||
|
g.funcInputs = []*gate{} |
||||
|
for _, in := range g.value.Inputs { |
||||
|
if constr, ex := con[in]; ex { |
||||
|
newGate := &gate{value: constr} |
||||
|
g.funcInputs = append(g.funcInputs, newGate) |
||||
|
buildTree(con, newGate) |
||||
|
} else { |
||||
|
panic(fmt.Sprintf("undefined value %s", g.value.V1)) |
||||
|
} |
||||
|
} |
||||
|
return |
||||
|
} |
||||
|
if constr, ex := con[g.value.V1]; ex { |
||||
|
g.addLeft(constr) |
||||
|
buildTree(con, g.left) |
||||
|
} else { |
||||
|
panic(fmt.Sprintf("undefined value %s", g.value.V1)) |
||||
|
} |
||||
|
|
||||
|
if constr, ex := con[g.value.V2]; ex { |
||||
|
g.addRight(constr) |
||||
|
buildTree(con, g.right) |
||||
|
} else { |
||||
|
panic(fmt.Sprintf("undefined value %s", g.value.V2)) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (p *Program) ReduceCombinedTree() (orderedmGates []gate) { |
||||
|
mGatesUsed := make(map[string]bool) |
||||
|
orderedmGates = []gate{} |
||||
|
functionRootMap := make(map[string]*gate) |
||||
|
for k, v := range p.functions { |
||||
|
functionRootMap[k] = v.root |
||||
|
} |
||||
|
|
||||
|
functionRenamer := func(c *Constraint) *gate { |
||||
|
|
||||
|
if c.Op != FUNC { |
||||
|
panic("not a function") |
||||
|
} |
||||
|
if b, name, in := isFunction(c.Out); b { |
||||
|
|
||||
|
if k, v := p.functions[name]; v { |
||||
|
//fmt.Println("unrenamed thing")
|
||||
|
//PrintTree(k.root)
|
||||
|
k.renameInputs(in) |
||||
|
//fmt.Println("renamed thing")
|
||||
|
//PrintTree(k.root)
|
||||
|
return k.root |
||||
|
} |
||||
|
} else { |
||||
|
panic("not a function dude") |
||||
|
} |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
traverseCombinedMultiplicationGates(p.getMainCircut().root, mGatesUsed, &orderedmGates, functionRootMap, functionRenamer, false, false) |
||||
|
|
||||
|
//for _, g := range mGates {
|
||||
|
// orderedmGates[len(orderedmGates)-1-g.index] = g
|
||||
|
//}
|
||||
|
|
||||
|
return orderedmGates |
||||
|
} |
||||
|
|
||||
|
func traverseCombinedMultiplicationGates(root *gate, mGatesUsed map[string]bool, orderedmGates *[]gate, functionRootMap map[string]*gate, functionRenamer func(c *Constraint) *gate, negate bool, inverse bool) { |
||||
|
//if root == nil {
|
||||
|
// return
|
||||
|
//}
|
||||
|
if root.OperationType() == FUNC { |
||||
|
//if a input has already been built, we let this subroutine know
|
||||
|
newMap := make(map[string]bool) |
||||
|
for _, in := range root.funcInputs { |
||||
|
|
||||
|
if _, ex := mGatesUsed[in.value.Out]; ex { |
||||
|
newMap[in.value.Out] = true |
||||
|
} else { |
||||
|
traverseCombinedMultiplicationGates(in, mGatesUsed, orderedmGates, functionRootMap, functionRenamer, negate, inverse) |
||||
|
} |
||||
|
} |
||||
|
//mGatesUsed[root.value.Out] = true
|
||||
|
traverseCombinedMultiplicationGates(functionRenamer(root.value), newMap, orderedmGates, functionRootMap, functionRenamer, negate, inverse) |
||||
|
} else { |
||||
|
if _, alreadyComputed := mGatesUsed[root.value.V1]; !alreadyComputed && root.OperationType()&(IN|CONST) == 0 { |
||||
|
traverseCombinedMultiplicationGates(root.left, mGatesUsed, orderedmGates, functionRootMap, functionRenamer, negate, inverse) |
||||
|
} |
||||
|
|
||||
|
if _, alreadyComputed := mGatesUsed[root.value.V2]; !alreadyComputed && root.OperationType()&(IN|CONST) == 0 { |
||||
|
traverseCombinedMultiplicationGates(root.right, mGatesUsed, orderedmGates, functionRootMap, functionRenamer, Xor(negate, root.value.negate), Xor(inverse, root.value.invert)) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if root.OperationType() == MULTIPLY { |
||||
|
|
||||
|
root.leftIns = make(map[string]int) |
||||
|
collectAtomsInSubtree(root.left, root.leftIns, functionRootMap, negate, inverse) |
||||
|
root.rightIns = make(map[string]int) |
||||
|
collectAtomsInSubtree(root.right, root.rightIns, functionRootMap, Xor(negate, root.value.negate), Xor(inverse, root.value.invert)) |
||||
|
root.index = len(mGatesUsed) |
||||
|
mGatesUsed[root.value.Out] = true |
||||
|
rootGate := cloneGate(root) |
||||
|
*orderedmGates = append(*orderedmGates, *rootGate) |
||||
|
} |
||||
|
|
||||
|
//TODO optimize if output is not a multipication gate
|
||||
|
} |
||||
|
|
||||
|
//copies a gate neglecting its references to other gates
|
||||
|
func cloneGate(in *gate) (out *gate) { |
||||
|
constr := &Constraint{Inputs: in.value.Inputs, Out: in.value.Out, Op: in.value.Op, invert: in.value.invert, negate: in.value.negate, V2: in.value.V2, V1: in.value.V1} |
||||
|
nRightins := make(map[string]int) |
||||
|
nLeftInst := make(map[string]int) |
||||
|
for k, v := range in.rightIns { |
||||
|
nRightins[k] = v |
||||
|
} |
||||
|
for k, v := range in.leftIns { |
||||
|
nLeftInst[k] = v |
||||
|
} |
||||
|
return &gate{value: constr, leftIns: nLeftInst, rightIns: nRightins, index: in.index} |
||||
|
} |
||||
|
|
||||
|
func (p *Program) getMainCircut() *Circuit { |
||||
|
return p.functions["main"] |
||||
|
} |
||||
|
|
||||
|
func (p *Program) addGlobalInput(c *Constraint) { |
||||
|
p.globalInputs = append(p.globalInputs, c) |
||||
|
} |
||||
|
|
||||
|
func NewProgramm() *Program { |
||||
|
return &Program{functions: map[string]*Circuit{}, signals: []string{}, globalInputs: []*Constraint{{Op: CONST, Out: "one"}}} |
||||
|
} |
||||
|
|
||||
|
func (p *Program) oneConstraint() *Constraint { |
||||
|
if p.globalInputs[0].Out != "one" { |
||||
|
panic("'one' should be first global input") |
||||
|
} |
||||
|
return p.globalInputs[0] |
||||
|
} |
||||
|
|
||||
|
func (p *Program) addSignal(name string) { |
||||
|
p.signals = append(p.signals, name) |
||||
|
} |
||||
|
|
||||
|
func (p *Program) addFunction(constraint *Constraint) (c *Circuit) { |
||||
|
name := constraint.Out |
||||
|
fmt.Println("try to add function ", name) |
||||
|
|
||||
|
b, name2, _ := isFunction(name) |
||||
|
if !b { |
||||
|
panic(fmt.Sprintf("not a function: %v", constraint)) |
||||
|
} |
||||
|
name = name2 |
||||
|
|
||||
|
if _, ex := p.functions[name]; ex { |
||||
|
panic("function already declared") |
||||
|
} |
||||
|
|
||||
|
c = newCircuit(name) |
||||
|
|
||||
|
p.functions[name] = c |
||||
|
|
||||
|
//if constraint.Literal == "main" {
|
||||
|
for _, in := range constraint.Inputs { |
||||
|
newConstr := &Constraint{ |
||||
|
Op: IN, |
||||
|
Out: in, |
||||
|
} |
||||
|
if name == "main" { |
||||
|
p.addGlobalInput(newConstr) |
||||
|
} |
||||
|
c.addConstraint(newConstr) |
||||
|
} |
||||
|
|
||||
|
c.Inputs = constraint.Inputs |
||||
|
return |
||||
|
|
||||
|
} |
||||
|
|
||||
|
// GenerateR1CS generates the R1CS polynomials from the Circuit
|
||||
|
func (p *Program) GenerateReducedR1CS(mGates []gate) (a, b, c [][]*big.Int) { |
||||
|
// from flat code to R1CS
|
||||
|
|
||||
|
offset := len(p.globalInputs) |
||||
|
// one + in1 +in2+... + gate1 + gate2 .. + out
|
||||
|
size := offset + len(mGates) |
||||
|
indexMap := make(map[string]int) |
||||
|
|
||||
|
//circ.Signals = []string{"one"}
|
||||
|
for i, v := range p.globalInputs { |
||||
|
indexMap[v.Out] = i |
||||
|
//circ.Signals = append(circ.Signals, v)
|
||||
|
|
||||
|
} |
||||
|
for i, v := range mGates { |
||||
|
indexMap[v.value.Out] = i + offset |
||||
|
//circ.Signals = append(circ.Signals, v.value.Out)
|
||||
|
} |
||||
|
//circ.NVars = len(circ.Signals)
|
||||
|
//circ.NSignals = len(circ.Signals)
|
||||
|
|
||||
|
for _, gate := range mGates { |
||||
|
|
||||
|
if gate.OperationType() == MULTIPLY { |
||||
|
aConstraint := r1csqap.ArrayOfBigZeros(size) |
||||
|
bConstraint := r1csqap.ArrayOfBigZeros(size) |
||||
|
cConstraint := r1csqap.ArrayOfBigZeros(size) |
||||
|
|
||||
|
for leftInput, val := range gate.leftIns { |
||||
|
insertVar3(aConstraint, val, leftInput, indexMap[leftInput]) |
||||
|
} |
||||
|
for rightInput, val := range gate.rightIns { |
||||
|
insertVar3(bConstraint, val, rightInput, indexMap[rightInput]) |
||||
|
} |
||||
|
cConstraint[indexMap[gate.value.Out]] = big.NewInt(int64(1)) |
||||
|
|
||||
|
if gate.value.invert { |
||||
|
a = append(a, cConstraint) |
||||
|
b = append(b, bConstraint) |
||||
|
c = append(c, aConstraint) |
||||
|
} else { |
||||
|
a = append(a, aConstraint) |
||||
|
b = append(b, bConstraint) |
||||
|
c = append(c, cConstraint) |
||||
|
} |
||||
|
|
||||
|
} else { |
||||
|
panic("not a m gate") |
||||
|
} |
||||
|
} |
||||
|
p.R1CS.A = a |
||||
|
p.R1CS.B = b |
||||
|
p.R1CS.C = c |
||||
|
return a, b, c |
||||
|
} |
||||
|
|
||||
|
func insertVar3(arr []*big.Int, val int, input string, index int) { |
||||
|
isVal, value := isValue(input) |
||||
|
var valueBigInt *big.Int |
||||
|
if isVal { |
||||
|
valueBigInt = big.NewInt(int64(value)) |
||||
|
arr[0] = new(big.Int).Add(arr[0], valueBigInt) |
||||
|
} else { |
||||
|
//if !indexMap[leftInput] {
|
||||
|
// panic(errors.New("using variable before it's set"))
|
||||
|
//}
|
||||
|
valueBigInt = big.NewInt(int64(val)) |
||||
|
arr[index] = new(big.Int).Add(arr[index], valueBigInt) |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
func (p *Program) CalculateWitness(input []*big.Int) (witness []*big.Int) { |
||||
|
|
||||
|
if len(p.globalInputs)-1 != len(input) { |
||||
|
panic("input do not match the required inputs") |
||||
|
} |
||||
|
|
||||
|
witness = r1csqap.ArrayOfBigZeros(len(p.R1CS.A[0])) |
||||
|
set := make([]bool, len(witness)) |
||||
|
witness[0] = big.NewInt(int64(1)) |
||||
|
set[0] = true |
||||
|
|
||||
|
for i := range input { |
||||
|
witness[i+1] = input[i] |
||||
|
set[i+1] = true |
||||
|
} |
||||
|
|
||||
|
zero := big.NewInt(int64(0)) |
||||
|
|
||||
|
for i := 0; i < len(p.R1CS.A); i++ { |
||||
|
gatesLeftInputs := p.R1CS.A[i] |
||||
|
gatesRightInputs := p.R1CS.B[i] |
||||
|
gatesOutputs := p.R1CS.C[i] |
||||
|
|
||||
|
sumLeft := big.NewInt(int64(0)) |
||||
|
sumRight := big.NewInt(int64(0)) |
||||
|
sumOut := big.NewInt(int64(0)) |
||||
|
|
||||
|
index := -1 |
||||
|
division := false |
||||
|
for j, val := range gatesLeftInputs { |
||||
|
if val.Cmp(zero) != 0 { |
||||
|
if !set[j] { |
||||
|
index = j |
||||
|
division = true |
||||
|
break |
||||
|
} |
||||
|
sumLeft.Add(sumLeft, new(big.Int).Mul(val, witness[j])) |
||||
|
} |
||||
|
} |
||||
|
for j, val := range gatesRightInputs { |
||||
|
if val.Cmp(zero) != 0 { |
||||
|
sumRight.Add(sumRight, new(big.Int).Mul(val, witness[j])) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
for j, val := range gatesOutputs { |
||||
|
if val.Cmp(zero) != 0 { |
||||
|
if !set[j] { |
||||
|
if index != -1 { |
||||
|
panic("invalid R1CS form") |
||||
|
} |
||||
|
|
||||
|
index = j |
||||
|
break |
||||
|
} |
||||
|
sumOut.Add(sumOut, new(big.Int).Mul(val, witness[j])) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if !division { |
||||
|
set[index] = true |
||||
|
witness[index] = new(big.Int).Mul(sumLeft, sumRight) |
||||
|
|
||||
|
} else { |
||||
|
b := sumRight.Int64() |
||||
|
c := sumOut.Int64() |
||||
|
set[index] = true |
||||
|
witness[index] = big.NewInt(c / b) |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
return |
||||
|
} |
@ -0,0 +1,78 @@ |
|||||
|
package circuitcompiler |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"math/big" |
||||
|
"strings" |
||||
|
"testing" |
||||
|
) |
||||
|
|
||||
|
func TestProgramm_BuildConstraintTree(t *testing.T) { |
||||
|
line := "asdf asfd" |
||||
|
line = strings.TrimFunc(line, func(i rune) bool { return isWhitespace(i) }) |
||||
|
fmt.Println(line) |
||||
|
} |
||||
|
|
||||
|
func TestNewProgramm(t *testing.T) { |
||||
|
|
||||
|
flat := ` |
||||
|
func do(x): |
||||
|
e = x * x |
||||
|
b = e * e |
||||
|
c = b * b |
||||
|
d = c * c |
||||
|
out = d * 1 |
||||
|
|
||||
|
func add(x ,k): |
||||
|
z = k * x |
||||
|
out = do(x) + mul(x,z) |
||||
|
|
||||
|
func main(a,b): |
||||
|
out = do(5) + 4 |
||||
|
|
||||
|
func mul(a,b): |
||||
|
out = a * b |
||||
|
` |
||||
|
|
||||
|
//flat := `
|
||||
|
//func do(x):
|
||||
|
// b = x - 2
|
||||
|
// out = x * b
|
||||
|
//func main(a,b):
|
||||
|
// out = do(a) + 4
|
||||
|
//`
|
||||
|
parser := NewParser(strings.NewReader(flat)) |
||||
|
program, err := parser.Parse() |
||||
|
|
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
fmt.Println("\n unreduced") |
||||
|
fmt.Println(flat) |
||||
|
|
||||
|
program.BuildConstraintTrees() |
||||
|
for k, v := range program.functions { |
||||
|
fmt.Println(k) |
||||
|
PrintTree(v.root) |
||||
|
} |
||||
|
|
||||
|
fmt.Println("\nReduced gates") |
||||
|
//PrintTree(froots["mul"])
|
||||
|
gates := program.ReduceCombinedTree() |
||||
|
for _, g := range gates { |
||||
|
fmt.Println(g) |
||||
|
} |
||||
|
|
||||
|
fmt.Println("generating R1CS") |
||||
|
a, b, c := program.GenerateReducedR1CS(gates) |
||||
|
fmt.Println(a) |
||||
|
fmt.Println(b) |
||||
|
fmt.Println(c) |
||||
|
a1 := big.NewInt(int64(6)) |
||||
|
a2 := big.NewInt(int64(5)) |
||||
|
inputs := []*big.Int{a1, a2} |
||||
|
w := program.CalculateWitness(inputs) |
||||
|
fmt.Println("witness") |
||||
|
fmt.Println(w) |
||||
|
|
||||
|
} |
@ -1,88 +1,128 @@ |
|||||
package circuitcompiler |
package circuitcompiler |
||||
|
|
||||
import ( |
import ( |
||||
"math/big" |
|
||||
"strings" |
|
||||
|
//"fmt"
|
||||
|
////"math/big"
|
||||
|
//"strings"
|
||||
"testing" |
"testing" |
||||
|
|
||||
"github.com/stretchr/testify/assert" |
"github.com/stretchr/testify/assert" |
||||
) |
) |
||||
|
|
||||
|
func TestXor(t *testing.T) { |
||||
|
assert.Equal(t, false, Xor(true, true)) |
||||
|
assert.Equal(t, true, Xor(true, false)) |
||||
|
assert.Equal(t, true, Xor(false, true)) |
||||
|
assert.Equal(t, false, Xor(false, false)) |
||||
|
|
||||
|
} |
||||
|
|
||||
func TestCircuitParser(t *testing.T) { |
func TestCircuitParser(t *testing.T) { |
||||
// y = x^3 + x + 5
|
|
||||
flat := ` |
|
||||
func test(private s0, public s1): |
|
||||
s2 = s0 * s0 |
|
||||
s3 = s2 * s0 |
|
||||
s4 = s3 + s0 |
|
||||
s5 = s4 + 5 |
|
||||
equals(s1, s5) |
|
||||
out = 1 * 1 |
|
||||
` |
|
||||
parser := NewParser(strings.NewReader(flat)) |
|
||||
circuit, err := parser.Parse() |
|
||||
assert.Nil(t, err) |
|
||||
|
|
||||
// flat code to R1CS
|
|
||||
a, b, c := circuit.GenerateR1CS() |
|
||||
assert.Equal(t, "s0", circuit.PrivateInputs[0]) |
|
||||
assert.Equal(t, "s1", circuit.PublicInputs[0]) |
|
||||
|
//flat := `
|
||||
|
//func main(a,b):
|
||||
|
// c = a / b
|
||||
|
// d = c * b
|
||||
|
// e = d - c
|
||||
|
// f = c * 55
|
||||
|
// out = f / e
|
||||
|
//`
|
||||
|
//flat := `
|
||||
|
//func test(a,b):
|
||||
|
// d = a / b
|
||||
|
// c = a + d
|
||||
|
// f = a * 55
|
||||
|
// g = a / d
|
||||
|
// h = g + f
|
||||
|
// i = c + h
|
||||
|
// out = i / c
|
||||
|
//`
|
||||
|
//parser := NewParser(strings.NewReader(flat))
|
||||
|
//programm, err := parser.Parse()
|
||||
|
//circuit := programm.getMainCircut()
|
||||
|
//assert.Nil(t, err)
|
||||
|
//fmt.Println("\n unreduced")
|
||||
|
//fmt.Println(flat)
|
||||
|
|
||||
assert.Equal(t, []string{"one", "s1", "s0", "s2", "s3", "s4", "s5", "out"}, circuit.Signals) |
|
||||
|
//fmt.Println("generating R1CS from flat code")
|
||||
|
//a, b, c := circuit.GenerateR1CS()
|
||||
|
//fmt.Println(a)
|
||||
|
//fmt.Println(b)
|
||||
|
//fmt.Println(c)
|
||||
|
//
|
||||
|
//a1 := big.NewInt(int64(6))
|
||||
|
//a2 := big.NewInt(int64(5))
|
||||
|
//inputs := []*big.Int{a1, a2}
|
||||
|
//// Calculate Witness
|
||||
|
//w, err := circuit.CalculateWitness(inputs)
|
||||
|
//assert.Nil(t, err)
|
||||
|
//fmt.Println("w", w)
|
||||
|
//fmt.Printf("inputs %s", circuit.Inputs)
|
||||
|
//fmt.Printf("signals %s", circuit.Signals)
|
||||
|
|
||||
// expected result
|
|
||||
b0 := big.NewInt(int64(0)) |
|
||||
b1 := big.NewInt(int64(1)) |
|
||||
b5 := big.NewInt(int64(5)) |
|
||||
aExpected := [][]*big.Int{ |
|
||||
[]*big.Int{b0, b0, b1, b0, b0, b0, b0, b0}, |
|
||||
[]*big.Int{b0, b0, b0, b1, b0, b0, b0, b0}, |
|
||||
[]*big.Int{b0, b0, b1, b0, b1, b0, b0, b0}, |
|
||||
[]*big.Int{b5, b0, b0, b0, b0, b1, b0, b0}, |
|
||||
[]*big.Int{b0, b0, b0, b0, b0, b0, b1, b0}, |
|
||||
[]*big.Int{b0, b1, b0, b0, b0, b0, b0, b0}, |
|
||||
[]*big.Int{b1, b0, b0, b0, b0, b0, b0, b0}, |
|
||||
} |
|
||||
bExpected := [][]*big.Int{ |
|
||||
[]*big.Int{b0, b0, b1, b0, b0, b0, b0, b0}, |
|
||||
[]*big.Int{b0, b0, b1, b0, b0, b0, b0, b0}, |
|
||||
[]*big.Int{b1, b0, b0, b0, b0, b0, b0, b0}, |
|
||||
[]*big.Int{b1, b0, b0, b0, b0, b0, b0, b0}, |
|
||||
[]*big.Int{b1, b0, b0, b0, b0, b0, b0, b0}, |
|
||||
[]*big.Int{b1, b0, b0, b0, b0, b0, b0, b0}, |
|
||||
[]*big.Int{b1, b0, b0, b0, b0, b0, b0, b0}, |
|
||||
} |
|
||||
cExpected := [][]*big.Int{ |
|
||||
[]*big.Int{b0, b0, b0, b1, b0, b0, b0, b0}, |
|
||||
[]*big.Int{b0, b0, b0, b0, b1, b0, b0, b0}, |
|
||||
[]*big.Int{b0, b0, b0, b0, b0, b1, b0, b0}, |
|
||||
[]*big.Int{b0, b0, b0, b0, b0, b0, b1, b0}, |
|
||||
[]*big.Int{b0, b1, b0, b0, b0, b0, b0, b0}, |
|
||||
[]*big.Int{b0, b0, b0, b0, b0, b0, b1, b0}, |
|
||||
[]*big.Int{b0, b0, b0, b0, b0, b0, b0, b1}, |
|
||||
} |
|
||||
|
//
|
||||
|
//fmt.Println("Reduced Tree Parsing")
|
||||
|
//r := circuit.BuildConstraintTree()
|
||||
|
//constraintReduced := ReduceTree(r)
|
||||
|
//fmt.Printf("depth %v, mGates %v \n", printDepth(r, 0), CountMultiplicationGates(r))
|
||||
|
//printTree(r, 0)
|
||||
|
//
|
||||
|
//a,b,c,w = circuit.GenerateReducedR1CSandWitness(inputs,constraintReduced)
|
||||
|
//fmt.Println("\ngenerating R1CS from reduced flat code")
|
||||
|
//fmt.Println("\nR1CS:")
|
||||
|
//fmt.Println("a:", a)
|
||||
|
//fmt.Println("b:", b)
|
||||
|
//fmt.Println("c:", c)
|
||||
|
//fmt.Println("w", w)
|
||||
|
|
||||
assert.Equal(t, aExpected, a) |
|
||||
assert.Equal(t, bExpected, b) |
|
||||
assert.Equal(t, cExpected, c) |
|
||||
|
//// R1CS to QAP
|
||||
|
//alphas, betas, gammas, zxQAP := fields.R1CSToQAP(a, b, c)
|
||||
|
//fmt.Println("qap")
|
||||
|
//fmt.Println("alphas", len(alphas))
|
||||
|
//fmt.Println("alphas", alphas[0])
|
||||
|
//fmt.Println("betas", len(betas))
|
||||
|
//fmt.Println("gammas", len(gammas))
|
||||
|
//fmt.Println("zx length", len(zxQAP))
|
||||
|
//circuit.reduceAdditionGates()
|
||||
|
//
|
||||
|
//fmt.Println(circuit)
|
||||
|
//fmt.Println("generating R1CS from flat code")
|
||||
|
//a, b, c = circuit.GenerateR1CS()
|
||||
|
//
|
||||
|
//fmt.Println(a)
|
||||
|
//fmt.Println(b)
|
||||
|
//fmt.Println(c)
|
||||
|
//
|
||||
|
//// Calculate Witness
|
||||
|
//w, err = circuit.CalculateWitness(inputs)
|
||||
|
//assert.Nil(t, err)
|
||||
|
//fmt.Println("w", w)
|
||||
|
|
||||
b3 := big.NewInt(int64(3)) |
|
||||
privateInputs := []*big.Int{b3} |
|
||||
b35 := big.NewInt(int64(35)) |
|
||||
publicInputs := []*big.Int{b35} |
|
||||
// Calculate Witness
|
|
||||
w, err := circuit.CalculateWitness(privateInputs, publicInputs) |
|
||||
assert.Nil(t, err) |
|
||||
b9 := big.NewInt(int64(9)) |
|
||||
b27 := big.NewInt(int64(27)) |
|
||||
b30 := big.NewInt(int64(30)) |
|
||||
wExpected := []*big.Int{b1, b35, b3, b9, b27, b30, b35, b1} |
|
||||
assert.Equal(t, wExpected, w) |
|
||||
|
//// expected result
|
||||
|
//b0 := big.NewInt(int64(0))
|
||||
|
//b1 := big.NewInt(int64(1))
|
||||
|
//b5 := big.NewInt(int64(5))
|
||||
|
//aExpected := [][]*big.Int{
|
||||
|
// []*big.Int{b0, b0, b1, b0, b0, b0},
|
||||
|
// []*big.Int{b0, b0, b0, b1, b0, b0},
|
||||
|
// []*big.Int{b0, b0, b1, b0, b1, b0},
|
||||
|
// []*big.Int{b5, b0, b0, b0, b0, b1},
|
||||
|
//}
|
||||
|
//bExpected := [][]*big.Int{
|
||||
|
// []*big.Int{b0, b0, b1, b0, b0, b0},
|
||||
|
// []*big.Int{b0, b0, b1, b0, b0, b0},
|
||||
|
// []*big.Int{b1, b0, b0, b0, b0, b0},
|
||||
|
// []*big.Int{b1, b0, b0, b0, b0, b0},
|
||||
|
//}
|
||||
|
//cExpected := [][]*big.Int{
|
||||
|
// []*big.Int{b0, b0, b0, b1, b0, b0},
|
||||
|
// []*big.Int{b0, b0, b0, b0, b1, b0},
|
||||
|
// []*big.Int{b0, b0, b0, b0, b0, b1},
|
||||
|
// []*big.Int{b0, b1, b0, b0, b0, b0},
|
||||
|
//}
|
||||
|
|
||||
// circuitJson, _ := json.Marshal(circuit)
|
|
||||
// fmt.Println("circuit:", string(circuitJson))
|
|
||||
|
//assert.Equal(t, aExpected, a)
|
||||
|
//assert.Equal(t, bExpected, b)
|
||||
|
//assert.Equal(t, cExpected, c)
|
||||
|
|
||||
assert.Equal(t, circuit.NPublic, 1) |
|
||||
assert.Equal(t, len(circuit.PublicInputs), 1) |
|
||||
assert.Equal(t, len(circuit.PrivateInputs), 1) |
|
||||
} |
} |