Browse Source

Preparing Pull Request

pull/8/head
mottla 5 years ago
parent
commit
0096fbcaff
18 changed files with 135 additions and 1136 deletions
  1. +0
    -8
      .idea/go-snark.iml
  2. +0
    -6
      .idea/misc.xml
  3. +0
    -8
      .idea/modules.xml
  4. +0
    -6
      .idea/vcs.xml
  5. +0
    -806
      .idea/workspace.xml
  6. +24
    -20
      README.md
  7. +1
    -1
      bn128/bn128.go
  8. +1
    -1
      bn128/g1.go
  9. +1
    -1
      bn128/g2.go
  10. +10
    -7
      circuitcompiler/Programm.go
  11. +19
    -15
      circuitcompiler/Programm_test.go
  12. +0
    -110
      circuitcompiler/circuit_test.go
  13. +32
    -15
      circuitcompiler/test.py
  14. +3
    -3
      cli/main.go
  15. +1
    -5
      r1csqap/r1csqap.go
  16. +1
    -63
      r1csqap/r1csqap_test.go
  17. +25
    -4
      snark.go
  18. +17
    -57
      snark_test.go

+ 0
- 8
.idea/go-snark.iml

@ -1,8 +0,0 @@
<?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
- 6
.idea/misc.xml

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>

+ 0
- 8
.idea/modules.xml

@ -1,8 +0,0 @@
<?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
- 6
.idea/vcs.xml

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 0
- 806
.idea/workspace.xml

