Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:EspressoSystems/zkrollup-integra…
Browse files Browse the repository at this point in the history
…tion into develop
  • Loading branch information
mrain committed Aug 28, 2024
2 parents 079dae5 + d9bf339 commit 776f0e6
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 74 deletions.
65 changes: 33 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Generally speaking, we are proving that a list of rollup's transactions are corr

- `rollup_txs: Vec<u8>`: the byte representation of all transactions specific to rollup with `ns_id` filtered from a batch of Espresso blocks
- `vid_param: VidParam`: public parameter for Espresso's VID scheme
- `block_derivation_proofs: Vec<Range, BlockDerivationProof>`: a list of `(range, proof)` pairs, one for each block, where `proof` proves that `rollup_txs[range]` is the complete subset of namespace-specific transactions filtered from the Espresso block.
- `block_derivation_proofs: Vec<(Range, BlockDerivationProof)>`: a list of `(range, proof)` pairs, one for each block, where `proof` proves that `rollup_txs[range]` is the complete subset of namespace-specific transactions filtered from the Espresso block.
Each `BlockDerivationProof` contains the following:
- `block_header: BlockHeader`: block header of the original Espresso block containing the block height, the namespace table `ns_table`, and a commitment `payload_commitment` to the entire Espresso block payload (which contains transactions from all rollups)
- `bmt_proof: BlockMerkleTreeProof`: a proof that the given block is in the block Merkle tree committed by `bmt_commitment`
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@

# Rust
nightlyRustToolchain
cargo-sort
] ++ lib.optionals stdenv.isDarwin
[ darwin.apple_sdk.frameworks.SystemConfiguration ];
shellHook = ''
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ default:
# Test SP1 contracts
@sp1-test-contracts:
echo "Testing SP1 contracts"
cd sp1/contracts && forge test -v
cd sp1/contracts && forge test -vv
2 changes: 1 addition & 1 deletion sp1/contracts/lib/sp1-contracts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,32 @@ pragma solidity ^0.8.20;
import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol";

