From 8c9d52b59a643e08d5c1bdb6c3f5c0f3e2bf0d6f Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Wed, 15 Jan 2025 15:03:47 -0800 Subject: [PATCH] feat: add nathan changes" gp --- Cargo.lock | 11 +---- README.md | 2 +- contracts/src/fixtures/groth16-fixture.json | 4 +- contracts/src/fixtures/plonk-fixture.json | 4 +- contracts/test/Fibonacci.t.sol | 45 ++++++++++++++++++++- script/Cargo.toml | 2 +- script/build.rs | 2 +- 7 files changed, 52 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6b028a6..be1c634 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1713,7 +1713,7 @@ dependencies = [ "hex", "serde", "serde_json", - "sp1-helper", + "sp1-build", "sp1-sdk", "tracing", ] @@ -4324,15 +4324,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "sp1-helper" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfeb036e069d9c621c99579e90175e71f2a59232b2ecdb3c44a31f5e601e5259" -dependencies = [ - "sp1-build", -] - [[package]] name = "sp1-lib" version = "4.0.0" diff --git a/README.md b/README.md index 097d368..504347e 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ cargo run --release --bin vkey ## Using the Prover Network -We highly recommend using the Succinct prover network for any non-trivial programs or benchmarking purposes. For more information, see the [setup guide](https://docs.succinct.xyz/generating-proofs/prover-network.html). +We highly recommend using the Succinct prover network for any non-trivial programs or benchmarking purposes. For more information, see the [setup guide](https://docs.succinct.xyz/docs/generating-proofs/prover-network). To get started, copy the example environment file: diff --git a/contracts/src/fixtures/groth16-fixture.json b/contracts/src/fixtures/groth16-fixture.json index db32ddc..90f352a 100644 --- a/contracts/src/fixtures/groth16-fixture.json +++ b/contracts/src/fixtures/groth16-fixture.json @@ -2,7 +2,7 @@ "a": 6765, "b": 10946, "n": 20, - "vkey": "0x00467584e2e560847e9e96b5102c082f5e07155429c6622988799df9d95dbb47", + "vkey": "0x005aa1cbc05f992604b4f375159054d79b76501cf214b1fec6724ea14eceaf78", "publicValues": "0x00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000001a6d0000000000000000000000000000000000000000000000000000000000002ac2", - "proof": "0x090690900091bc3f08015e1ed96bee4e8c7a3ab074bfaa54129b1c63a9c6e478ec63255d3028cceaeed53e04bf0ee42f58ff0980ff00212e52a2a1d85b69b1268f5030820bc4589b0566e8a3f0738fa64405c10ee7347e58afbf4f1f431b327e5ba522c32f83c0c6e9e5bc37dfe2b31ae2bead89e0c7d8a0df1226b005d75f2e252b104a030d532c73f896df2328ce3322c055bda3b979dda22568ef85761b1d82bdcbec230f2838693d3663a0bd00006fa0f0dd4ea0e14b8b44273b0e8575e5478fa8d92a910cc26e0cdff4869f3fac686f91d245839368dbeadc9daaa4062ad1b3772523b284a3c41d60328f30461e03a465f4d6ec8d0fdfeeba176b8d0c7c82167c18" + "proof": "0x11b6a09d26e2118c306f7c64b4445c077f90764aaf4c3f0b5195ab76135914a2ba0e62be02216ef9ee42db956a50745c57dc6754a616995e6df07f027b32aafd83d9a9c30d129ff8fd534a67fe6a2fa1807f49e3045f8e85269fc90880da3a8063c45d500228c65c2772dd994f30db4ecb6745ab63ef7ea6e8b3ef6e9b600db7330b95c30a2ad71b04e752d8a045e15f803c3be01c0816f07823471294f204bc876d652f189720fa96d811da3e9d83acf730fef4da8bfd685530dd3867190e26e1ccf4d81b68ff5cf9bb36c36d522eac43653f7c3be5a3f022b680983fb04495633146062481a668712b472d6f18ac56f0eda3fedc9a5ee38d3679ef4aa4b3ea9e6208b7" } \ No newline at end of file diff --git a/contracts/src/fixtures/plonk-fixture.json b/contracts/src/fixtures/plonk-fixture.json index cbfaad2..664dadc 100644 --- a/contracts/src/fixtures/plonk-fixture.json +++ b/contracts/src/fixtures/plonk-fixture.json @@ -2,7 +2,7 @@ "a": 6765, "b": 10946, "n": 20, - "vkey": "0x00467584e2e560847e9e96b5102c082f5e07155429c6622988799df9d95dbb47", + "vkey": "0x005aa1cbc05f992604b4f375159054d79b76501cf214b1fec6724ea14eceaf78", "publicValues": "0x00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000001a6d0000000000000000000000000000000000000000000000000000000000002ac2", - "proof": "0x54bdcae32122ba5d63ecb7d08cf7e217531928202417f27aa006e67ab53721eb386323bd1548e7a98de06f907d6067c9069866a6e8ca4a81a8553566abee9c2903efec8d0d3a52e9e717313d6fb5076bf3865cd8705a40b2613563b1d10f13adbeced54b179c997b00339169940341b4bb6ea21cd43992779b03e9a17fe6925f6273774e1b37fe45304344f3c66efee0b283cc6f8bb5d50e1f711d869080191284b5b93d10eafd8c57fab7d77ff15918e5e7fd93ed7ae6edc8629464aee148934e719c761e932ac3e956d05c70f9f2d2145c0b72f5e96127311b0b5ff805683091ec1f391beaffe65cf81e0613902331c700fcb0659c0c57e2f5d48d7e4eec04309060221f29322fc530473f367d34f38b47747afd4397acf8f75219ed6d393a468822b5152de3687df40b6ffebe49fbf0ceda8b54042283e454586875bb602b26a1175e165bdd7b6f29206896396e864904bb3cf5d375c84f311e5c557918dedccf27c30f43b11922ac6c9c0901634269de7d8ec9543ff834167149db30cd87b5c00c8d28cabf65079b6be84e5d013f514775e16d078215751f30547561ded0d2af784c0cbefb1fbd6149c09ed6eb0844265b1b0d038acd6b389cba9b3d6335e31567c706acf8cb896be0b70ce13eeb65990e69e29a48b85de56e2cda40d154034633f321f266a6af27e1adebe64e89a451bbeabb5fc0d9cf22c66c76710f599f39434b12f8ce865dda948710bed1755df69588eb5b0c21fb0f929b1bff7b7358c4cb1c271a65be960be28f2af49f3be51ddd6a4e552a3c1bb57204cd020d1057ae15602a43eb67628c5697ef5b181ded7e76a1f26997bca92ba31ef7337b63326a31cb1a13ec5b1d81605d83dbbf17f9699ebe3f2a2afa211dd09cf5de084d29ab28c212d9017f24ce6697e36d8c84b82970e1dedf5c74a821b73fce661c2a0bf1408f2c557c0e8962ad59cca1931cb276d3566e6f4a9411102cbf486c83aced09563d22a891e9abd3b6cee11963269c1f32f6131e97852584736ca8dbf7c6f9e34f660f79c2b9cd21515608ccc90af5e5689df83f623c08bc49284d93d4cfbf4ca60c2e2d8c1cb71195ac41b0788267d5af7092b421963519a1bb2e23774e7648344b19334175fa8031c8562bfb5209242b0a35282cbc7d05f96f4bf24318b6c37f0727f359fd9cf136abc923abbffc906a32cfb0e6d16ce61cc2d20748c2460f6844" + "proof": "0x1b34fe110b653a5bb2e727aacca6d4c9de41249fbd7586b9aa02af98399a3b3fd1666cec0c8473bae000e399aecaab29ecd01dcf66e08e638a7a7bae517ef9ed22be23df12c942a19b734fba23b60c1bbd9abca4f98c56dc118a0fc872ae921b54438e25185909e44fd21ab07cebba1de255741b72e8bad0620f05aebad4f765b1cbba112b4379c851beaac58afb53b98ff31dc9292c0163fdac2068608f197ff0be1c050857edec30d56a0373109031afc35e54b0b6383ee7944c8e3f1d08040fc0f5721fb16d8af362b7aff5855d2f6c4a843003a7b8020728114de8e4ef6dedbd532b1f7e65dbf48e8cc592cf8163f5de468e24e904d67b7ae3f58f7edc14fc38a60317b175cd23772ca939ffd13e9d7390cb4c811384d746fa874d4a84117c25c3ab2e124b51764997fefd97605bdfcf60f634bd0d3f47efb8d68ac077b8cac612bb15e2d52dc1662680acd46432e3415dbc936673a0060164f80d2a55d6e6a0eec709f763b91500f52ae86229b6f155aa7aa4a6350373b459027d959fbc8eeabc2d04a1e18f91b62d4094a6279def15868b9f01ed81be16b65e607f7eeb938c1018276c666be3300a1de112fbf3e3ebdf49c9daffab4711a11fecca183830639bbb1bfc81381e005f2c1d7702b2cc579719a32a2e8b8144cded8f19edb24ad709a01a49867454a0e9fe6253dbb04b4fd9484b2a2fa10fa974ff327b93ccf6f71a61061c2fd03794cb3badac3326b32467122480cf2810135832b89f8891248ff1c8035256d4e18515e1986d0995e6d945b02e88cace743fe19b86e7ac366c8448fb1dee3630fb6f57be5abded070ed4f04af597886e4d8f5188bcfb1d9fbca9f45b2223d5821917f386acf5ce74098e52f971257b5ad06039311e85f2bf4d3f6a7f300548634ba8c77666ad320f998cf42e6efa3fb84571959d055b394a7b9ede590ce87fda92632f6ece014fb9bd9b3ea3a919fc7139bc59003fa9f33a4342f46e2ca3d09e3d10af3d06906af1fea935bb06143d7525daa6a0cd5352d098d9af7c196d44286c029bf773f5dd8bcee23b60c44c2f7632224b880d4b856a9aaa0e832e2be26a5eb31a4f3697fdac727722eb76da934054937d29f44a01959fd571332a58e27cc753247c57817b338e30397fecff0fe609f6dae12cd54aae72a55ce60d46b7bb14ceba9b0e69f35be38547f7a3f71dbaea85459449daa1353f338fcf" } \ No newline at end of file diff --git a/contracts/test/Fibonacci.t.sol b/contracts/test/Fibonacci.t.sol index 9e065f1..b53bdd2 100644 --- a/contracts/test/Fibonacci.t.sol +++ b/contracts/test/Fibonacci.t.sol @@ -15,7 +15,50 @@ struct SP1ProofFixtureJson { bytes32 vkey; } -contract FibonacciTest is Test { +contract FibonacciGroth16Test is Test { + using stdJson for string; + + address verifier; + Fibonacci public fibonacci; + + function loadFixture() public view returns (SP1ProofFixtureJson memory) { + string memory root = vm.projectRoot(); + string memory path = string.concat(root, "/src/fixtures/groth16-fixture.json"); + string memory json = vm.readFile(path); + bytes memory jsonBytes = json.parseRaw("."); + return abi.decode(jsonBytes, (SP1ProofFixtureJson)); + } + + function setUp() public { + SP1ProofFixtureJson memory fixture = loadFixture(); + + verifier = address(new SP1VerifierGateway(address(1))); + fibonacci = new Fibonacci(verifier, fixture.vkey); + } + + function test_ValidFibonacciProof() public { + SP1ProofFixtureJson memory fixture = loadFixture(); + + vm.mockCall(verifier, abi.encodeWithSelector(SP1VerifierGateway.verifyProof.selector), abi.encode(true)); + + (uint32 n, uint32 a, uint32 b) = fibonacci.verifyFibonacciProof(fixture.publicValues, fixture.proof); + assert(n == fixture.n); + assert(a == fixture.a); + assert(b == fixture.b); + } + + function testFail_InvalidFibonacciProof() public view { + SP1ProofFixtureJson memory fixture = loadFixture(); + + // Create a fake proof. + bytes memory fakeProof = new bytes(fixture.proof.length); + + fibonacci.verifyFibonacciProof(fixture.publicValues, fakeProof); + } +} + + +contract FibonacciPlonkTest is Test { using stdJson for string; address verifier; diff --git a/script/Cargo.toml b/script/Cargo.toml index d8adb8d..0c7e581 100644 --- a/script/Cargo.toml +++ b/script/Cargo.toml @@ -28,4 +28,4 @@ fibonacci-lib = { path = "../lib" } dotenv = "0.15.0" [build-dependencies] -sp1-helper = "4.0.0" +sp1-build = "4.0.0" diff --git a/script/build.rs b/script/build.rs index bc5f025..7025fc6 100644 --- a/script/build.rs +++ b/script/build.rs @@ -1,4 +1,4 @@ -use sp1_helper::build_program_with_args; +use sp1_build::build_program_with_args; fn main() { build_program_with_args("../program", Default::default())