diff --git a/with-foundry/README.md b/with-foundry/README.md index 3082d37..0265a73 100644 --- a/with-foundry/README.md +++ b/with-foundry/README.md @@ -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 diff --git a/with-foundry/foundry.toml b/with-foundry/foundry.toml index 8d34fc9..85bfabf 100644 --- a/with-foundry/foundry.toml +++ b/with-foundry/foundry.toml @@ -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 diff --git a/with-foundry/script/prove.sh b/with-foundry/script/prove.sh new file mode 100755 index 0000000..27195ad --- /dev/null +++ b/with-foundry/script/prove.sh @@ -0,0 +1,2 @@ +#!/bin/bash +cd ./circuits && nargo prove d && echo "Command Completed" \ No newline at end of file diff --git a/with-foundry/test/Starter.t.sol b/with-foundry/test/Starter.t.sol index 015897c..9f5b53f 100644 --- a/with-foundry/test/Starter.t.sol +++ b/with-foundry/test/Starter.t.sol @@ -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; @@ -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); + + } }