From a7add3e518c5003c707ba5447a69796c753b2c1d Mon Sep 17 00:00:00 2001 From: Timofey Luin Date: Wed, 6 Dec 2023 14:03:32 +0100 Subject: [PATCH] add accumulator into rpc response --- Cargo.toml | 26 +++++++++---------- contracts/src/RotateLib.sol | 12 ++++----- contracts/src/Spectre.sol | 4 +-- contracts/test/RotateExternal.sol | 4 +-- .../src/gadget/crypto/sha256_wide/gate.rs | 1 - prover/src/rpc.rs | 24 +++++++++++------ prover/src/rpc_api.rs | 7 +++++ 7 files changed, 46 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3e728886..d9373aa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -93,24 +93,24 @@ ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "5f1ec833718efa0 [patch."https://github.com/axiom-crypto/halo2-lib"] -halo2-base = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false, features = [ - "halo2-pse", - "display", - "jemallocator", -] } -halo2-ecc = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false, features = [ - "halo2-pse", - "jemallocator", -] } -zkevm-hashes = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false } -# halo2-base = { path = "../halo2-lib/halo2-base", default-features = false, features = [ +# halo2-base = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false, features = [ # "halo2-pse", # "display", +# "jemallocator", # ] } -# halo2-ecc = { path = "../halo2-lib/halo2-ecc", default-features = false, features = [ +# halo2-ecc = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false, features = [ # "halo2-pse", +# "jemallocator", # ] } -# zkevm-hashes = { path = "../halo2-lib/hashes/zkevm", default-features = false } +# zkevm-hashes = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false } +halo2-base = { path = "../halo2-lib/halo2-base", default-features = false, features = [ + "halo2-pse", + "display", +] } +halo2-ecc = { path = "../halo2-lib/halo2-ecc", default-features = false, features = [ + "halo2-pse", +] } +zkevm-hashes = { path = "../halo2-lib/hashes/zkevm", default-features = false } [patch."https://github.com/axiom-crypto/snark-verifier.git"] diff --git a/contracts/src/RotateLib.sol b/contracts/src/RotateLib.sol index fa701805..e3582e49 100644 --- a/contracts/src/RotateLib.sol +++ b/contracts/src/RotateLib.sol @@ -16,24 +16,24 @@ library RotateLib { * @param args The arguments for the sync step * @return The public input commitment that can be sent to the verifier contract. */ - function toPublicInputs(RotateInput memory args, bytes32 finalizedHeaderRoot, uint256[12] memory blsAccumulator) internal pure returns (uint256[77] memory) { + function toPublicInputs(RotateInput memory args, bytes32 finalizedHeaderRoot, uint256[12] memory accumulator) internal pure returns (uint256[77] memory) { uint256[77] memory inputs; - for (uint256 i = 0; i < blsAccumulator.length; i++) { - inputs[i] = blsAccumulator[i]; + for (uint256 i = 0; i < accumulator.length; i++) { + inputs[i] = accumulator[i]; } - inputs[blsAccumulator.length] = uint256(EndianConversions.toLittleEndian(uint256(args.syncCommitteePoseidon))); + inputs[accumulator.length] = uint256(EndianConversions.toLittleEndian(uint256(args.syncCommitteePoseidon))); uint256 syncCommitteeSSZNumeric = uint256(args.syncCommitteeSSZ); for (uint256 i = 0; i < 32; i++) { - inputs[blsAccumulator.length + 32 - i] = syncCommitteeSSZNumeric % 2 ** 8; + inputs[accumulator.length + 32 - i] = syncCommitteeSSZNumeric % 2 ** 8; syncCommitteeSSZNumeric = syncCommitteeSSZNumeric / 2 ** 8; } uint256 finalizedHeaderRootNumeric = uint256(finalizedHeaderRoot); for (uint256 j = 0; j < 32; j++) { - inputs[blsAccumulator.length + 64 - j] = finalizedHeaderRootNumeric % 2 ** 8; + inputs[accumulator.length + 64 - j] = finalizedHeaderRootNumeric % 2 ** 8; finalizedHeaderRootNumeric = finalizedHeaderRootNumeric / 2 ** 8; } diff --git a/contracts/src/Spectre.sol b/contracts/src/Spectre.sol index c39a9efa..be2b6fd3 100644 --- a/contracts/src/Spectre.sol +++ b/contracts/src/Spectre.sol @@ -68,7 +68,7 @@ contract Spectre { /// @param rotateProof The proof for the rotation /// @param stepInput The input to the sync step. /// @param stepProof The proof for the sync step - function rotate(RotateLib.RotateInput calldata rotateInput, bytes calldata rotateProof, SyncStepLib.SyncStepInput calldata stepInput, bytes calldata stepProof, uint256[12] memory blsAccumulator) external { + function rotate(RotateLib.RotateInput calldata rotateInput, bytes calldata rotateProof, SyncStepLib.SyncStepInput calldata stepInput, bytes calldata stepProof, uint256[12] memory accumulator) external { // *step phase* // This allows trusting that the current sync committee has signed off on the finalizedHeaderRoot which is used as the base of the SSZ proof // that checks the new committee is in the beacon state 'next_sync_committee' field. It also allows trusting the finalizedSlot which is @@ -85,7 +85,7 @@ contract Spectre { // that there exists an SSZ proof that can verify this SSZ commitment to the committee is in the state uint256 currentPeriod = getSyncCommitteePeriod(stepInput.finalizedSlot); uint256 nextPeriod = currentPeriod + 1; - uint256[77] memory verifierInput = rotateInput.toPublicInputs(stepInput.finalizedHeaderRoot, blsAccumulator); + uint256[77] memory verifierInput = rotateInput.toPublicInputs(stepInput.finalizedHeaderRoot, accumulator); bool rotateSuccess = committeeUpdateVerifier.verify(verifierInput, rotateProof); if (!rotateSuccess) { revert("Rotation proof verification failed"); diff --git a/contracts/test/RotateExternal.sol b/contracts/test/RotateExternal.sol index 78fd352d..0e6ed292 100644 --- a/contracts/test/RotateExternal.sol +++ b/contracts/test/RotateExternal.sol @@ -11,8 +11,8 @@ import { RotateLib } from "../src/RotateLib.sol"; contract RotateExternal { using RotateLib for RotateLib.RotateInput; - function toPublicInputs(RotateLib.RotateInput calldata args, bytes32 finalizedHeaderRoot, uint256[12] memory blsAccumulator) public pure returns (uint256[] memory) { - uint256[77] memory commitment = args.toPublicInputs(finalizedHeaderRoot, blsAccumulator); + function toPublicInputs(RotateLib.RotateInput calldata args, bytes32 finalizedHeaderRoot, uint256[12] memory accumulator) public pure returns (uint256[] memory) { + uint256[77] memory commitment = args.toPublicInputs(finalizedHeaderRoot, accumulator); // copy all elements into a dynamic array. We need to do this because ethers-rs has a bug that can't support uint256[65] return types uint256[] memory result = new uint256[](77); for (uint256 i = 0; i < commitment.length; i++) { diff --git a/lightclient-circuits/src/gadget/crypto/sha256_wide/gate.rs b/lightclient-circuits/src/gadget/crypto/sha256_wide/gate.rs index 047145ad..c5f52093 100644 --- a/lightclient-circuits/src/gadget/crypto/sha256_wide/gate.rs +++ b/lightclient-circuits/src/gadget/crypto/sha256_wide/gate.rs @@ -71,7 +71,6 @@ impl VirtualRegionManager for ShaBitGateManager { type Config = Sha256CircuitConfig; fn assign_raw(&self, config: &Self::Config, region: &mut Region) { - // config.annotate_columns_in_region(region); let mut copy_manager = self.copy_manager.lock().unwrap(); config diff --git a/prover/src/rpc.rs b/prover/src/rpc.rs index d5d92548..fa42c0c5 100644 --- a/prover/src/rpc.rs +++ b/prover/src/rpc.rs @@ -22,9 +22,10 @@ use url::Url; pub type JsonRpcServerState = Arc>; use crate::rpc_api::{ - EvmProofResult, GenProofRotationParams, GenProofRotationWithWitnessParams, GenProofStepParams, - GenProofStepWithWitnessParams, SyncCommitteePoseidonParams, SyncCommitteePoseidonResult, - EVM_PROOF_ROTATION_CIRCUIT, EVM_PROOF_ROTATION_CIRCUIT_WITH_WITNESS, EVM_PROOF_STEP_CIRCUIT, + AggregatedEvmProofResult, EvmProofResult, GenProofRotationParams, + GenProofRotationWithWitnessParams, GenProofStepParams, GenProofStepWithWitnessParams, + SyncCommitteePoseidonParams, SyncCommitteePoseidonResult, EVM_PROOF_ROTATION_CIRCUIT, + EVM_PROOF_ROTATION_CIRCUIT_WITH_WITNESS, EVM_PROOF_STEP_CIRCUIT, EVM_PROOF_STEP_CIRCUIT_WITH_WITNESS, SYNC_COMMITTEE_POSEIDON_COMPRESSED, SYNC_COMMITTEE_POSEIDON_UNCOMPRESSED, }; @@ -142,17 +143,20 @@ pub(crate) async fn gen_evm_proof_rotation_circuit_handler( let public_inputs = instances[0] .iter() .map(|pi| U256::from_little_endian(&pi.to_bytes())) - .collect(); + .collect_vec(); + let mut accumulator = [U256::zero(); 12]; + accumulator.clone_from_slice(&public_inputs[0..12]); - Ok(EvmProofResult { + Ok(AggregatedEvmProofResult { proof, + accumulator, public_inputs, }) } pub(crate) async fn gen_evm_proof_rotation_circuit_with_witness_handler( Params(params): Params, -) -> Result { +) -> Result { let GenProofRotationWithWitnessParams { spec, light_client_update, @@ -221,9 +225,13 @@ pub(crate) async fn gen_evm_proof_rotation_circuit_with_witness_handler( let public_inputs = instances[0] .iter() .map(|pi| U256::from_little_endian(&pi.to_bytes())) - .collect(); - Ok(EvmProofResult { + .collect_vec(); + let mut accumulator = [U256::zero(); 12]; + accumulator.clone_from_slice(&public_inputs[0..12]); + + Ok(AggregatedEvmProofResult { proof, + accumulator, public_inputs, }) } diff --git a/prover/src/rpc_api.rs b/prover/src/rpc_api.rs index 1f92264c..95c70a01 100644 --- a/prover/src/rpc_api.rs +++ b/prover/src/rpc_api.rs @@ -43,6 +43,13 @@ pub struct EvmProofResult { pub public_inputs: Vec, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AggregatedEvmProofResult { + pub proof: Vec, + pub accumulator: [U256; 12], + pub public_inputs: Vec, +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SyncCommitteePoseidonParams { pub pubkeys: Vec>,