/// @title Fibonacci.
/// @author Succinct Labs
/// @author Espresso System
/// @notice This contract implements a simple example of verifying the proof of a computing a
/// fibonacci number.
contract Fibonacci {
contract EspressoDerivation {
/// @notice The address of the SP1 verifier contract.
/// @dev This can either be a specific SP1Verifier for a specific version, or the
/// SP1VerifierGateway which can be used to verify proofs for any version of SP1.
/// For the list of supported verifiers on each chain, see:
/// https://github.com/succinctlabs/sp1-contracts/tree/main/contracts/deployments
address public verifier;

/// @notice The verification key for the fibonacci program.
bytes32 public fibonacciProgramVkey;
/// @notice The verification key for the program.
bytes32 public vkey;

constructor(address _verifier, bytes32 _fibonacciProgramVkey) {
constructor(address _verifier, bytes32 _vkey) {
verifier = _verifier;
fibonacciProgramVkey = _fibonacciProgramVkey;
vkey = _vkey;
}

/// @notice The entrypoint for verifying the proof of a fibonacci number.
/// @notice Verify a derivation proof from a batch of Espresso blocks.
/// @param proof The encoded proof.
/// @param publicValues The encoded public values.
function verifyFibonacciProof(bytes calldata proof, bytes calldata publicValues)
function verifyDerivationProof(bytes calldata proof, bytes calldata publicValues)
public
view
returns (uint32, uint32, uint32)
{
ISP1Verifier(verifier).verifyProof(fibonacciProgramVkey, publicValues, proof);
(uint32 n, uint32 a, uint32 b) = abi.decode(publicValues, (uint32, uint32, uint32));
return (n, a, b);
ISP1Verifier(verifier).verifyProof(vkey, publicValues, proof);
}
}
11 changes: 4 additions & 7 deletions sp1/contracts/src/fixtures/fixture.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"a": 6765,
"b": 10946,
"n": 20,
"vkey": "0x00307ac6ea935608a65cea9a739f1c678dc028267391566806be12953d865be8",
"publicValues": "0x00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000001a6d0000000000000000000000000000000000000000000000000000000000002ac2",
"proof": "0x801c66ac24a8c9c720fb536ab6d292c3f4bdd9ecfb8bbd58a094081a578dd19ec444d9170ce9d31a25163009ff046d03f74dc0212f0cc713454574a72e41ed4e7604087a180ce46f081dc855f9b952ddc3e42002da927b46b7c826e7dd9373695fc0aa152a3dc2bf70aa716243930edf99a1958345e94cc88fb3dd4acd9af75175fd1f1504805ba12b526663567b12475f1b940323c87e2246195de23a5e0be5d2abe3b41e99dbddefc673abc7038e71c19e1e7ec170d1b48a12e63c2657fbc5b96defab06a2347a8a095b44692536217bdc71787da3464ab717cfa6b5b74849469795510728acc0be593ce813059e33337bfd33d11ac03676c1a8cd508518d1ee3859af19ba893298a9b35ee3cd3346e2c6f8aa71fa58c225128693eee97ed1374535e30c8d107388bb500af98fe04a2ec60f0efe1026f90745e2cd157e95468cd5c8db16b99e8616eb444a6f89c7c31728c039c75f340e3b6a3ca621b0172fc400990f195a6b6dce88cae4604b354eb4eea15ea0e9f8a0837813f621d0b1289d90a0d812eaedc02934cc41c86f242123d8a753d308d8134f3f33b8168140b2ba612b9129d54b9566230974f9778e8cb3dcd0d187e32fcea5969855642190bd3416d65212d2ea3d785b8ddf7f477259a3d11e5326c3a14a1ffc1e121f38975a01fbba640a28cbf9d7f5b22be18cbbaf3442d9284eee0f632d0fce47475e7be13103f8ba1f8f4ebc25b73650969c53b13a35cc6943a331c689841a40325d23b6045f240803d1738e11c5c46999bb6e060ac823a865ddc4f7e83dfecffb6f0a822180a6db2eeb6e91e1d80d78a9350df39d142c462cce1ac9e36cd8ab682f167b13e690d522642cc4bde919a52f333a00700fccf2fa6212fd3cf49b430368e7fc6b80ab8c1e5b265ccdf8bb49174102224f419c437da1b1bbe892dad2039a3f98e7a328a702ab130b30b7d818efe388a6134fe3c085d213a5534d604b9b3335b8db4180991abb9efda23fa9be95c8c46dd270200ad00f114d830ae8a019b76a02aa2a69f50fa73605947b3e7640d90d481dbff96bf124c92691fdfa52358671a5a3ea355d0128af0521a8b783fff80caf13fd8dc30757bc5ef93fc5f7b0411f44ca5f15510c6cae1f1eeca8477aef5a6d5d4197dcd220536498706c553e86da5b91afd3900bea3e07838a9592c798e1c38674ab04e0d51badf80bb95331702db27dfb2347"
}
"vkey": "0x00878da947d29df42252238b58a0e5f3dc5c1ba90c3b7616013772bcb85f514c",
"publicValues": "0x420000000000000030783131323438633764376631386137373236663063373537343662643434396530373831363663373066396433383838663665623034353132653630303362326342000000000000003078366531393061626164656331333862366535393939383935333839363333393839333864623435316134633031336232623135323663623034343533326462339bf49a6a4c000000000000000b000000000000004d45524b4c455f434f4d4d3000000000000000b0f1b60f2db6ccd4c6d4d849c0afd14a0f7bbc32a714e292964b673e818cc1a120000000000000000500000000000000a9",
"proof": "0xc430ff7f219349a8600513c3755bbd0c886782164b318efa39e3529e85483bff3917bb2e101bc0b36d479ca6e981db09604f068a0a83ff893d3935d9bf9d12aab25d8663123754cdafa3f98a1b5efd2e18571e8fb5753a070806624798a6cdf46a27854e094355079660660cb639020880645aa8b41ea1eea4244406cc383ffe862df8780173f12d2a568a652ca76e0aa38e440d81b2c58dbdb682a321aa7621b7b44fd8085dee1e045083280914b75684032ad21a3af762d4910f81a5c233d3af2b715b0d23a75746a231e3b57abeea2e7cd782a46a62a6ee1cb467640353a7c4723d5a27f6921fc70896c961c7633b8be57add2347ac13933f4842127f7910a4af15ef18035847bb3b7e382813725c7d62c70d425d179210ce654ed544330c4db2af0b0d44ecf0b9f81917da1ff791072fce1aba9c9ea559b435e4fa45b21a51665a80040fd1d1ad3efa0a21dad1ccc1a0bf7f5fed07094a04c80bade33cfe762e094f2ecd0d40107d44cdbc471f9491c4ec5da06e26a9349f421ae26f787cf515096022ca5d04207eddf7b30cb382e468fc94beffabb6c65ac3b7881fae3c91f5109822a430f9ca7f27185a908eb120c3785953979d1291a5fc6fc7f6ca2d4c5883832805092c0c9ad55c55cd2c98a0779ba3ac02ecf5c5f006d218d6bb84705af928240c8913a507604ccb91e0b3d54313b398eade0ff8286160a79c3c40570cba2202d690b34d2f4dd5fcc4bc1a75c73bc0e2d64de06b5a3ffa12389710bbb72b662fd0d98b4492bc742ce0fa71bb32f44b0100ff967bada30744e09476cf8e89002429a51df17ed41a03b8f2db372b25e21d935c3b4fc885dd79c3b9a9fd9770fb2df69f6685f85814eaa556249f83e98f01c04d450e1c4ad0c47d95be33acd5ba1d57a4cabe29262c308678089bcf184326b98ffa0e30e590c118374571f222b62011de8579fdde9a9a51e4f1e74a4fb2dfa6673be195ec44b1dbd409639730f7172a487e987d128011ffdf13eefbea13796b9b5c5f476f2b0e34ac4ca39c359b09689b4b45ff42f441c30984fbb026c3a0b5cf5aeeb675e461f747f64ae3ecc707ceb03c6b5f79da885d35c14aa65afa735dfd68dd8289d0ba63a71690e0efe323ea08b4b6aa5b20ca812eb5d2805b327bfbbcc74da6b5ef3d31ba106ceea46c1f9375edf8844b0b78bfc72a74f66b4c25a044d9585c2c02e62bab5893e9b21e"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ pragma solidity ^0.8.20;

import {Test, console} from "forge-std/Test.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {Fibonacci} from "../src/Fibonacci.sol";
import {SP1Verifier} from "@sp1-contracts/v1.0.8-testnet/SP1Verifier.sol";
import {EspressoDerivation} from "../src/EspressoDerivation.sol";
import {SP1Verifier} from "@sp1-contracts/v1.1.0/SP1Verifier.sol";

struct SP1ProofFixtureJson {
uint32 a;
uint32 b;
uint32 n;
bytes proof;
bytes publicValues;
bytes32 vkey;
}

contract FibonacciTest is Test {
contract EspressoDerivationTest is Test {
using stdJson for string;

address verifier;
Fibonacci public fibonacci;
EspressoDerivation public es;

function loadFixture() public view returns (SP1ProofFixtureJson memory) {
string memory root = vm.projectRoot();
Expand All @@ -33,24 +30,21 @@ contract FibonacciTest is Test {
SP1ProofFixtureJson memory fixture = loadFixture();

verifier = address(new SP1Verifier());
fibonacci = new Fibonacci(verifier, fixture.vkey);
es = new EspressoDerivation(verifier, fixture.vkey);
}

function test_ValidFibonacciProof() public view {
function test_ValidDerivationProof() public view {
SP1ProofFixtureJson memory fixture = loadFixture();

(uint32 n, uint32 a, uint32 b) = fibonacci.verifyFibonacciProof(fixture.proof, fixture.publicValues);
assert(n == fixture.n);
assert(a == fixture.a);
assert(b == fixture.b);
es.verifyDerivationProof(fixture.proof, fixture.publicValues);
}

function testFail_InvalidFibonacciProof() public view {
function testFail_InvalidDerivationProof() public view {
SP1ProofFixtureJson memory fixture = loadFixture();

// Create a fake proof.
bytes memory fakeProof = new bytes(fixture.proof.length);

fibonacci.verifyFibonacciProof(fakeProof, fixture.publicValues);
es.verifyDerivationProof(fakeProof, fixture.publicValues);
}
}
2 changes: 1 addition & 1 deletion sp1/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ committable = { workspace = true }
espresso-derivation-utils = { path = "../utils" }
jf-merkle-tree = { workspace = true }
jf-vid = { workspace = true }
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.1.1" }
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.1.0" }
5 changes: 3 additions & 2 deletions sp1/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ bincode = "1.3"
clap = { version = "4.0", features = ["derive", "env"] }
committable = { workspace = true }
espresso-derivation-utils = { path = "../utils" }
hex = "0.4.3"
jf-merkle-tree = { workspace = true }
jf-pcs = { workspace = true }
jf-vid = { workspace = true }
rand = "0.8"
serde = { workspace = true }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.1.1" }
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.1.0" }
tracing = "0.1.40"

[build-dependencies]
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.1.1" }
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.1.0" }
4 changes: 2 additions & 2 deletions sp1/script/src/bin/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ fn create_plonk_fixture(proof: &SP1ProofWithPublicValues, vk: &SP1VerifyingKey)
// Create the testing fixture so we can test things end-to-end.
let fixture = ProofFixture {
vkey: vk.bytes32().to_string(),
public_values: proof.public_values.raw(),
proof: proof.raw(),
public_values: format!("0x{}", hex::encode(proof.public_values.as_slice())),
proof: format!("0x{}", hex::encode(proof.bytes())),
};

// The verification key is used to verify that the proof corresponds to the
Expand Down

0 comments on commit 776f0e6

Please sign in to comment.