@ -1,806 +0,0 @@
<?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="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/circuitcompiler/Programm.go" beforeDir="false" afterPath="$PROJECT_DIR$/circuitcompiler/Programm.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="false">
<entry file="file://$PROJECT_DIR$/circuitcompiler/Programm_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="615">
<caret line="46" column="5" selection-start-line="28" selection-start-column="4" selection-end-line="46" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/circuitcompiler/test.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="420">
<caret line="28" column="21" selection-start-line="28" selection-start-column="21" selection-end-line="28" selection-end-column="21" />
</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="11625">
<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="10140">
<caret line="680" selection-start-line="680" selection-end-line="680" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/circuitcompiler/Programm.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="224">
<caret line="527" column="5" lean-forward="true" selection-start-line="527" selection-start-column="5" selection-end-line="527" selection-end-column="5" />
<folding>
<element signature="n#!!block;n#mulFactors#0" />
<element signature="n#!!block;n#addFactors#0" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/circuitcompiler/circuit.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="284">
<caret line="156" lean-forward="true" selection-start-line="156" selection-end-line="156" />
</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="825">
<caret line="60" column="15" lean-forward="true" selection-start-line="60" selection-start-column="15" selection-end-line="60" selection-end-column="15" />
<folding>
<element signature="e#25#72#0" expanded="true" />
</folding>
</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="600">
<caret line="44" column="19" selection-start-line="44" selection-start-column="19" selection-end-line="44" selection-end-column="19" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/snark_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="330">
<caret line="30" column="15" selection-start-line="30" selection-start-column="15" selection-end-line="30" selection-end-column="15" />
<folding>
<element signature="e#15#188#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/snark.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="945">
<caret line="72" selection-start-line="72" selection-end-line="72" selection-end-column="26" />
<folding>
<element signature="e#15#208#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>arnaucube</find>
<find>oneConst</find>
<find>opera</find>
<find>getmain</find>
<find>one</find>
<find>oneCo</find>
<find>md</find>
<find>new</find>
<find>newpro</find>
<find>clone</find>
<find>newProg</find>
<find>func</find>
<find>global</find>
<find>globalin</find>
<find>newcir</find>
<find>newprogr</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_test.go" />
<option value="$PROJECT_DIR$/circuitcompiler/circuit_test.go" />
<option value="$PROJECT_DIR$/circuitcompiler/temp" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/../../go-lexer/lexer.go" />
<option value="$PROJECT_DIR$/circuitcompiler/lexer/lexer.go" />
<option value="$PROJECT_DIR$/circuitcompiler/lexer/lexer_test/lexer_test.go" />
<option value="$PROJECT_DIR$/snark.go" />
<option value="$PROJECT_DIR$/snark_test.go" />
<option value="$PROJECT_DIR$/r1csqap/r1csqap.go" />
<option value="$PROJECT_DIR$/circuitcompiler/lexer.go" />
<option value="$PROJECT_DIR$/circuitcompiler/parser.go" />
<option value="$PROJECT_DIR$/circuitcompiler/test.py" />
<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="611" />
<option name="y" value="52" />
<option name="width" value="1853" />
<option name="height" value="1004" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<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>
<path>
<item name="go-snark" type="b2602c69:ProjectViewProjectNode" />
<item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</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$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="restartRequiresConfirmation" value="false" />
<property name="settings.editor.selected.configurable" value="preferences.intentionPowerPack" />
</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" selected="Go Test.TestNewProgramm in github.com/mottla/go-snark/circuitcompiler">
<configuration name="TestGenerateProofs in github.com/mottla/go-snark" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="go-snark" />
<working_directory value="$PROJECT_DIR$" />
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/mottla/go-snark" />
<directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" />
<pattern value="^TestGenerateProofs$" />
<method v="2" />
</configuration>
<configuration name="TestNewProgramm in github.com/mottla/go-snark" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="go-snark" />
<working_directory value="$PROJECT_DIR$" />
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/mottla/go-snark" />
<directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" />
<pattern value="^TestNewProgramm$" />
<method v="2" />
</configuration>
<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>
<configuration name="TestProgramm_BuildConstraintTree 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="^TestProgramm_BuildConstraintTree$" />
<method v="2" />
</configuration>
<configuration name="test" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="go-snark" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/circuitcompiler" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/circuitcompiler/test.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="true" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Go Test.TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" />
<item itemvalue="Python.test" />
<item itemvalue="Go Test.TestProgramm_BuildConstraintTree in github.com/mottla/go-snark/circuitcompiler" />
<item itemvalue="Go Test.TestNewProgramm in github.com/mottla/go-snark" />
<item itemvalue="Go Test.TestGenerateProofs in github.com/mottla/go-snark" />
</list>
</recent_temporary>
</component>
<component name="TestHistory">
<history-entry file="TestNewProgramm_in_github_com_mottla_go-snark_circuitcompiler - 2019.05.28 at 10h 20m 04s.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.28 at 10h 20m 44s.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.28 at 10h 25m 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.28 at 10h 25m 15s.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.28 at 10h 28m 04s.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.28 at 10h 33m 25s.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.28 at 10h 39m 15s.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.28 at 10h 39m 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.28 at 10h 41m 23s.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.28 at 11h 03m 24s.xml">
<configuration name="TestNewProgramm in github.com/mottla/go-snark/circuitcompiler" configurationId="GoTestRunConfiguration" />
</history-entry>
</component>
<component name="TodoView">
<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="65" y="-4" width="1855" height="1012" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.19845219" />
<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.46314633" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.42244226" />
<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" weight="0.32893288" />
<window_info anchor="bottom" id="Terminal" order="10" weight="0.32893288" />
<window_info anchor="bottom" id="Event Log" order="11" side_tool="true" weight="0.32893288" />
<window_info anchor="bottom" id="Messages" order="12" weight="0.32993197" />
<window_info anchor="bottom" id="Inspection Results" order="13" weight="0.32893288" />
<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>
<layout-to-restore>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.15754561" />
<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.37623763" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.3984109" />
<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="bottom" id="Messages" order="12" />
<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-to-restore>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="-initial commit,&#10;-extending flat code compiler to a more general compiler&#10;-reducing all gates to multiplication gates only in the R1CS description of a program." />
<MESSAGE value="allow constants in function calls: like foo(5,a)&#10;-prepair constraints is now done during parsing" />
<MESSAGE value="reducing multiplication gates with constants" />
<MESSAGE value="optimizing R1CS representation" />
<MESSAGE value="cleaning up a bit" />
<MESSAGE value="working on multiplication gate reduction algo" />
<MESSAGE value="constraint is no longer a reference pointer" />
<MESSAGE value="new renaming logic preparations" />
<MESSAGE value="changing gate structure from entirely" />
<MESSAGE value="improved circuit compiling" />
<MESSAGE value="improved circuit compiling&#10;still not fully working" />
<option name="LAST_COMMIT_MESSAGE" value="improved circuit compiling&#10;still not fully working" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/circuitcompiler/parser.go</url>
<line>81</line>
<option name="timeStamp" value="12" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/circuitcompiler/parser.go</url>
<line>82</line>
<option name="timeStamp" value="13" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/circuitcompiler/parser.go</url>
<line>83</line>
<option name="timeStamp" value="14" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/r1csqap/r1csqap.go</url>
<line>228</line>
<option name="timeStamp" value="43" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/r1csqap/r1csqap.go</url>
<line>229</line>
<option name="timeStamp" value="44" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/r1csqap/r1csqap.go</url>
<line>83</line>
<option name="timeStamp" value="45" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/r1csqap/r1csqap.go</url>
<line>74</line>
<option name="timeStamp" value="46" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/snark_test.go</url>
<line>113</line>
<option name="timeStamp" value="47" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/r1csqap/r1csqap.go</url>
<line>135</line>
<option name="timeStamp" value="48" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/circuitcompiler/Programm.go</url>
<line>514</line>
<option name="timeStamp" value="172" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/circuitcompiler/Programm.go</url>
<line>218</line>
<option name="timeStamp" value="204" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/circuitcompiler/Programm.go</url>
<line>298</line>
<option name="timeStamp" value="220" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/circuitcompiler/Programm.go</url>
<line>325</line>
<option name="timeStamp" value="263" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<watches-manager>
<configuration name="GoTestRunConfiguration">
<watch expression="*(*&quot;map[string]bool&quot;)(824634576984)" />
<watch expression="mGatesUsed" />
</configuration>
</watches-manager>
</component>
<component name="editorHistoryManager">
<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/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$/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:///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" />
<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://$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://$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="90">
<caret line="6" column="74" selection-start-line="6" selection-start-column="74" selection-end-line="6" selection-end-column="74" />
</first_editor>
<second_editor />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/r1csqapFloat/r1csqapFloat_test.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/circuitcompiler/lexer/.idea/vcs.xml" />
<entry file="file://$PROJECT_DIR$/circuitcompiler/lexer/lexer.go" />
<entry file="file://$PROJECT_DIR$/circuitcompiler/lexer/lexer_test/lexer_test.go" />
<entry file="file:///usr/local/go/src/crypto/md5/md5.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2040">
<caret line="140" column="15" selection-start-line="140" selection-start-column="15" selection-end-line="140" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../go-lexer/lexer.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="5115">
<caret line="346" column="12" lean-forward="true" selection-start-line="346" selection-start-column="12" selection-end-line="346" selection-end-column="12" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/image/png/example_test.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file:///usr/local/go/src/image/png/reader_test.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file:///usr/local/go/src/mime/type_dragonfly.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file:///usr/local/go/src/math/big/int.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="293">
<caret line="101" column="14" selection-start-line="101" selection-start-column="14" selection-end-line="101" selection-end-column="14" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/go/token/token.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file:///usr/local/go/src/go/parser/short_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="482">
<caret line="131" column="32" lean-forward="true" selection-start-line="131" selection-start-column="32" selection-end-line="131" selection-end-column="32" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/image/png/testdata/benchGray.png">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file:///usr/local/go/src/image/png/testdata/benchNRGBA-gradient.png">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file:///usr/local/go/src/image/png/testdata/benchPaletted.png">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/fields/fq6.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file:///usr/local/go/src/math/abs.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="12" column="54" selection-start-line="12" selection-start-column="41" selection-end-line="12" selection-end-column="54" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/go/constant/value.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="8130">
<caret line="551" column="5" selection-start-line="551" selection-start-column="5" selection-end-line="551" selection-end-column="5" />
</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$/r1csqap/r1csqap_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="435">
<caret line="36" column="27" selection-start-line="36" selection-start-column="27" selection-end-line="36" selection-end-column="27" />
<folding>
<element signature="e#17#135#0" expanded="true" />
<element signature="n#!!block;n#TestPol#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/fields/fq2.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="75">
<caret line="7" column="7" selection-start-line="7" selection-start-column="7" selection-end-line="7" selection-end-column="7" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/bn128/bn128.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="193">
<caret line="18" column="25" selection-start-line="18" selection-start-column="25" selection-end-line="18" selection-end-column="25" />
<folding>
<element signature="e#15#85#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/fields/fq.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="990">
<caret line="70" column="13" selection-start-line="70" selection-start-column="13" selection-end-line="70" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/builtin/builtin.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="359">
<caret line="182" column="5" selection-start-line="182" selection-start-column="5" selection-end-line="182" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/strings/strings.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="4710">
<caret line="318" selection-start-line="318" selection-end-line="318" selection-end-column="80" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/r1csqap/r1csqap.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="315">
<caret line="27" column="30" lean-forward="true" selection-start-line="27" selection-start-column="30" selection-end-line="27" selection-end-column="30" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/runtime/asm_amd64.s">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="152">
<caret line="428" selection-start-line="428" selection-end-line="428" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circuitcompiler/Programm_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="615">
<caret line="46" column="5" selection-start-line="28" selection-start-column="4" selection-end-line="46" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circuitcompiler/test.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="420">
<caret line="28" column="21" selection-start-line="28" selection-start-column="21" selection-end-line="28" selection-end-column="21" />
</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="11625">
<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="10140">
<caret line="680" selection-start-line="680" selection-end-line="680" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circuitcompiler/parser.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="825">
<caret line="60" column="15" lean-forward="true" selection-start-line="60" selection-start-column="15" selection-end-line="60" selection-end-column="15" />
<folding>
<element signature="e#25#72#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circuitcompiler/lexer.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="600">
<caret line="44" column="19" selection-start-line="44" selection-start-column="19" selection-end-line="44" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/snark_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="330">
<caret line="30" column="15" selection-start-line="30" selection-start-column="15" selection-end-line="30" selection-end-column="15" />
<folding>
<element signature="e#15#188#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/snark.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="945">
<caret line="72" selection-start-line="72" selection-end-line="72" selection-end-column="26" />
<folding>
<element signature="e#15#208#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circuitcompiler/Programm.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="224">
<caret line="527" column="5" lean-forward="true" selection-start-line="527" selection-start-column="5" selection-end-line="527" selection-end-column="5" />
<folding>
<element signature="n#!!block;n#mulFactors#0" />
<element signature="n#!!block;n#addFactors#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circuitcompiler/circuit.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="284">
<caret line="156" lean-forward="true" selection-start-line="156" selection-end-line="156" />
</state>
</provider>
</entry>
</component>
</project>

