diff --git a/Cargo.lock b/Cargo.lock index 053a5bc..85587a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5319,6 +5319,8 @@ dependencies = [ "ibc-core-host", "ibc-primitives", "serde", + "serde_cbor", + "serde_json", "sha2 0.10.8", "sp1-ics07-tendermint-shared", "sp1-zkvm", diff --git a/Cargo.toml b/Cargo.toml index d833c19..873e141 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,12 +33,13 @@ ibc-client-tendermint-types = { version = "0.53.0", default-features = false } serde = { version = "1.0", default-features = false } sha2 = { version = "0.10.8", default-features = false } alloy-sol-types = "0.7.2" +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" } reqwest = { version = "0.11", features = ["json"] } tokio = { version = "1", features = ["full"] } -serde_json = { version = "1.0", default-features = false, features = ["alloc"] } tendermint = { version = "0.36.0", default-features = false } ibc-core-client-types = { version = "0.53.0", default-features = false } ibc-core-commitment-types = { version = "0.53.0", default-features = false } @@ -49,7 +50,6 @@ time = { version = "0.3", default-features = false, features = ["macros", "parsi alloy-primitives = "0.7.2" bincode = "1.3.3" itertools = "0.12.1" -serde_cbor = "0.11.2" dotenv = "0.15.0" subtle-encoding = "0.5.1" ethers = "2.0.14" diff --git a/contracts/fixtures/mock_fixture.json b/contracts/fixtures/mock_fixture.json new file mode 100644 index 000000000..eb9767b --- /dev/null +++ b/contracts/fixtures/mock_fixture.json @@ -0,0 +1,9 @@ +{ + "trustedClientState": "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034c200000000000000000000000000000000000000000000000000044c1ff252000000000000000000000000000000000000000000000000000000044c1ff2520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000", + "trustedConsensusState": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c419", + "targetConsensusState": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c419", + "targetHeight": 2110668, + "vkey": "0x0028d036f6404b30d0c8b3fdb4e64852b04f78d54115702b299f18afb8b00ef4", + "publicValues": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034c2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034cc00000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000044c1ff252000000000000000000000000000000000000000000000000000017db9e47e5d87cc800000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000", + "proof": "0x00000000" +} \ No newline at end of file diff --git a/contracts/src/fixtures/fixture.json b/contracts/src/fixtures/fixture.json deleted file mode 100644 index e7f7d14..000000000 --- a/contracts/src/fixtures/fixture.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "a": 1268, - "b": 1926, - "n": 500, - "vkey": "0x000c413c257554c0d44f840ea4e6e3cf6acf1ec722af839547814ce9632fd6bf", - "publicValues": "0x00000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000004f40000000000000000000000000000000000000000000000000000000000000786", - "proof": "0x1b24bf0ece10786a2307e121b48c2c90c4b07641f81b773502cb132296a837c61c37e1fb4402606cacf385295f7b4832d2222f9ecd9803d022c09fb159e8af8f0fd2cb1fceb65e32058b0f7e04734682cca35b917098b6e0a95aeb02f69272c4168899e7867a5ddfa8246ec4fe35a0e2d2ac85355a26b2490ed78aea20a2869a115b66835ee849fa9fbd3462138bccb3092b4f4cb8cdd5af495ae5ab06f0e1a00c043787dcda55e88dca9a6b845806f626b29c0d191aaf48ae93d00e02ffda7a2680eaf720b34b00aa4477b6b9b4512e0cc94b2df5a865a6c0cb491bdc834f5800c80881e1ce55a364dcce58fb1daaaf9f5986845036b1831024e03072a3ac56051d6c07a287a27414da42ba86bf42cc9d0ef7f17ebb1226f6b263086c2d77b910466c8d8b6675c0d0fce875f6b594722ad5bdaeeca7d4b673467adf065cf00d2f2ecdf78010fe75f1212dd9c6540c96a6e1eb11530290e966699018c1e41d7b07e3a1a08cb13adcf536851e5f58e33f464321118b67f8c80db338733c3bda72039aa214dfe5015f117b6f876b018199424510024b2946bb5f8027245225ff8b240237bdef147c509f04f33a09da19549a27411430c059cd1376f2706549b6671694bb18973c35c9fe8cc4d40f08c60aca4c277ddf09eb2e095556f3c3156ba51550b6a94fd21d4540764d093fb39e4e6c4517bd4ccc87c21f08fdd4588ff27b032cbbfb8c6a8cd431524521677d40aed6700eac960e2ca5f66c6f19cbcbe1af16f962c9e5eae242aab756079cee9a1419474da4e3f5d531f70738e6dac99dd40858cee714f519e6af127d3c57553c1e3ace3206dc24866f6dce3b6a9fa99ced10ef7440dc5227ab24c05201207fdfeb341fbe716f2a969c9663d6b2188c25271abff2b7c68177be370f2d804306693461a5f749de729433ad45e6eff0b692e216c9216e5596d7a39e5971c5bcfed0cebb520014059ec9ade2c7a1196d967f4121aa5603cda863fbda14a380853fdac1e09de824fc8bb65c29ef2fd78d32aa8e24bef20ab27682cd82dcaee11a478bc5f9da361d87262686b1b2d91f135a10d3120954d3a8f3f5c14c069730d0c9bfc2bb86f7cd6a106e294f1ecddd3543b7110bc67355e1fc211b968f314ebcf9ea8352a01d0b9a1bbaac88457409b49388ac189007a6b62c2839220edd1f012ff5331baec07c4077522fce86fd3b8931e8a4" -} \ No newline at end of file diff --git a/elf/riscv32im-succinct-zkvm-elf b/elf/riscv32im-succinct-zkvm-elf index 2dcd5df..590ed89 100755 Binary files a/elf/riscv32im-succinct-zkvm-elf and b/elf/riscv32im-succinct-zkvm-elf differ diff --git a/operator/bin/fixture.rs b/operator/bin/fixture.rs index 19fccfc..2bdfc7a 100644 --- a/operator/bin/fixture.rs +++ b/operator/bin/fixture.rs @@ -121,7 +121,7 @@ async fn main() -> anyhow::Result<()> { // Generate a header update proof for the specified blocks. let proof_data = tendermint_prover.generate_ics07_update_client_proof( - &trusted_consensus_state, + &trusted_consensus_state.clone().into(), &proposed_header, &contract_env, ); diff --git a/operator/bin/operator.rs b/operator/bin/operator.rs index e91db8d..7840b47 100644 --- a/operator/bin/operator.rs +++ b/operator/bin/operator.rs @@ -76,7 +76,7 @@ async fn main() -> anyhow::Result<()> { // Generate a proof of the transition from the trusted block to the target block. let proof_data = prover.generate_ics07_update_client_proof( - &trusted_consensus_state.into(), + &trusted_consensus_state, &proposed_header, &contract_env, ); diff --git a/operator/src/lib.rs b/operator/src/lib.rs index 74894fb..b0930aa 100644 --- a/operator/src/lib.rs +++ b/operator/src/lib.rs @@ -1,4 +1,6 @@ -use ibc_client_tendermint::types::{ConsensusState, Header}; +use alloy_sol_types::SolValue; +use ibc_client_tendermint::types::Header; +use sp1_ics07_tendermint_shared::types::ics07_tendermint::ConsensusState; use sp1_ics07_tendermint_update_client::types::validation::Env; use sp1_sdk::{ProverClient, SP1PlonkBn254Proof, SP1ProvingKey, SP1Stdin, SP1VerifyingKey}; @@ -44,7 +46,7 @@ impl SP1ICS07TendermintProver { ) -> SP1PlonkBn254Proof { // Encode the light blocks to be input into our program. // TODO: make sure the encoding is correct. - let encoded_1 = serde_cbor::to_vec(trusted_consensus_state).unwrap(); + let encoded_1 = trusted_consensus_state.abi_encode(); let encoded_2 = serde_cbor::to_vec(proposed_header).unwrap(); let encoded_3 = serde_cbor::to_vec(contract_env).unwrap(); diff --git a/programs/update-client/Cargo.toml b/programs/update-client/Cargo.toml index f58e4a6..975e8a8 100644 --- a/programs/update-client/Cargo.toml +++ b/programs/update-client/Cargo.toml @@ -19,3 +19,5 @@ ibc-core-handler-types = { workspace = true } serde = { workspace = true } sha2 = { workspace = true } alloy-sol-types = { workspace = true } +serde_cbor = { workspace = true } +serde_json = { workspace = true } diff --git a/programs/update-client/src/main.rs b/programs/update-client/src/main.rs index b5497ed..61925e4 100644 --- a/programs/update-client/src/main.rs +++ b/programs/update-client/src/main.rs @@ -19,7 +19,9 @@ use ibc_client_tendermint::{ types::{ConsensusState, Header, TENDERMINT_CLIENT_TYPE}, }; use ibc_core_host::types::identifiers::{ChainId, ClientId}; -use sp1_ics07_tendermint_shared::types::ics07_tendermint; +use sp1_ics07_tendermint_shared::types::ics07_tendermint::{ + self, ConsensusState as SolConsensusState, +}; use sp1_ics07_tendermint_update_client::types; use tendermint_light_client_verifier::{options::Options, ProdVerifier}; @@ -28,12 +30,16 @@ use tendermint_light_client_verifier::{options::Options, ProdVerifier}; /// # Panics /// Panics if the verification fails. pub fn main() { - // input 1: the trusted consensus state - let trusted_consensus_state = sp1_zkvm::io::read::(); - // input 2: the proposed header - let proposed_header = sp1_zkvm::io::read::
(); + let encoded_1 = sp1_zkvm::io::read_vec(); + let encoded_2 = sp1_zkvm::io::read_vec(); + let encoded_3 = sp1_zkvm::io::read_vec(); + // input 3: environment - let env = sp1_zkvm::io::read::(); + let env = serde_cbor::from_slice::(&encoded_3).unwrap(); + // input 2: the proposed header + let proposed_header = serde_cbor::from_slice::
(&encoded_2).unwrap(); + // input 1: the trusted consensus state + let trusted_consensus_state = SolConsensusState::abi_decode(&encoded_1, true).unwrap(); let client_id = ClientId::new(TENDERMINT_CLIENT_TYPE, 0).unwrap(); let chain_id = ChainId::from_str(&env.chain_id).unwrap(); @@ -42,8 +48,10 @@ pub fn main() { trusting_period: Duration::from_nanos(env.trusting_period), clock_drift: Duration::default(), }; - let ctx = - types::validation::ClientValidationCtx::new(env.clone(), trusted_consensus_state.clone()); + let ctx = types::validation::ClientValidationCtx::new( + env.clone(), + trusted_consensus_state.clone().into(), + ); verify_header::<_, sha2::Sha256>( &ctx, @@ -66,7 +74,7 @@ pub fn main() { let new_consensus_state = ConsensusState::from(proposed_header); let output = types::output::SP1ICS07TendermintOutput { - trusted_consensus_state: trusted_consensus_state.into(), + trusted_consensus_state, new_consensus_state: new_consensus_state.into(), env, trusted_height,