Skip to content

Commit

Permalink
Submission to suggest a fix for issue : Add on-the-fly proof generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bbresearcher committed Jun 14, 2023
1 parent 1dc4e00 commit 02b99fb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion with-foundry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ We're ready to test with Foundry. There's a basic test inside the `test` folder
By running the following command, forge will compile the contract with 5000 rounds of optimization and the London EVM version. __You need to use these optimizer settings to supress the "stack too deep" error on the solc compiler__. Then it will run the test, expecting it to pass with correct inputs, and fail with wrong inputs:

```bash
forge test --optimize --optimizer-runs 5000 --evm-version london
forge test --optimize --optimizer-runs 5000 --evm-version london --ffi
```

### Deploy with Foundry
Expand Down
2 changes: 1 addition & 1 deletion with-foundry/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
src = "src"
out = "out"
libs = ["lib"]
fs_permissions = [{ access = "read", path = "./"}]
fs_permissions = [{ access = "read-write", path = "./"}]


# See more config options https://github.com/foundry-rs/foundry/tree/master/config
2 changes: 2 additions & 0 deletions with-foundry/script/prove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
cd ./circuits && nargo prove d && echo "Command Completed"
32 changes: 31 additions & 1 deletion with-foundry/test/Starter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma solidity ^0.8.17;

import "forge-std/Test.sol";
import "../contract/Starter.sol";
import "../circuits/contract/plonk_vk.sol";
//import "../circuits/contract/plonk_vk.sol";

contract StarterTest is Test {
Starter public starter;
Expand Down Expand Up @@ -31,4 +31,34 @@ contract StarterTest is Test {
bytes memory proofBytes = vm.parseBytes(proof);
starter.verifyEqual(proofBytes, wrong);
}

function test_dynamicProof() public {
string[] memory _fieldNames = new string[](2);
string[] memory _fieldValues = new string[](2);

_fieldNames[0] = "x";
_fieldNames[1] = "y";
_fieldValues[0] = "3";
_fieldValues[1] = "3";
bytes memory proofBytes = generateDynamicProof(_fieldNames,_fieldValues);
starter.verifyEqual(proofBytes, correct);
}
function generateDynamicProof(string[] memory _fields, string[] memory _fieldValues) public returns (bytes memory) {
require(_fields.length == _fieldValues.length,"generateProof: Input arrays not the same length");
string memory _file = "./circuits/Prover.toml";
vm.writeFile(_file,"");
for(uint256 i; i < _fields.length; i++)
{
vm.writeLine(_file, string.concat( _fields[i] , " = " , _fieldValues[i]));
}

// now generate the proof by calling the script using ffi
string[] memory ffi_command = new string[] (1);
ffi_command[0] = "./script/prove.sh";
bytes memory commandResponse = vm.ffi(ffi_command);
console.log(string(commandResponse));
string memory _newProof = vm.readLine("./circuits/proofs/d.proof");
return vm.parseBytes(_newProof);

}
}

0 comments on commit 02b99fb

Please sign in to comment.