+ 24
- 20
README.md

@ -14,27 +14,31 @@ Warning: not finished.
Working example of gate-reduction and code parsing:
```go
def do(x):
e = x * 5
b = e * 6
c = b * 7
f = c * 1
d = c * f
out = d * mul(d,e)
def doSomethingElse(x ,k):
z = k * x
out = do(x) + mul(x,z)
def main(x,z):
out = do(z) + doSomethingElse(x,x)
def mul(a,b):
out = a * b
e = x * 5
b = e * 6
c = b * 7
f = c * 1
d = c * f
out = d * mul(d,e)
def doSomethingElse(x ,k):
z = k * x
out = do(x) + mul(x,z)
def main(x,z):
out = do(z) + doSomethingElse(x,x)
def mul(a,b):
out = a * b
```
R1CS Output:
```go
[[0 0 210 0 0 0 0 0 0 0 0 0 0 0] [0 0 210 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 1 0 0 0 0 0 0 0 0 0] [0 0 0 1 0 0 0 0 0 0 0 0 0 0] [0 210 0 0 0 0 0 0 0 0 0 0 0 0] [0 210 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 1 0 0 0 0 0] [0 0 0 0 0 0 0 1 0 0 0 0 0 0] [0 1 0 0 0 0 0 0 0 0 0 0 0 0] [0 1 0 0 0 0 0 0 0 0 0 0 0 0] [1 0 0 0 0 0 0 0 0 0 0 0 0 0]]
[[0 0 210 0 0 0 0 0 0 0 0 0 0 0] [0 0 210 0 0 0 0 0 0 0 0 0 0 0] [0 0 5 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 1 0 0 0 0 0 0 0 0] [0 210 0 0 0 0 0 0 0 0 0 0 0 0] [0 210 0 0 0 0 0 0 0 0 0 0 0 0] [0 5 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 1 0 0 0 0] [0 1 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 1 0 0] [0 0 0 0 0 0 1 0 0 0 1 0 1 0]]
[[0 0 0 1 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 1 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 1 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 1 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 1 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 1 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 1 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 1 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 1 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 1 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 1]]
[[0 0 210 0 0 0 0 0 0 0 0 0] [0 0 0 1 0 0 0 0 0 0 0 0] [0 0 0 1 0 0 0 0 0 0 0 0] [0 210 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 1 0 0 0 0 0] [0 0 0 0 0 0 1 0 0 0 0 0] [0 1 0 0 0 0 0 0 0 0 0 0] [0 1 0 0 0 0 0 0 0 0 0 0] [1 0 0 0 0 0 0 0 0 0 0 0]]
[[0 0 210 0 0 0 0 0 0 0 0 0] [0 0 5 0 0 0 0 0 0 0 0 0] [0 0 0 0 1 0 0 0 0 0 0 0] [0 210 0 0 0 0 0 0 0 0 0 0] [0 5 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 1 0 0 0 0] [0 1 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 1 0 0] [0 0 0 0 0 1 0 0 1 0 1 0]]
[[0 0 0 1 0 0 0 0 0 0 0 0] [0 0 0 0 1 0 0 0 0 0 0 0] [0 0 0 0 0 1 0 0 0 0 0 0] [0 0 0 0 0 0 1 0 0 0 0 0] [0 0 0 0 0 0 0 1 0 0 0 0] [0 0 0 0 0 0 0 0 1 0 0 0] [0 0 0 0 0 0 0 0 0 1 0 0] [0 0 0 0 0 0 0 0 0 0 1 0] [0 0 0 0 0 0 0 0 0 0 0 1]]
input
[7 11]
witness
[1 7 11 5336100 293485500 1566067976550000 2160900 75631500 163432108350000 49 343 1729500084900343]
```
Note that we only need 11 multiplication Gates instead of 16
Note that we only need 9 multiplication Gates instead of 16

