Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
feat: added real generated proof
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jun 23, 2024
1 parent c058d20 commit f781cd4
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 60 deletions.
69 changes: 20 additions & 49 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ authors = ["srdtrk <[email protected]>"]

[workspace.dependencies]
# Used by the programs
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.7-testnet" }
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.7-testnet" }
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.5-testnet" }
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.5-testnet" }

sp1-ics07-tendermint-shared = { path = "./packages/shared/" }
sp1-ics07-tendermint-update-client = { path = "./programs/update-client/" }
Expand All @@ -37,7 +37,7 @@ serde_cbor = "0.11.2"
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }

# Used by the operator
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.7-testnet" }
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", tag = "v1.0.5-testnet", features = ["plonk"] }
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }
tendermint = { version = "0.36.0", default-features = false }
Expand Down
9 changes: 9 additions & 0 deletions contracts/fixtures/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"trustedClientState": "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034c200000000000000000000000000000000000000000000000000044c1ff252000000000000000000000000000000000000000000000000000000044c1ff2520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000",
"trustedConsensusState": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c419",
"targetConsensusState": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c419",
"targetHeight": 2110668,
"vkey": "0x004ac9cd92d0a05a01903f9f62b3c271ba861e2cd6b615c4c081394cbaf123f3",
"publicValues": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034c2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034cc00000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000044c1ff252000000000000000000000000000000000000000000000000000017dbb9d861d9c38000000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000",
"proof": "0x28192d1ec8d20562142ae5ed4b621a04cf6871187db21b0991e4732d470d7b5a17e6b1c037a5e75fc275e8bae644060d82c70050b6c695bbc4efe534db3f99c62c37e3e49930156a62b2743c054c463a789181b3ade6be54b8108e2afaebc1900f30a937736a0566bda5e72e11ede01e5a9f4cc54e45deb12b5a913415df51c30d5b991991f73942bb25c07444eabf989fe86dcf09874ff7c168a6a52a5d7cf52e46af4a99e227fec9990646781353e3c35a2b6303db59f2dd6c89c6e8b7f61a1e1a5bb75660dd8a914abb6ab7fa24f6ece69b87738b39066a720617707515892dbe014e002a1b859eef8de16ec36b2adfe95d44598853412f9f8c15e6574c732902911a34c720778d381fde493150f3582e412832bc5dfd7c9769a47c6f7c310ecaccac1d8701e743aecff4f8954bda594dc60cd124491bad0b5422abe5f8c60d19b48760f8d8a4243af71ea83c67b56a0c77aa559ff686c493d55a21c83ebb25aba42a65fa9eebde9c6b23b65870cdb0f0b6ed5162042f2f76ff7c63b617861c32723bff3020c91a5a0215d7cc43c59b151909075ddc78ec46895df1c9068f1bb77a4feae837abbbf959af7348b003cd2acbb825cbaf0c1e58db57bb454ddf186666c0a1459c4a578558d46e9b02cb541b173e96e7225e1e91b80c203203001831d51c0423869cefb63f2b346df6b138bd747b1335f48d6e0fe46d6683eda110aa73735e712cc3a921134713d07f839dbd582c2b3174bcc6d2b5b6926447ca190ed214ed8fa55fffb6b850bc6b3eeaa60790c84cfaaf6d31300ed796302e6c2d42eb241dac89b1723e736da9f8c4d897c2da6c2f3b76eda7faf94d4e930d8f1e3ebb0d58ca7c0164e82a7e86724f4a12b6051a5c51d9974d3f1756d1674bd91a1a9c8d5eea30c21cfef32aba24fb9ceb9b2f543871a5855c1c7b7deeed1aac013a6be382d092b3ba9645659e1f9c8d4953e50628a55d6552183a703fca9b330f41c0ce092b8305eea6516531dd98749945178fa5fb0dabe5e6f26a4e7d0a112238b8154ad17fca7edab2c51275d5a0d06496266811912cf9b0fdc2cc14d37924dfc2a17ea46cee7f66cce4883490c7c0abcd51ae339264faf39600bfb256c926620ea8e3d6b8f3babe6ebaee3cc0d48dbbffaf9798ddffdc78cfaa7f07969f141fb667d4790be0b9ef1f503a90c41610f0cc3a6913c69049aa5ab69466dec4"
}
67 changes: 59 additions & 8 deletions contracts/test/SP1ICS07Tendermint.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ struct SP1ICS07TendermintFixtureJson {
contract SP1ICS07TendermintTest is Test {
using stdJson for string;

// TODO: Test non-mock ics07Tendermint, once we have a way to generate the fixture.
// SP1ICS07Tendermint public ics07Tendermint;
SP1ICS07Tendermint public ics07Tendermint;
SP1ICS07Tendermint public mockIcs07Tendermint;

function setUp() public {
/*
SP1TendermintFixtureJson memory fixture = loadFixture("fixture.json");
SP1ICS07TendermintFixtureJson memory fixture = loadFixture(
"fixture.json"
);
SP1Verifier verifier = new SP1Verifier();
ics07Tendermint = new SP1ICS07Tendermint(
fixture.vkey,
address(verifier),
fixture.trustedClientState,
fixture.trustedConsensusState
);
*/

SP1ICS07TendermintFixtureJson memory mockFixture = loadFixture(
"mock_fixture.json"
Expand Down Expand Up @@ -111,6 +110,46 @@ contract SP1ICS07TendermintTest is Test {
return fixture;
}

// Confirm that submitting a real proof passes the verifier.
function test_ValidSP1ICS07Tendermint() public {
SP1ICS07TendermintFixtureJson memory fixture = loadFixture(
"fixture.json"
);

ics07Tendermint.verifyIcs07UpdateClientProof(
fixture.proof,
fixture.publicValues
);

(
string memory chain_id,
ICS07Tendermint.TrustThreshold memory trust_level,
ICS07Tendermint.Height memory latest_height,
uint64 trusting_period,
uint64 unbonding_period,
bool is_frozen
) = ics07Tendermint.clientState();

assert(keccak256(bytes(chain_id)) == keccak256(bytes("mocha-4")));
assert(trust_level.numerator == 1);
assert(trust_level.denominator == 3);
assert(latest_height.revision_number == 4);
assert(latest_height.revision_height == 2110668);
assert(trusting_period == 1_209_600_000_000_000);
assert(unbonding_period == 1_209_600_000_000_000);
assert(is_frozen == false);

(
uint64 timestamp,
bytes memory root,
bytes memory next_validators_hash
) = ics07Tendermint.consensusStates(2110668);

assert(timestamp > 0);
assert(root.length > 0);
assert(next_validators_hash.length > 0);
}

// Confirm that submitting an empty proof passes the mock verifier.
function test_ValidMockTendermint() public {
SP1ICS07TendermintFixtureJson memory fixture = loadFixture(
Expand Down Expand Up @@ -151,16 +190,28 @@ contract SP1ICS07TendermintTest is Test {
assert(next_validators_hash.length > 0);
}

// Confirm that submitting a non-empty proof with the mock verifier fails. This typically
// indicates that the user has passed in a real proof to the mock verifier.
// Confirm that submitting a non-empty proof with the mock verifier fails.
function test_Invalid_MockTendermint() public {
SP1ICS07TendermintFixtureJson memory fixture = loadFixture(
"mock_fixture.json"
);

vm.expectRevert();
mockIcs07Tendermint.verifyIcs07UpdateClientProof(
bytes("aa"),
bytes("invalid"),
fixture.publicValues
);
}

// Confirm that submitting a random proof with the real verifier fails.
function test_Invalid_SP1ICS07Tendermint() public {
SP1ICS07TendermintFixtureJson memory fixture = loadFixture(
"fixture.json"
);

vm.expectRevert();
ics07Tendermint.verifyIcs07UpdateClientProof(
bytes("invalid"),
fixture.publicValues
);
}
Expand Down
Binary file modified elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
build-program:
cd programs/update-client && cargo prove build
@echo "ELF created at 'program/elf/riscv32im-succinct-zkvm-elf'"

# Run the Solidity tests using `forge test` command
test-foundry:
cd contracts && forge test -vvv

0 comments on commit f781cd4

Please sign in to comment.