+ 1
- 1
bn128/bn128.go

@ -4,7 +4,7 @@ import (
"errors"
"math/big"
"github.com/mottla/go-snark/fields"
"github.com/arnaucube/go-snark/fields"
)
// Bn128 is the data structure of the BN128

+ 1
- 1
bn128/g1.go

@ -3,7 +3,7 @@ package bn128
import (
"math/big"
"github.com/mottla/go-snark/fields"
"github.com/arnaucube/go-snark/fields"
)
type G1 struct {

+ 1
- 1
bn128/g2.go

@ -3,7 +3,7 @@ package bn128
import (
"math/big"
"github.com/mottla/go-snark/fields"
"github.com/arnaucube/go-snark/fields"
)
type G2 struct {

+ 10
- 7
circuitcompiler/Programm.go

@ -3,9 +3,9 @@ package circuitcompiler
import (
"crypto/sha256"
"fmt"
"github.com/mottla/go-snark/bn128"
"github.com/mottla/go-snark/fields"
"github.com/mottla/go-snark/r1csqap"
"github.com/arnaucube/go-snark/bn128"
"github.com/arnaucube/go-snark/fields"
"github.com/arnaucube/go-snark/r1csqap"
"hash"
"math/big"
"sync"
@ -41,6 +41,10 @@ type Program struct {
computedFactors map[string]string
}
func (p *Program) GlobalInputCount() int {
return len(p.globalInputs)
}
func (p *Program) PrintContraintTrees() {
for k, v := range p.functions {
fmt.Println(k)
@ -52,6 +56,7 @@ func (p *Program) BuildConstraintTrees() {
mainRoot := p.getMainCircuit().root
//if our programs last operation is not a multiplication gate, we need to introduce on
if mainRoot.value.Op&(MINUS|PLUS) != 0 {
newOut := Constraint{Out: "out", V1: "1", V2: "out2", Op: MULTIPLY}
p.getMainCircuit().addConstraint(&newOut)
@ -64,6 +69,7 @@ func (p *Program) BuildConstraintTrees() {
}
var wg = sync.WaitGroup{}
//we build the parse trees concurrently! because we can! go rocks
for _, circuit := range p.functions {
wg.Add(1)
//interesting: if circuit is not passed as argument, the program fails. duno why..
@ -87,11 +93,10 @@ func (c *Circuit) buildTree(g *gate) {
panic(fmt.Sprintf("undefined variable %s", g.value.Out))
}
if g.OperationType() == FUNC {
//g.funcInputs = []*gate{}
for _, in := range g.value.Inputs {
if gate, ex := c.gateMap[in]; ex {
g.funcInputs = append(g.funcInputs, gate)
//note that we do repeated work here. the argument
c.buildTree(gate)
} else {
panic(fmt.Sprintf("undefined argument %s", g.value.V1))
@ -115,7 +120,6 @@ func (c *Circuit) buildTree(g *gate) {
}
func (p *Program) ReduceCombinedTree() (orderedmGates []gate) {
//mGatesUsed := make(map[string]bool)
orderedmGates = []gate{}
p.computedInContext = make(map[string]map[string]string)
p.computedFactors = make(map[string]string)
@ -128,7 +132,6 @@ func (p *Program) ReduceCombinedTree() (orderedmGates []gate) {
//recursively walks through the parse tree to create a list of all
//multiplication gates needed for the QAP construction
//Takes into account, that multiplication with constants and addition (= substraction) can be reduced, and does so
//TODO if the same variable that has been computed in context A, is needed again but from a different context b, will be recomputed and not reused
func (p *Program) r1CSRecursiveBuild(currentCircuit *Circuit, node *gate, hashTraceBuildup []byte, orderedmGates *[]gate, negate bool, invert bool) (facs []factor, hashTraceResult []byte, variableEnd bool) {
if node.OperationType() == CONST {

+ 19
- 15
circuitcompiler/Programm_test.go

@ -32,6 +32,9 @@ var correctnesTest = []TraceCorrectnessTest{
result: bigNumberResult1,
}},
code: `
def main( x , z ) :
out = do(z) + add(x,x)
def do(x):
e = x * 5
b = e * 6
@ -44,9 +47,7 @@ var correctnesTest = []TraceCorrectnessTest{
z = k * x
out = do(x) + mul(x,z)
def main(x,z):
out = do(z) + add(x,x)
def mul(a,b):
out = a * b
`,
@ -98,21 +99,24 @@ var correctnesTest = []TraceCorrectnessTest{
out = g * a
`,
},
{
io: []InOut{{
inputs: []*big.Int{big.NewInt(int64(3)), big.NewInt(int64(5)), big.NewInt(int64(7)), big.NewInt(int64(11))},
result: big.NewInt(int64(444675)),
}},
code: `
def main(a,b,c,d):
e = a * b
f = c * d
g = e * f
h = g / e
i = h * 5
out = g * i
`,
},
}
func TestNewProgramm(t *testing.T) {
//flat := `
//
//def doSomething(x ,k):
// z = k * x
// out = 6 + mul(x,z)
//
//def main(x,z):
// out = mul(x,z) - doSomething(x,x)
//
//def mul(a,b):
// out = a * b
//`
for _, test := range correctnesTest {
parser := NewParser(strings.NewReader(test.code))

+ 0
- 110
circuitcompiler/circuit_test.go

@ -16,113 +16,3 @@ func TestXor(t *testing.T) {
assert.Equal(t, false, Xor(false, false))
}
func TestCircuitParser(t *testing.T) {
//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.getMainCircuit()
//assert.Nil(t, err)
//fmt.Println("\n unreduced")
//fmt.Println(flat)
//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)
//
//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)
//// 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)
//// 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},
//}
//assert.Equal(t, aExpected, a)
//assert.Equal(t, bExpected, b)
//assert.Equal(t, cExpected, c)
}

+ 32
- 15
circuitcompiler/test.py

@ -38,21 +38,21 @@
# g = f + 2
# return g * a
def doSomething(x ,k):
z = k * x
return 6 + mul(x,z)
# def main(x,z):
# out =
def mul(a,b):
return a * b
def main():
x=64341
z=76548465
##############################
# def doSomething(x ,k):
# z = k * x
# return 6 + mul(x,z)
#
# def mul(a,b):
# return a * b
#
# def main():
# x=64341
# z=76548465
#
# print(mul(x,z) - doSomething(x,x))
print(mul(x,z) - doSomething(x,x))
#######################
#
# def mul(a,b):
# return a * b
@ -62,7 +62,24 @@ def main():
# c = 4 - b
# d = 5 * c
# return mul(d,c) / mul(b,b)
############################
def go(a,b,c,d):
e = a * b
f = c * d
g = e * f
h = g / e
i = h * 5
return g * i
def main():
print(go(3,5,7,11))
if __name__ == '__main__':
#pascal(8)
main()
main()
[[0 1 0 0 0 0 0 0 0 0] [0 0 0 1 0 0 0 0 0 0] [0 0 0 0 0 1 0 0 0 0] [0 0 0 0 0 0 0 0 1 0] [0 0 0 0 0 0 0 1 0 0]]
[[0 0 1 0 0 0 0 0 0 0] [0 0 0 0 1 0 0 0 0 0] [0 0 0 0 0 0 1 0 0 0] [0 0 0 0 0 1 0 0 0 0] [0 0 0 0 0 0 0 0 5 0]]
[[0 0 0 0 0 1 0 0 0 0] [0 0 0 0 0 0 1 0 0 0] [0 0 0 0 0 0 0 1 0 0] [0 0 0 0 0 0 0 1 0 0] [0 0 0 0 0 0 0 0 0 1]]

+ 3
- 3
cli/main.go

@ -11,9 +11,9 @@ import (
"math/big"
"os"
snark "github.com/mottla/go-snark"
"github.com/mottla/go-snark/circuitcompiler"
"github.com/mottla/go-snark/r1csqap"
snark "github.com/arnaucube/go-snark"
"github.com/arnaucube/go-snark/circuitcompiler"
"github.com/arnaucube/go-snark/r1csqap"
"github.com/urfave/cli"
)

+ 1
- 5
r1csqap/r1csqap.go

@ -2,10 +2,9 @@ package r1csqap
import (
"bytes"
"fmt"
"math/big"
"github.com/mottla/go-snark/fields"
"github.com/arnaucube/go-snark/fields"
)
// Transpose transposes the *big.Int matrix
@ -173,9 +172,6 @@ func (pf PolynomialField) R1CSToQAP(a, b, c [][]*big.Int) (alphas [][]*big.Int,
aT := Transpose(a)
bT := Transpose(b)
cT := Transpose(c)
fmt.Println(aT)
fmt.Println(bT)
fmt.Println(cT)
for i := 0; i < len(aT); i++ {
alphas = append(alphas, pf.LagrangeInterpolation(aT[i]))

+ 1
- 63
r1csqap/r1csqap_test.go

@ -5,7 +5,7 @@ import (
"math/big"
"testing"
"github.com/mottla/go-snark/fields"
"github.com/arnaucube/go-snark/fields"
"github.com/stretchr/testify/assert"
)
@ -112,65 +112,3 @@ func TestLagrangeInterpolation(t *testing.T) {
assert.Equal(t, aux, int64(0))
}
func TestR1CSToQAP(t *testing.T) {
// new Finite Field
r, ok := new(big.Int).SetString("21888242871839275222246405745257275088548364400416034343698204186575808495617", 10)
assert.True(nil, ok)
f := fields.NewFq(r)
// new Polynomial Field
pf := NewPolynomialField(f)
b0 := big.NewInt(int64(0))
b1 := big.NewInt(int64(1))
b3 := big.NewInt(int64(3))
b5 := big.NewInt(int64(5))
b9 := big.NewInt(int64(9))
b27 := big.NewInt(int64(27))
b30 := big.NewInt(int64(30))
b35 := big.NewInt(int64(35))
a := [][]*big.Int{
[]*big.Int{b0, b1, b0, b0, b0, b0},
[]*big.Int{b0, b0, b0, b1, b0, b0},
[]*big.Int{b0, b1, b0, b0, b1, b0},
[]*big.Int{b5, b0, b0, b0, b0, b1},
}
b := [][]*big.Int{
[]*big.Int{b0, b1, b0, b0, b0, b0},
[]*big.Int{b0, b1, b0, b0, b0, b0},
[]*big.Int{b1, b0, b0, b0, b0, b0},
[]*big.Int{b1, b0, b0, b0, b0, b0},
}
c := [][]*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, b0, b1, b0, b0, b0},
}
alphas, betas, gammas, zx := pf.R1CSToQAP(a, b, c)
// fmt.Println(alphas)
// fmt.Println(betas)
// fmt.Println(gammas)
// fmt.Print("Z(x): ")
// fmt.Println(zx)
w := []*big.Int{b1, b3, b35, b9, b27, b30}
ax, bx, cx, px := pf.CombinePolynomials(w, alphas, betas, gammas)
// fmt.Println(ax)
// fmt.Println(bx)
// fmt.Println(cx)
// fmt.Println(px)
hx := pf.DivisorPolynomial(px, zx)
// fmt.Println(hx)
// hx==px/zx so px==hx*zx
assert.Equal(t, px, pf.Mul(hx, zx))
// p(x) = a(x) * b(x) - c(x) == h(x) * z(x)
abc := pf.Sub(pf.Mul(ax, bx), cx)
assert.Equal(t, abc, px)
hz := pf.Mul(hx, zx)
assert.Equal(t, abc, hz)
}

+ 25
- 4
snark.go

@ -2,12 +2,13 @@ package snark
import (
"fmt"
"github.com/arnaucube/go-snark/circuitcompiler"
"math/big"
"os"
"github.com/mottla/go-snark/bn128"
"github.com/mottla/go-snark/fields"
"github.com/mottla/go-snark/r1csqap"
"github.com/arnaucube/go-snark/bn128"
"github.com/arnaucube/go-snark/fields"
"github.com/arnaucube/go-snark/r1csqap"
)
// Setup is the data structure holding the Trusted Setup data. The Setup.Toxic sub struct must be destroyed after the GenerateTrustedSetup function is completed
@ -27,7 +28,8 @@ type Setup struct {
// public
G1T [][3]*big.Int // t encrypted in G1 curve, G1T == Pk.H
G2T [][3][2]*big.Int // t encrypted in G2 curve
Pk struct { // Proving Key pk:=(pkA, pkB, pkC, pkH)
Pk struct {
// Proving Key pk:=(pkA, pkB, pkC, pkH)
A [][3]*big.Int
B [][3][2]*big.Int
C [][3]*big.Int
@ -353,3 +355,22 @@ func VerifyProof(setup Setup, proof Proof, publicSignals []*big.Int, debug bool)
return true
}
//TODO this is just a workaround to place the output after the input signals. Will be removed once the handling of private variables is already considered in the lexer
func RelocateOutput(numberOfInputs int, r1cs circuitcompiler.R1CS, witness []*big.Int) (r circuitcompiler.R1CS, w []*big.Int) {
tmpA, tmpB, tmpC := [][]*big.Int{}, [][]*big.Int{}, [][]*big.Int{}
tmpA = append(tmpA, r1cs.A[len(r1cs.A)-1])
tmpA = append(tmpA, r1cs.A[:len(r1cs.A)-1]...)
tmpB = append(tmpB, r1cs.B[len(r1cs.B)-1])
tmpB = append(tmpB, r1cs.B[:len(r1cs.B)-1]...)
tmpC = append(tmpC, r1cs.C[len(r1cs.C)-1])
tmpC = append(tmpC, r1cs.C[:len(r1cs.C)-1]...)
wtmp := append(witness[:numberOfInputs], witness[len(witness)-1])
wtmp = append(wtmp, witness[numberOfInputs:len(witness)-2]...)
return circuitcompiler.R1CS{A: tmpA, B: tmpB, C: tmpC}, wtmp
}

+ 17
- 57
snark_test.go

@ -2,58 +2,14 @@ package snark
import (
"fmt"
"github.com/mottla/go-snark/circuitcompiler"
"github.com/mottla/go-snark/r1csqap"
"github.com/arnaucube/go-snark/circuitcompiler"
"github.com/arnaucube/go-snark/r1csqap"
"github.com/stretchr/testify/assert"
"math/big"
"strings"
"testing"
)
func TestGenerateProofs(t *testing.T) {
z := []*big.Int{big.NewInt(int64(1))}
for i := 1; i < 6; i++ {
z = Utils.PF.Mul(
z,
[]*big.Int{
Utils.PF.F.Neg(
big.NewInt(int64(i))),
big.NewInt(int64(1)),
})
}
fmt.Println(z)
for i := 0; i < 7; i++ {
fmt.Println(Utils.PF.Eval(z, big.NewInt(int64(i))))
}
z = []*big.Int{big.NewInt(int64(1))}
for i := 1; i < 6; i++ {
z = Utils.PF.Mul(
z,
[]*big.Int{
big.NewInt(int64(i)),
big.NewInt(int64(1)),
})
}
fmt.Println(z)
z = []*big.Int{
big.NewInt(int64(1)),
big.NewInt(int64(
-3)),
}
z = Utils.PF.Mul(
z,
[]*big.Int{
big.NewInt(int64(1)),
big.NewInt(int64(3)),
})
fmt.Println(z)
fmt.Println(Utils.PF.F.Neg(
big.NewInt(int64(1))))
fmt.Println(Utils.PF.F.Inverse(big.NewInt(int64(1))))
}
func TestNewProgramm(t *testing.T) {
flat := `
@ -86,27 +42,30 @@ func TestNewProgramm(t *testing.T) {
fmt.Println("generating R1CS")
r1cs := program.GenerateReducedR1CS(gates)
a, b, c := r1cs.A, r1cs.B, r1cs.C
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)
//[[0 1 0 0 0 0 0 0 0 0] [0 0 0 1 0 0 0 0 0 0] [0 0 0 0 0 1 0 0 0 0] [0 0 0 0 0 0 0 0 1 0] [0 0 0 0 0 0 0 1 0 0]]
//[[0 0 1 0 0 0 0 0 0 0] [0 0 0 0 1 0 0 0 0 0] [0 0 0 0 0 0 1 0 0 0] [0 0 0 0 0 1 0 0 0 0] [0 0 0 0 0 0 0 0 5 0]]
//[[0 0 0 0 0 1 0 0 0 0] [0 0 0 0 0 0 1 0 0 0] [0 0 0 0 0 0 0 1 0 0] [0 0 0 0 0 0 0 1 0 0] [0 0 0 0 0 0 0 0 0 1]]
a1 := big.NewInt(int64(6))
a2 := big.NewInt(int64(5))
inputs := []*big.Int{a1, a2, a1, a2}
w := circuitcompiler.CalculateWitness(inputs, r1cs)
fmt.Println("witness")
fmt.Println(w)
r1csReordered, wReordered := RelocateOutput(program.GlobalInputCount(), r1cs, w)
a, b, c := r1csReordered.A, r1csReordered.B, r1csReordered.C
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)
// R1CS to QAP
alphas, betas, gammas, domain := Utils.PF.R1CSToQAP(a, b, c)
fmt.Println("qap")
fmt.Println("QAP array lengths")
fmt.Println("alphas", len(alphas))
fmt.Println("alphas", alphas)
fmt.Println("betas", len(betas))
fmt.Println("gammas", len(gammas))
fmt.Println("domain polynomial ", len(domain))
ax, bx, cx, px := Utils.PF.CombinePolynomials(w, alphas, betas, gammas)
ax, bx, cx, px := Utils.PF.CombinePolynomials(wReordered, alphas, betas, gammas)
fmt.Println("ax length", len(ax))
fmt.Println("bx length", len(bx))
fmt.Println("cx length", len(cx))
@ -147,7 +106,7 @@ func TestNewProgramm(t *testing.T) {
// fmt.Println("zxQAP", len(zxQAP))
// piA = g1 * A(t), piB = g2 * B(t), piC = g1 * C(t), piH = g1 * H(t)
proof, err := GenerateProofs(setup, 5, w, px)
proof, err := GenerateProofs(setup, program.GlobalInputCount(), wReordered, px)
assert.Nil(t, err)
// fmt.Println("\n proofs:")
@ -155,11 +114,12 @@ func TestNewProgramm(t *testing.T) {
// fmt.Println("public signals:", proof.PublicSignals)
fmt.Println("\nwitness", w)
fmt.Println("\nwitness Reordered ", wReordered)
// b1 := big.NewInt(int64(1))
//b35 := big.NewInt(int64(35))
//// publicSignals := []*big.Int{b1, b35}
//publicSignals := []*big.Int{b35}
//before := time.Now()
assert.True(t, VerifyProof(setup, proof, w[:5], true))
assert.True(t, VerifyProof(setup, proof, wReordered[:program.GlobalInputCount()], true))
//fmt.Println("verify proof time elapsed:", time.Since(before))
}

Loading…
Cancel
Save