From 1a8ed2b8f90c32302e6eaca9c0bea28231f2250f Mon Sep 17 00:00:00 2001 From: jeanmon Date: Fri, 8 Sep 2023 12:10:08 +0000 Subject: [PATCH 1/8] 2116 - migrate cbind routine for merge rollup to msgpack --- .../aztec3/circuits/rollup/merge/.test.cpp | 82 ++-- .../aztec3/circuits/rollup/merge/c_bind.cpp | 26 +- .../src/aztec3/circuits/rollup/merge/c_bind.h | 7 +- .../src/kernel_prover/proof_creator.ts | 6 +- .../circuits.js/src/cbind/circuits.gen.ts | 355 ++++++++++++++++++ yarn-project/circuits.js/src/cbind/types.ts | 23 ++ .../src/rollup/rollup_wasm_wrapper.test.ts | 64 ++-- .../src/rollup/rollup_wasm_wrapper.ts | 20 +- .../base_or_merge_rollup_public_inputs.ts | 10 +- .../src/structs/rollup/base_rollup.ts | 16 +- .../structs/rollup/previous_rollup_data.ts | 4 +- .../circuits.js/src/tests/factories.ts | 6 +- .../src/block_builder/solo_block_builder.ts | 8 +- .../sequencer-client/src/simulator/rollup.ts | 12 +- 14 files changed, 496 insertions(+), 143 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp index 845cc9b90e6..5aa4a30e619 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp @@ -28,46 +28,46 @@ class merge_rollup_tests : public ::testing::Test { protected: static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../barretenberg/cpp/srs_db/ignition"); } - static void run_cbind(MergeRollupInputs& merge_rollup_inputs, - BaseOrMergeRollupPublicInputs& expected_public_inputs, - bool compare_pubins = true) - { - info("Retesting via cbinds...."); - std::vector merge_rollup_inputs_vec; - serialize::write(merge_rollup_inputs_vec, merge_rollup_inputs); - - uint8_t const* public_inputs_buf = nullptr; - // info("simulating circuit via cbind"); - size_t public_inputs_size = 0; - info("creating proof"); - auto* circuit_failure_ptr = - merge_rollup__sim(merge_rollup_inputs_vec.data(), &public_inputs_size, &public_inputs_buf); - ASSERT_TRUE(circuit_failure_ptr == nullptr); - // info("PublicInputs size: ", public_inputs_size); - - if (compare_pubins) { - BaseOrMergeRollupPublicInputs public_inputs; - uint8_t const* public_inputs_buf_tmp = public_inputs_buf; - serialize::read(public_inputs_buf_tmp, public_inputs); - ASSERT_EQ(public_inputs.calldata_hash.size(), expected_public_inputs.calldata_hash.size()); - for (size_t i = 0; i < public_inputs.calldata_hash.size(); i++) { - ASSERT_EQ(public_inputs.calldata_hash[i], expected_public_inputs.calldata_hash[i]); - } - - std::vector expected_public_inputs_vec; - serialize::write(expected_public_inputs_vec, expected_public_inputs); - - ASSERT_EQ(public_inputs_size, expected_public_inputs_vec.size()); - // Just compare the first 10 bytes of the serialized public outputs - if (public_inputs_size > 10) { - // for (size_t 0; i < public_inputs_size; i++) { - for (size_t i = 0; i < 10; i++) { - ASSERT_EQ(public_inputs_buf[i], expected_public_inputs_vec[i]); - } - } - } - free((void*)public_inputs_buf); - } + // static void run_cbind(MergeRollupInputs& merge_rollup_inputs, + // BaseOrMergeRollupPublicInputs& expected_public_inputs, + // bool compare_pubins = true) + // { + // info("Retesting via cbinds...."); + // std::vector merge_rollup_inputs_vec; + // serialize::write(merge_rollup_inputs_vec, merge_rollup_inputs); + + // uint8_t const* public_inputs_buf = nullptr; + // // info("simulating circuit via cbind"); + // size_t public_inputs_size = 0; + // info("creating proof"); + // auto* circuit_failure_ptr = + // merge_rollup__sim(merge_rollup_inputs_vec.data(), &public_inputs_size, &public_inputs_buf); + // ASSERT_TRUE(circuit_failure_ptr == nullptr); + // // info("PublicInputs size: ", public_inputs_size); + + // if (compare_pubins) { + // BaseOrMergeRollupPublicInputs public_inputs; + // uint8_t const* public_inputs_buf_tmp = public_inputs_buf; + // serialize::read(public_inputs_buf_tmp, public_inputs); + // ASSERT_EQ(public_inputs.calldata_hash.size(), expected_public_inputs.calldata_hash.size()); + // for (size_t i = 0; i < public_inputs.calldata_hash.size(); i++) { + // ASSERT_EQ(public_inputs.calldata_hash[i], expected_public_inputs.calldata_hash[i]); + // } + + // std::vector expected_public_inputs_vec; + // serialize::write(expected_public_inputs_vec, expected_public_inputs); + + // ASSERT_EQ(public_inputs_size, expected_public_inputs_vec.size()); + // // Just compare the first 10 bytes of the serialized public outputs + // if (public_inputs_size > 10) { + // // for (size_t 0; i < public_inputs_size; i++) { + // for (size_t i = 0; i < 10; i++) { + // ASSERT_EQ(public_inputs_buf[i], expected_public_inputs_vec[i]); + // } + // } + // } + // free((void*)public_inputs_buf); + // } }; TEST_F(merge_rollup_tests, native_different_rollup_type_fails) @@ -299,6 +299,6 @@ TEST_F(merge_rollup_tests, native_merge_cbind) ASSERT_FALSE(builder.failed()); BaseOrMergeRollupPublicInputs ignored_public_inputs; - run_cbind(inputs, ignored_public_inputs, false); + // run_cbind(inputs, ignored_public_inputs, false); } } // namespace aztec3::circuits::rollup::merge::native_merge_rollup_circuit diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp index fe93b3ac07e..cd52451cc6c 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp @@ -9,32 +9,14 @@ namespace { using NT = aztec3::utils::types::NativeTypes; using DummyCircuitBuilder = aztec3::utils::DummyCircuitBuilder; -using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::MergeRollupInputs; using aztec3::circuits::rollup::merge::merge_rollup_circuit; } // namespace // WASM Cbinds -extern "C" { -WASM_EXPORT uint8_t* merge_rollup__sim(uint8_t const* merge_rollup_inputs_buf, - size_t* merge_rollup_public_inputs_size_out, - uint8_t const** merge_rollup_public_inputs_buf) -{ +CBIND(merge_rollup__sim, [](MergeRollupInputs const& merge_rollup_inputs) { DummyCircuitBuilder builder = DummyCircuitBuilder("merge_rollup__sim"); - MergeRollupInputs merge_rollup_inputs; - serialize::read(merge_rollup_inputs_buf, merge_rollup_inputs); - - BaseOrMergeRollupPublicInputs const public_inputs = merge_rollup_circuit(builder, merge_rollup_inputs); - - // serialize public inputs to bytes vec - std::vector public_inputs_vec; - serialize::write(public_inputs_vec, public_inputs); - // copy public inputs to output buffer - auto* raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); - memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); - *merge_rollup_public_inputs_buf = raw_public_inputs_buf; - *merge_rollup_public_inputs_size_out = public_inputs_vec.size(); - return builder.alloc_and_serialize_first_failure(); -} -} // extern "C" \ No newline at end of file + auto const& public_inputs = merge_rollup_circuit(builder, merge_rollup_inputs); + return builder.result_or_error(public_inputs); +}); \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.h b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.h index c16fdc190e6..5063715b631 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.h +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.h @@ -5,9 +5,4 @@ #include #include -extern "C" { - -WASM_EXPORT uint8_t* merge_rollup__sim(uint8_t const* merge_rollup_inputs_buf, - size_t* merge_rollup_public_inputs_size_out, - uint8_t const** merge_rollup_public_inputs_buf); -} \ No newline at end of file +CBIND_DECL(merge_rollup__sim); \ No newline at end of file diff --git a/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts b/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts index 99b7e464711..cbf02be23d3 100644 --- a/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts +++ b/yarn-project/aztec-rpc/src/kernel_prover/proof_creator.ts @@ -154,11 +154,9 @@ export class KernelProofCreator implements ProofCreator { const proof = makeEmptyProof(); this.log('Ordering Kernel Prover Ordering Completed!'); - const publicInputs = result as KernelCircuitPublicInputsFinal; - return { - publicInputs, - proof, + publicInputs: result, + proof: proof, }; } } diff --git a/yarn-project/circuits.js/src/cbind/circuits.gen.ts b/yarn-project/circuits.js/src/cbind/circuits.gen.ts index b1a272ddc9d..2a1722fc757 100644 --- a/yarn-project/circuits.js/src/cbind/circuits.gen.ts +++ b/yarn-project/circuits.js/src/cbind/circuits.gen.ts @@ -9,10 +9,13 @@ import mapValues from 'lodash.mapvalues'; import { callCbind } from './cbind.js'; import { Address, + AppendOnlyTreeSnapshot, + BaseOrMergeRollupPublicInputs, CallContext, CircuitError, CombinedAccumulatedData, CombinedConstantData, + ConstantRollupData, ContractDeploymentData, ContractStorageRead, ContractStorageUpdateRequest, @@ -27,12 +30,15 @@ import { KernelCircuitPublicInputs, KernelCircuitPublicInputsFinal, MembershipWitness4, + MembershipWitness8, MembershipWitness16, + MergeRollupInputs, NativeAggregationState, NewContractData, OptionallyRevealedData, Point, PreviousKernelData, + PreviousRollupData, PrivateCallData, PrivateCallStackItem, PrivateCircuitPublicInputs, @@ -2228,6 +2234,346 @@ export function fromPublicKernelInputs(o: PublicKernelInputs): MsgpackPublicKern }; } +interface MsgpackAppendOnlyTreeSnapshot { + root: Buffer; + next_available_leaf_index: number; +} + +export function toAppendOnlyTreeSnapshot(o: MsgpackAppendOnlyTreeSnapshot): AppendOnlyTreeSnapshot { + if (o.root === undefined) { + throw new Error('Expected root in AppendOnlyTreeSnapshot deserialization'); + } + if (o.next_available_leaf_index === undefined) { + throw new Error('Expected next_available_leaf_index in AppendOnlyTreeSnapshot deserialization'); + } + return new AppendOnlyTreeSnapshot(Fr.fromBuffer(o.root), o.next_available_leaf_index); +} + +export function fromAppendOnlyTreeSnapshot(o: AppendOnlyTreeSnapshot): MsgpackAppendOnlyTreeSnapshot { + if (o.root === undefined) { + throw new Error('Expected root in AppendOnlyTreeSnapshot serialization'); + } + if (o.nextAvailableLeafIndex === undefined) { + throw new Error('Expected nextAvailableLeafIndex in AppendOnlyTreeSnapshot serialization'); + } + return { + root: toBuffer(o.root), + next_available_leaf_index: o.nextAvailableLeafIndex, + }; +} + +interface MsgpackConstantRollupData { + start_historic_blocks_tree_roots_snapshot: MsgpackAppendOnlyTreeSnapshot; + private_kernel_vk_tree_root: Buffer; + public_kernel_vk_tree_root: Buffer; + base_rollup_vk_hash: Buffer; + merge_rollup_vk_hash: Buffer; + global_variables: MsgpackGlobalVariables; +} + +export function toConstantRollupData(o: MsgpackConstantRollupData): ConstantRollupData { + if (o.start_historic_blocks_tree_roots_snapshot === undefined) { + throw new Error('Expected start_historic_blocks_tree_roots_snapshot in ConstantRollupData deserialization'); + } + if (o.private_kernel_vk_tree_root === undefined) { + throw new Error('Expected private_kernel_vk_tree_root in ConstantRollupData deserialization'); + } + if (o.public_kernel_vk_tree_root === undefined) { + throw new Error('Expected public_kernel_vk_tree_root in ConstantRollupData deserialization'); + } + if (o.base_rollup_vk_hash === undefined) { + throw new Error('Expected base_rollup_vk_hash in ConstantRollupData deserialization'); + } + if (o.merge_rollup_vk_hash === undefined) { + throw new Error('Expected merge_rollup_vk_hash in ConstantRollupData deserialization'); + } + if (o.global_variables === undefined) { + throw new Error('Expected global_variables in ConstantRollupData deserialization'); + } + return new ConstantRollupData( + toAppendOnlyTreeSnapshot(o.start_historic_blocks_tree_roots_snapshot), + Fr.fromBuffer(o.private_kernel_vk_tree_root), + Fr.fromBuffer(o.public_kernel_vk_tree_root), + Fr.fromBuffer(o.base_rollup_vk_hash), + Fr.fromBuffer(o.merge_rollup_vk_hash), + toGlobalVariables(o.global_variables), + ); +} + +export function fromConstantRollupData(o: ConstantRollupData): MsgpackConstantRollupData { + if (o.startHistoricBlocksTreeRootsSnapshot === undefined) { + throw new Error('Expected startHistoricBlocksTreeRootsSnapshot in ConstantRollupData serialization'); + } + if (o.privateKernelVkTreeRoot === undefined) { + throw new Error('Expected privateKernelVkTreeRoot in ConstantRollupData serialization'); + } + if (o.publicKernelVkTreeRoot === undefined) { + throw new Error('Expected publicKernelVkTreeRoot in ConstantRollupData serialization'); + } + if (o.baseRollupVkHash === undefined) { + throw new Error('Expected baseRollupVkHash in ConstantRollupData serialization'); + } + if (o.mergeRollupVkHash === undefined) { + throw new Error('Expected mergeRollupVkHash in ConstantRollupData serialization'); + } + if (o.globalVariables === undefined) { + throw new Error('Expected globalVariables in ConstantRollupData serialization'); + } + return { + start_historic_blocks_tree_roots_snapshot: fromAppendOnlyTreeSnapshot(o.startHistoricBlocksTreeRootsSnapshot), + private_kernel_vk_tree_root: toBuffer(o.privateKernelVkTreeRoot), + public_kernel_vk_tree_root: toBuffer(o.publicKernelVkTreeRoot), + base_rollup_vk_hash: toBuffer(o.baseRollupVkHash), + merge_rollup_vk_hash: toBuffer(o.mergeRollupVkHash), + global_variables: fromGlobalVariables(o.globalVariables), + }; +} + +interface MsgpackBaseOrMergeRollupPublicInputs { + rollup_type: number; + rollup_subtree_height: Buffer; + end_aggregation_object: MsgpackNativeAggregationState; + constants: MsgpackConstantRollupData; + start_private_data_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + end_private_data_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + start_nullifier_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + end_nullifier_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + start_contract_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + end_contract_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + start_public_data_tree_root: Buffer; + end_public_data_tree_root: Buffer; + calldata_hash: Tuple; +} + +export function toBaseOrMergeRollupPublicInputs( + o: MsgpackBaseOrMergeRollupPublicInputs, +): BaseOrMergeRollupPublicInputs { + if (o.rollup_type === undefined) { + throw new Error('Expected rollup_type in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.rollup_subtree_height === undefined) { + throw new Error('Expected rollup_subtree_height in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.end_aggregation_object === undefined) { + throw new Error('Expected end_aggregation_object in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.constants === undefined) { + throw new Error('Expected constants in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.start_private_data_tree_snapshot === undefined) { + throw new Error('Expected start_private_data_tree_snapshot in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.end_private_data_tree_snapshot === undefined) { + throw new Error('Expected end_private_data_tree_snapshot in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.start_nullifier_tree_snapshot === undefined) { + throw new Error('Expected start_nullifier_tree_snapshot in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.end_nullifier_tree_snapshot === undefined) { + throw new Error('Expected end_nullifier_tree_snapshot in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.start_contract_tree_snapshot === undefined) { + throw new Error('Expected start_contract_tree_snapshot in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.end_contract_tree_snapshot === undefined) { + throw new Error('Expected end_contract_tree_snapshot in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.start_public_data_tree_root === undefined) { + throw new Error('Expected start_public_data_tree_root in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.end_public_data_tree_root === undefined) { + throw new Error('Expected end_public_data_tree_root in BaseOrMergeRollupPublicInputs deserialization'); + } + if (o.calldata_hash === undefined) { + throw new Error('Expected calldata_hash in BaseOrMergeRollupPublicInputs deserialization'); + } + return new BaseOrMergeRollupPublicInputs( + o.rollup_type, + Fr.fromBuffer(o.rollup_subtree_height), + toNativeAggregationState(o.end_aggregation_object), + toConstantRollupData(o.constants), + toAppendOnlyTreeSnapshot(o.start_private_data_tree_snapshot), + toAppendOnlyTreeSnapshot(o.end_private_data_tree_snapshot), + toAppendOnlyTreeSnapshot(o.start_nullifier_tree_snapshot), + toAppendOnlyTreeSnapshot(o.end_nullifier_tree_snapshot), + toAppendOnlyTreeSnapshot(o.start_contract_tree_snapshot), + toAppendOnlyTreeSnapshot(o.end_contract_tree_snapshot), + Fr.fromBuffer(o.start_public_data_tree_root), + Fr.fromBuffer(o.end_public_data_tree_root), + mapTuple(o.calldata_hash, (v: Buffer) => Fr.fromBuffer(v)), + ); +} + +export function fromBaseOrMergeRollupPublicInputs( + o: BaseOrMergeRollupPublicInputs, +): MsgpackBaseOrMergeRollupPublicInputs { + if (o.rollupType === undefined) { + throw new Error('Expected rollupType in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.rollupSubtreeHeight === undefined) { + throw new Error('Expected rollupSubtreeHeight in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.endAggregationObject === undefined) { + throw new Error('Expected endAggregationObject in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.constants === undefined) { + throw new Error('Expected constants in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.startPrivateDataTreeSnapshot === undefined) { + throw new Error('Expected startPrivateDataTreeSnapshot in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.endPrivateDataTreeSnapshot === undefined) { + throw new Error('Expected endPrivateDataTreeSnapshot in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.startNullifierTreeSnapshot === undefined) { + throw new Error('Expected startNullifierTreeSnapshot in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.endNullifierTreeSnapshot === undefined) { + throw new Error('Expected endNullifierTreeSnapshot in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.startContractTreeSnapshot === undefined) { + throw new Error('Expected startContractTreeSnapshot in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.endContractTreeSnapshot === undefined) { + throw new Error('Expected endContractTreeSnapshot in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.startPublicDataTreeRoot === undefined) { + throw new Error('Expected startPublicDataTreeRoot in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.endPublicDataTreeRoot === undefined) { + throw new Error('Expected endPublicDataTreeRoot in BaseOrMergeRollupPublicInputs serialization'); + } + if (o.calldataHash === undefined) { + throw new Error('Expected calldataHash in BaseOrMergeRollupPublicInputs serialization'); + } + return { + rollup_type: o.rollupType, + rollup_subtree_height: toBuffer(o.rollupSubtreeHeight), + end_aggregation_object: fromNativeAggregationState(o.endAggregationObject), + constants: fromConstantRollupData(o.constants), + start_private_data_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startPrivateDataTreeSnapshot), + end_private_data_tree_snapshot: fromAppendOnlyTreeSnapshot(o.endPrivateDataTreeSnapshot), + start_nullifier_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startNullifierTreeSnapshot), + end_nullifier_tree_snapshot: fromAppendOnlyTreeSnapshot(o.endNullifierTreeSnapshot), + start_contract_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startContractTreeSnapshot), + end_contract_tree_snapshot: fromAppendOnlyTreeSnapshot(o.endContractTreeSnapshot), + start_public_data_tree_root: toBuffer(o.startPublicDataTreeRoot), + end_public_data_tree_root: toBuffer(o.endPublicDataTreeRoot), + calldata_hash: mapTuple(o.calldataHash, (v: Fr) => toBuffer(v)), + }; +} + +interface MsgpackMembershipWitness8 { + leaf_index: Buffer; + sibling_path: Tuple; +} + +export function toMembershipWitness8(o: MsgpackMembershipWitness8): MembershipWitness8 { + if (o.leaf_index === undefined) { + throw new Error('Expected leaf_index in MembershipWitness8 deserialization'); + } + if (o.sibling_path === undefined) { + throw new Error('Expected sibling_path in MembershipWitness8 deserialization'); + } + return new MembershipWitness8( + Fr.fromBuffer(o.leaf_index), + mapTuple(o.sibling_path, (v: Buffer) => Fr.fromBuffer(v)), + ); +} + +export function fromMembershipWitness8(o: MembershipWitness8): MsgpackMembershipWitness8 { + if (o.leafIndex === undefined) { + throw new Error('Expected leafIndex in MembershipWitness8 serialization'); + } + if (o.siblingPath === undefined) { + throw new Error('Expected siblingPath in MembershipWitness8 serialization'); + } + return { + leaf_index: toBuffer(o.leafIndex), + sibling_path: mapTuple(o.siblingPath, (v: Fr) => toBuffer(v)), + }; +} + +interface MsgpackPreviousRollupData { + base_or_merge_rollup_public_inputs: MsgpackBaseOrMergeRollupPublicInputs; + proof: Buffer; + vk: MsgpackVerificationKeyData; + vk_index: number; + vk_sibling_path: MsgpackMembershipWitness8; +} + +export function toPreviousRollupData(o: MsgpackPreviousRollupData): PreviousRollupData { + if (o.base_or_merge_rollup_public_inputs === undefined) { + throw new Error('Expected base_or_merge_rollup_public_inputs in PreviousRollupData deserialization'); + } + if (o.proof === undefined) { + throw new Error('Expected proof in PreviousRollupData deserialization'); + } + if (o.vk === undefined) { + throw new Error('Expected vk in PreviousRollupData deserialization'); + } + if (o.vk_index === undefined) { + throw new Error('Expected vk_index in PreviousRollupData deserialization'); + } + if (o.vk_sibling_path === undefined) { + throw new Error('Expected vk_sibling_path in PreviousRollupData deserialization'); + } + return new PreviousRollupData( + toBaseOrMergeRollupPublicInputs(o.base_or_merge_rollup_public_inputs), + Proof.fromMsgpackBuffer(o.proof), + toVerificationKeyData(o.vk), + o.vk_index, + toMembershipWitness8(o.vk_sibling_path), + ); +} + +export function fromPreviousRollupData(o: PreviousRollupData): MsgpackPreviousRollupData { + if (o.baseOrMergeRollupPublicInputs === undefined) { + throw new Error('Expected baseOrMergeRollupPublicInputs in PreviousRollupData serialization'); + } + if (o.proof === undefined) { + throw new Error('Expected proof in PreviousRollupData serialization'); + } + if (o.vk === undefined) { + throw new Error('Expected vk in PreviousRollupData serialization'); + } + if (o.vkIndex === undefined) { + throw new Error('Expected vkIndex in PreviousRollupData serialization'); + } + if (o.vkSiblingPath === undefined) { + throw new Error('Expected vkSiblingPath in PreviousRollupData serialization'); + } + return { + base_or_merge_rollup_public_inputs: fromBaseOrMergeRollupPublicInputs(o.baseOrMergeRollupPublicInputs), + proof: o.proof.toMsgpackBuffer(), + vk: fromVerificationKeyData(o.vk), + vk_index: o.vkIndex, + vk_sibling_path: fromMembershipWitness8(o.vkSiblingPath), + }; +} + +interface MsgpackMergeRollupInputs { + previous_rollup_data: Tuple; +} + +export function toMergeRollupInputs(o: MsgpackMergeRollupInputs): MergeRollupInputs { + if (o.previous_rollup_data === undefined) { + throw new Error('Expected previous_rollup_data in MergeRollupInputs deserialization'); + } + return new MergeRollupInputs( + mapTuple(o.previous_rollup_data, (v: MsgpackPreviousRollupData) => toPreviousRollupData(v)), + ); +} + +export function fromMergeRollupInputs(o: MergeRollupInputs): MsgpackMergeRollupInputs { + if (o.previousRollupData === undefined) { + throw new Error('Expected previousRollupData in MergeRollupInputs serialization'); + } + return { + previous_rollup_data: mapTuple(o.previousRollupData, (v: PreviousRollupData) => fromPreviousRollupData(v)), + }; +} + export function abisComputeCommitmentNonce(wasm: IWasmModule, arg0: Fr, arg1: Fr): Fr { return Fr.fromBuffer(callCbind(wasm, 'abis__compute_commitment_nonce', [toBuffer(arg0), toBuffer(arg1)])); } @@ -2325,3 +2671,12 @@ export function publicKernelSim(wasm: IWasmModule, arg0: PublicKernelInputs): Ci callCbind(wasm, 'public_kernel__sim', [fromPublicKernelInputs(arg0)]), ); } +export function mergeRollupSim( + wasm: IWasmModule, + arg0: MergeRollupInputs, +): CircuitError | BaseOrMergeRollupPublicInputs { + return ((v: MsgpackCircuitError | MsgpackBaseOrMergeRollupPublicInputs) => + isCircuitError(v) ? toCircuitError(v) : toBaseOrMergeRollupPublicInputs(v))( + callCbind(wasm, 'merge_rollup__sim', [fromMergeRollupInputs(arg0)]), + ); +} diff --git a/yarn-project/circuits.js/src/cbind/types.ts b/yarn-project/circuits.js/src/cbind/types.ts index e7f4d009f3e..c3f7a5eac9e 100644 --- a/yarn-project/circuits.js/src/cbind/types.ts +++ b/yarn-project/circuits.js/src/cbind/types.ts @@ -25,6 +25,24 @@ export class MembershipWitness16 extends MembershipWitness<16> { } } +/** + * Alias for msgpack which expects a MembershipWitness + N name. + */ +export class MembershipWitness8 extends MembershipWitness<8> { + constructor( + /** + * Index of a leaf in the Merkle tree. + */ + leafIndex: Fr, + /** + * Sibling path of the leaf in the Merkle tree. + */ + siblingPath: Tuple, + ) { + super(8, leafIndex.toBigInt(), siblingPath); + } +} + /** * Alias for msgpack which expects a MembershipWitness + N name. */ @@ -99,6 +117,11 @@ export { PrivateKernelInputsInit, PrivateKernelInputsInner, TxRequest, + PreviousRollupData, + AppendOnlyTreeSnapshot, + BaseOrMergeRollupPublicInputs, + ConstantRollupData, + MergeRollupInputs, } from '../structs/index.js'; export { FunctionSelector } from '@aztec/foundation/abi'; diff --git a/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.test.ts b/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.test.ts index 6b023b6e01f..abbcbf241e6 100644 --- a/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.test.ts +++ b/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.test.ts @@ -1,7 +1,7 @@ import { AggregationObject, CircuitError, MergeRollupInputs, RootRollupInputs, VerificationKey } from '../index.js'; import { makeBaseRollupInputs, makeMergeRollupInputs, makeRootRollupInputs } from '../tests/factories.js'; import { CircuitsWasm } from '../wasm/circuits_wasm.js'; -import { RollupWasmWrapper } from './rollup_wasm_wrapper.js'; +import { RollupWasmWrapper, mergeRollupSim } from './rollup_wasm_wrapper.js'; describe('rollup/rollup_wasm_wrapper', () => { let wasm: CircuitsWasm; @@ -22,22 +22,23 @@ describe('rollup/rollup_wasm_wrapper', () => { }; const fixPreviousRollupInputs = (input: MergeRollupInputs | RootRollupInputs) => { - input.previousRollupData[1].publicInputs.constants = input.previousRollupData[0].publicInputs.constants; - input.previousRollupData[1].publicInputs.startPrivateDataTreeSnapshot = - input.previousRollupData[0].publicInputs.endPrivateDataTreeSnapshot; - input.previousRollupData[1].publicInputs.startNullifierTreeSnapshot = - input.previousRollupData[0].publicInputs.endNullifierTreeSnapshot; - input.previousRollupData[1].publicInputs.startContractTreeSnapshot = - input.previousRollupData[0].publicInputs.endContractTreeSnapshot; - input.previousRollupData[1].publicInputs.startPublicDataTreeRoot = - input.previousRollupData[0].publicInputs.endPublicDataTreeRoot; + input.previousRollupData[1].baseOrMergeRollupPublicInputs.constants = + input.previousRollupData[0].baseOrMergeRollupPublicInputs.constants; + input.previousRollupData[1].baseOrMergeRollupPublicInputs.startPrivateDataTreeSnapshot = + input.previousRollupData[0].baseOrMergeRollupPublicInputs.endPrivateDataTreeSnapshot; + input.previousRollupData[1].baseOrMergeRollupPublicInputs.startNullifierTreeSnapshot = + input.previousRollupData[0].baseOrMergeRollupPublicInputs.endNullifierTreeSnapshot; + input.previousRollupData[1].baseOrMergeRollupPublicInputs.startContractTreeSnapshot = + input.previousRollupData[0].baseOrMergeRollupPublicInputs.endContractTreeSnapshot; + input.previousRollupData[1].baseOrMergeRollupPublicInputs.startPublicDataTreeRoot = + input.previousRollupData[0].baseOrMergeRollupPublicInputs.endPublicDataTreeRoot; }; const makeMergeRollupInputsForCircuit = () => { const input = makeMergeRollupInputs(); for (const previousData of input.previousRollupData) { previousData.vk = VerificationKey.makeFake(); - previousData.publicInputs.endAggregationObject = AggregationObject.makeFake(); + previousData.baseOrMergeRollupPublicInputs.endAggregationObject = AggregationObject.makeFake(); } fixPreviousRollupInputs(input); return input; @@ -56,35 +57,38 @@ describe('rollup/rollup_wasm_wrapper', () => { it('calls merge_rollup__sim', () => { const input = makeMergeRollupInputsForCircuit(); - const output = rollupWasm.simulateMergeRollup(input); + const output = mergeRollupSim(wasm, input); + if (output instanceof CircuitError) { + throw new CircuitError(output.code, output.message); + } + expect(output.rollupType).toEqual(1); expect(output.startContractTreeSnapshot).toEqual( - input.previousRollupData[0].publicInputs.startContractTreeSnapshot, + input.previousRollupData[0].baseOrMergeRollupPublicInputs.startContractTreeSnapshot, ); expect(output.startNullifierTreeSnapshot).toEqual( - input.previousRollupData[0].publicInputs.startNullifierTreeSnapshot, + input.previousRollupData[0].baseOrMergeRollupPublicInputs.startNullifierTreeSnapshot, ); expect(output.startPrivateDataTreeSnapshot).toEqual( - input.previousRollupData[0].publicInputs.startPrivateDataTreeSnapshot, + input.previousRollupData[0].baseOrMergeRollupPublicInputs.startPrivateDataTreeSnapshot, ); expect(output.endPrivateDataTreeSnapshot).toEqual( - input.previousRollupData[1].publicInputs.endPrivateDataTreeSnapshot, + input.previousRollupData[1].baseOrMergeRollupPublicInputs.endPrivateDataTreeSnapshot, ); }); it('calling merge_rollup__sim with different constants should fail', () => { const input = makeMergeRollupInputs(); - try { - rollupWasm.simulateMergeRollup(input); - } catch (e) { - expect(e).toBeInstanceOf(CircuitError); - const err = e as CircuitError; - expect(err.message).toEqual( - `input proofs have different constants -Refer to https://docs.aztec.network/aztec/protocol/errors for more information.`, - ); - expect(err.code).toEqual(7003); - } + + const output = mergeRollupSim(wasm, input); + expect(output instanceof CircuitError).toBeTruthy(); + + const err = output as CircuitError; + expect(err.message).toEqual( + `input proofs have different constants`, + // Refer to https://docs.aztec.network/aztec/protocol/errors for more information.`, + ); + expect(err.code).toEqual(7003); }); // Task to repair this test: https://github.com/AztecProtocol/aztec-packages/issues/1586 @@ -92,14 +96,14 @@ Refer to https://docs.aztec.network/aztec/protocol/errors for more information.` const input = makeRootRollupInputs(); for (const rd of input.previousRollupData) { rd.vk = VerificationKey.makeFake(); - rd.publicInputs.endAggregationObject = AggregationObject.makeFake(); - rd.publicInputs = rollupWasm.simulateBaseRollup(makeBaseRollupInputsForCircuit()); + rd.baseOrMergeRollupPublicInputs.endAggregationObject = AggregationObject.makeFake(); + rd.baseOrMergeRollupPublicInputs = rollupWasm.simulateBaseRollup(makeBaseRollupInputsForCircuit()); } fixPreviousRollupInputs(input); const output = rollupWasm.simulateRootRollup(input); expect(output.startNullifierTreeSnapshot).toEqual( - input.previousRollupData[0].publicInputs.startNullifierTreeSnapshot, + input.previousRollupData[0].baseOrMergeRollupPublicInputs.startNullifierTreeSnapshot, ); }, 15_000); }); diff --git a/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts b/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts index 99f286d8f66..0518ba02180 100644 --- a/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts +++ b/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts @@ -1,13 +1,9 @@ -import { - BaseOrMergeRollupPublicInputs, - BaseRollupInputs, - MergeRollupInputs, - RootRollupInputs, - RootRollupPublicInputs, -} from '../index.js'; +import { BaseOrMergeRollupPublicInputs, BaseRollupInputs, RootRollupInputs, RootRollupPublicInputs } from '../index.js'; import { callWasm } from '../utils/call_wasm.js'; import { CircuitsWasm } from '../wasm/circuits_wasm.js'; +export { mergeRollupSim } from '../cbind/circuits.gen.js'; + /** * A wrapper around `CircuitsWasm` used to expose only the functions relevant for rollup circuits. */ @@ -24,16 +20,6 @@ export class RollupWasmWrapper { return callWasm(this.wasm, 'base_rollup__sim', baseRollupInputs, BaseOrMergeRollupPublicInputs); } - /** - * Simulates the merge rollup circuit from its inputs. - * @param mergeRollupInputs - Inputs to the circuit. - * @returns The result of the simulation. Since the circuits are recursive the result is in a form which can be used - * as an input of the next iteration. - */ - public simulateMergeRollup(mergeRollupInputs: MergeRollupInputs): BaseOrMergeRollupPublicInputs { - return callWasm(this.wasm, 'merge_rollup__sim', mergeRollupInputs, BaseOrMergeRollupPublicInputs); - } - /** * Simulates the root rollup circuit from its inputs. * @param rootRollupInputs - Inputs to the circuit. diff --git a/yarn-project/circuits.js/src/structs/rollup/base_or_merge_rollup_public_inputs.ts b/yarn-project/circuits.js/src/structs/rollup/base_or_merge_rollup_public_inputs.ts index 446c4e2d668..7f616bcabf7 100644 --- a/yarn-project/circuits.js/src/structs/rollup/base_or_merge_rollup_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/rollup/base_or_merge_rollup_public_inputs.ts @@ -6,7 +6,7 @@ import { serializeToBuffer } from '../../utils/serialize.js'; import { AggregationObject } from '../aggregation_object.js'; import { RollupTypes } from '../shared.js'; import { AppendOnlyTreeSnapshot } from './append_only_tree_snapshot.js'; -import { ConstantBaseRollupData } from './base_rollup.js'; +import { ConstantRollupData } from './base_rollup.js'; /** * Output of the base and merge rollup circuits. @@ -22,7 +22,7 @@ export class BaseOrMergeRollupPublicInputs { * Note 1: Base rollup circuit always have a sub tree height of 0. * Note 2: With each merge, the sub tree height increases by 1. */ - public rollupSubTreeHeight: Fr, + public rollupSubtreeHeight: Fr, /** * Native aggregation state at the end of the rollup circuit. */ @@ -30,7 +30,7 @@ export class BaseOrMergeRollupPublicInputs { /** * Data which is forwarded through the rollup circuits unchanged. */ - public constants: ConstantBaseRollupData, + public constants: ConstantRollupData, /** * Snapshot of the private data tree at the start of the rollup circuit. @@ -87,7 +87,7 @@ export class BaseOrMergeRollupPublicInputs { reader.readNumber(), reader.readFr(), reader.readObject(AggregationObject), - reader.readObject(ConstantBaseRollupData), + reader.readObject(ConstantRollupData), reader.readObject(AppendOnlyTreeSnapshot), reader.readObject(AppendOnlyTreeSnapshot), reader.readObject(AppendOnlyTreeSnapshot), @@ -107,7 +107,7 @@ export class BaseOrMergeRollupPublicInputs { toBuffer() { return serializeToBuffer( this.rollupType, - this.rollupSubTreeHeight, + this.rollupSubtreeHeight, this.endAggregationObject, this.constants, diff --git a/yarn-project/circuits.js/src/structs/rollup/base_rollup.ts b/yarn-project/circuits.js/src/structs/rollup/base_rollup.ts index 467cf463ef2..7f3fed8f22f 100644 --- a/yarn-project/circuits.js/src/structs/rollup/base_rollup.ts +++ b/yarn-project/circuits.js/src/structs/rollup/base_rollup.ts @@ -53,7 +53,7 @@ export class NullifierLeafPreimage { /** * Data which is forwarded through the base rollup circuits unchanged. */ -export class ConstantBaseRollupData { +export class ConstantRollupData { constructor( /** * Snapshot of the historic blocks roots tree at the start of the rollup. @@ -82,13 +82,13 @@ export class ConstantBaseRollupData { public globalVariables: GlobalVariables, ) {} - static from(fields: FieldsOf): ConstantBaseRollupData { - return new ConstantBaseRollupData(...ConstantBaseRollupData.getFields(fields)); + static from(fields: FieldsOf): ConstantRollupData { + return new ConstantRollupData(...ConstantRollupData.getFields(fields)); } - static fromBuffer(buffer: Buffer | BufferReader): ConstantBaseRollupData { + static fromBuffer(buffer: Buffer | BufferReader): ConstantRollupData { const reader = BufferReader.asReader(buffer); - return new ConstantBaseRollupData( + return new ConstantRollupData( reader.readObject(AppendOnlyTreeSnapshot), reader.readFr(), reader.readFr(), @@ -98,7 +98,7 @@ export class ConstantBaseRollupData { ); } - static getFields(fields: FieldsOf) { + static getFields(fields: FieldsOf) { return [ fields.startHistoricBlocksTreeRootsSnapshot, fields.privateKernelVkTreeRoot, @@ -110,7 +110,7 @@ export class ConstantBaseRollupData { } toBuffer() { - return serializeToBuffer(...ConstantBaseRollupData.getFields(this)); + return serializeToBuffer(...ConstantRollupData.getFields(this)); } } @@ -203,7 +203,7 @@ export class BaseRollupInputs { /** * Data which is not modified by the base rollup circuit. */ - public constants: ConstantBaseRollupData, + public constants: ConstantRollupData, ) { assertMemberLength(this, 'lowNullifierLeafPreimages', 2 * MAX_NEW_NULLIFIERS_PER_TX); assertMemberLength(this, 'lowNullifierMembershipWitness', 2 * MAX_NEW_NULLIFIERS_PER_TX); diff --git a/yarn-project/circuits.js/src/structs/rollup/previous_rollup_data.ts b/yarn-project/circuits.js/src/structs/rollup/previous_rollup_data.ts index c112e541cf9..db7c2da556f 100644 --- a/yarn-project/circuits.js/src/structs/rollup/previous_rollup_data.ts +++ b/yarn-project/circuits.js/src/structs/rollup/previous_rollup_data.ts @@ -14,7 +14,7 @@ export class PreviousRollupData { /** * Public inputs to the base or merge rollup circuit. */ - public publicInputs: BaseOrMergeRollupPublicInputs, + public baseOrMergeRollupPublicInputs: BaseOrMergeRollupPublicInputs, /** * The proof of the base or merge rollup circuit. */ @@ -38,6 +38,6 @@ export class PreviousRollupData { * @returns The buffer of the serialized previous rollup data. */ public toBuffer(): Buffer { - return serializeToBuffer(this.publicInputs, this.proof, this.vk, this.vkIndex, this.vkSiblingPath); + return serializeToBuffer(this.baseOrMergeRollupPublicInputs, this.proof, this.vk, this.vkIndex, this.vkSiblingPath); } } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 9c6a3656ba6..ad0beb0c05c 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -16,7 +16,7 @@ import { CircuitsWasm, CombinedAccumulatedData, CombinedConstantData, - ConstantBaseRollupData, + ConstantRollupData, ContractDeploymentData, ContractStorageRead, ContractStorageUpdateRequest, @@ -704,8 +704,8 @@ export function makeGlobalVariables(seed = 1, blockNumber: number | undefined = export function makeConstantBaseRollupData( seed = 1, globalVariables: GlobalVariables | undefined = undefined, -): ConstantBaseRollupData { - return ConstantBaseRollupData.from({ +): ConstantRollupData { + return ConstantRollupData.from({ startHistoricBlocksTreeRootsSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x300), privateKernelVkTreeRoot: fr(seed + 0x401), publicKernelVkTreeRoot: fr(seed + 0x402), diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts index bd9ef821a12..29298836852 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts @@ -3,7 +3,7 @@ import { BaseOrMergeRollupPublicInputs, BaseRollupInputs, CircuitsWasm, - ConstantBaseRollupData, + ConstantRollupData, GlobalVariables, HISTORIC_BLOCKS_TREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_HEIGHT, @@ -528,8 +528,8 @@ export class SoloBlockBuilder implements BlockBuilder { return this.getMembershipWitnessFor(blockHash, MerkleTreeId.BLOCKS_TREE, HISTORIC_BLOCKS_TREE_HEIGHT); } - protected async getConstantBaseRollupData(globalVariables: GlobalVariables): Promise { - return ConstantBaseRollupData.from({ + protected async getConstantRollupData(globalVariables: GlobalVariables): Promise { + return ConstantRollupData.from({ baseRollupVkHash: DELETE_FR, mergeRollupVkHash: DELETE_FR, privateKernelVkTreeRoot: FUTURE_FR, @@ -604,7 +604,7 @@ export class SoloBlockBuilder implements BlockBuilder { const wasm = await CircuitsWasm.get(); // Get trees info before any changes hit - const constants = await this.getConstantBaseRollupData(globalVariables); + const constants = await this.getConstantRollupData(globalVariables); const startNullifierTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE); const startContractTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.CONTRACT_TREE); const startPrivateDataTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.PRIVATE_DATA_TREE); diff --git a/yarn-project/sequencer-client/src/simulator/rollup.ts b/yarn-project/sequencer-client/src/simulator/rollup.ts index 787f0c46784..addd8590e19 100644 --- a/yarn-project/sequencer-client/src/simulator/rollup.ts +++ b/yarn-project/sequencer-client/src/simulator/rollup.ts @@ -1,11 +1,13 @@ import { BaseOrMergeRollupPublicInputs, BaseRollupInputs, + CircuitError, CircuitsWasm, MergeRollupInputs, RollupWasmWrapper, RootRollupInputs, RootRollupPublicInputs, + mergeRollupSim, } from '@aztec/circuits.js'; import { RollupSimulator } from './index.js'; @@ -15,9 +17,11 @@ import { RollupSimulator } from './index.js'; */ export class WasmRollupCircuitSimulator implements RollupSimulator { private rollupWasmWrapper: RollupWasmWrapper; + private wasm: CircuitsWasm; constructor(wasm: CircuitsWasm) { this.rollupWasmWrapper = new RollupWasmWrapper(wasm); + this.wasm = wasm; } /** @@ -42,8 +46,14 @@ export class WasmRollupCircuitSimulator implements RollupSimulator { * @returns The public inputs as outputs of the simulation. */ mergeRollupCircuit(input: MergeRollupInputs): Promise { - return Promise.resolve(this.rollupWasmWrapper.simulateMergeRollup(input)); + const result = mergeRollupSim(this.wasm, input); + if (result instanceof CircuitError) { + throw new CircuitError(result.code, result.message); + } + + return Promise.resolve(result); } + /** * Simulates the root rollup circuit from its inputs. * @param input - Inputs to the circuit. From 22e1a761c0ec45c1953baf9770de6891e29c7a25 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Mon, 11 Sep 2023 05:20:08 +0000 Subject: [PATCH 2/8] 2117 - remove unused code in root rollup --- .../src/aztec3/circuits/rollup/root/.test.cpp | 12 ------ .../aztec3/circuits/rollup/root/c_bind.cpp | 38 +------------------ .../src/aztec3/circuits/rollup/root/c_bind.h | 8 +--- 3 files changed, 2 insertions(+), 56 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp index 2a7d5626532..22c36fe04e4 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -69,16 +69,6 @@ class root_rollup_tests : public ::testing::Test { bool compare_pubins = true) { info("Retesting via cbinds...."); - // TODO might be able to get rid of proving key buffer - uint8_t const* pk_buf = nullptr; - size_t const pk_size = root_rollup__init_proving_key(&pk_buf); - (void)pk_size; - // info("Proving key size: ", pk_size); - - // TODO might be able to get rid of verification key buffer - uint8_t const* vk_buf = nullptr; - size_t const vk_size = root_rollup__init_verification_key(pk_buf, &vk_buf); - (void)vk_size; // info("Verification key size: ", vk_size); std::vector root_rollup_inputs_vec; @@ -117,8 +107,6 @@ class root_rollup_tests : public ::testing::Test { } } - free((void*)pk_buf); - free((void*)vk_buf); // free((void*)proof_data); free((void*)public_inputs_buf); } diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp index 857f4f2691d..38feb1b2a44 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp @@ -19,32 +19,6 @@ using aztec3::circuits::rollup::native_root_rollup::RootRollupPublicInputs; } // namespace // WASM Cbinds -extern "C" { - -WASM_EXPORT size_t root_rollup__init_proving_key(uint8_t const** pk_buf) -{ - std::vector pk_vec(42, 0); - - auto* raw_buf = (uint8_t*)malloc(pk_vec.size()); - memcpy(raw_buf, (void*)pk_vec.data(), pk_vec.size()); - *pk_buf = raw_buf; - - return pk_vec.size(); -} - -WASM_EXPORT size_t root_rollup__init_verification_key(uint8_t const* pk_buf, uint8_t const** vk_buf) -{ - std::vector vk_vec(42, 0); - // TODO remove when proving key is used - (void)pk_buf; // unused - - auto* raw_buf = (uint8_t*)malloc(vk_vec.size()); - memcpy(raw_buf, (void*)vk_vec.data(), vk_vec.size()); - *vk_buf = raw_buf; - - return vk_vec.size(); -} - WASM_EXPORT uint8_t* root_rollup__sim(uint8_t const* root_rollup_inputs_buf, size_t* root_rollup_public_inputs_size_out, uint8_t const** root_rollup_public_inputs_buf) @@ -64,14 +38,4 @@ WASM_EXPORT uint8_t* root_rollup__sim(uint8_t const* root_rollup_inputs_buf, *root_rollup_public_inputs_buf = raw_public_inputs_buf; *root_rollup_public_inputs_size_out = public_inputs_vec.size(); return builder.alloc_and_serialize_first_failure(); -} - -WASM_EXPORT size_t root_rollup__verify_proof(uint8_t const* vk_buf, uint8_t const* proof, uint32_t length) -{ - (void)vk_buf; // unused - (void)proof; // unused - (void)length; // unused - return 1U; -} - -} // extern "C" +} \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.h b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.h index d159a646412..b430e8d1907 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.h +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.h @@ -5,12 +5,6 @@ #include #include -extern "C" { - -WASM_EXPORT size_t root_rollup__init_proving_key(uint8_t const** pk_buf); -WASM_EXPORT size_t root_rollup__init_verification_key(uint8_t const* pk_buf, uint8_t const** vk_buf); WASM_EXPORT uint8_t* root_rollup__sim(uint8_t const* root_rollup_inputs_buf, size_t* root_rollup_public_inputs_size_out, - uint8_t const** root_rollup_public_inputs_buf); -WASM_EXPORT size_t root_rollup__verify_proof(uint8_t const* vk_buf, uint8_t const* proof, uint32_t length); -} \ No newline at end of file + uint8_t const** root_rollup_public_inputs_buf); \ No newline at end of file From 2dda3a82bf98234a6619a111420ede412ce20270 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Mon, 11 Sep 2023 05:39:47 +0000 Subject: [PATCH 3/8] 2117 - use msgpack based macro for cbind in root rollups --- .../src/aztec3/circuits/rollup/root/.test.cpp | 96 +++++++++---------- .../aztec3/circuits/rollup/root/c_bind.cpp | 23 +---- .../src/aztec3/circuits/rollup/root/c_bind.h | 4 +- 3 files changed, 53 insertions(+), 70 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp index 22c36fe04e4..ded030ebcd5 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -64,52 +64,52 @@ class root_rollup_tests : public ::testing::Test { protected: static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../barretenberg/cpp/srs_db/ignition"); } - static void run_cbind(RootRollupInputs& root_rollup_inputs, - RootRollupPublicInputs& expected_public_inputs, - bool compare_pubins = true) - { - info("Retesting via cbinds...."); - // info("Verification key size: ", vk_size); - - std::vector root_rollup_inputs_vec; - serialize::write(root_rollup_inputs_vec, root_rollup_inputs); - - // uint8_t const* proof_data; - // size_t proof_data_size; - uint8_t const* public_inputs_buf = nullptr; - size_t public_inputs_size = 0; - // info("simulating circuit via cbind"); - uint8_t* const circuit_failure_ptr = - root_rollup__sim(root_rollup_inputs_vec.data(), &public_inputs_size, &public_inputs_buf); - ASSERT_TRUE(circuit_failure_ptr == nullptr); - // info("Proof size: ", proof_data_size); - // info("PublicInputs size: ", public_inputs_size); - - if (compare_pubins) { - RootRollupPublicInputs public_inputs; - uint8_t const* public_inputs_buf_tmp = public_inputs_buf; - serialize::read(public_inputs_buf_tmp, public_inputs); - ASSERT_EQ(public_inputs.calldata_hash.size(), expected_public_inputs.calldata_hash.size()); - for (size_t i = 0; i < public_inputs.calldata_hash.size(); i++) { - ASSERT_EQ(public_inputs.calldata_hash[i], expected_public_inputs.calldata_hash[i]); - } - - std::vector expected_public_inputs_vec; - serialize::write(expected_public_inputs_vec, expected_public_inputs); - - ASSERT_EQ(public_inputs_size, expected_public_inputs_vec.size()); - // Just compare the first 10 bytes of the serialized public outputs - if (public_inputs_size > 10) { - // for (size_t 0; i < public_inputs_size; i++) { - for (size_t i = 0; i < 10; i++) { - ASSERT_EQ(public_inputs_buf[i], expected_public_inputs_vec[i]); - } - } - } - - // free((void*)proof_data); - free((void*)public_inputs_buf); - } + // static void run_cbind(RootRollupInputs& root_rollup_inputs, + // RootRollupPublicInputs& expected_public_inputs, + // bool compare_pubins = true) + // { + // info("Retesting via cbinds...."); + // // info("Verification key size: ", vk_size); + + // std::vector root_rollup_inputs_vec; + // serialize::write(root_rollup_inputs_vec, root_rollup_inputs); + + // // uint8_t const* proof_data; + // // size_t proof_data_size; + // uint8_t const* public_inputs_buf = nullptr; + // size_t public_inputs_size = 0; + // // info("simulating circuit via cbind"); + // uint8_t* const circuit_failure_ptr = + // root_rollup__sim(root_rollup_inputs_vec.data(), &public_inputs_size, &public_inputs_buf); + // ASSERT_TRUE(circuit_failure_ptr == nullptr); + // // info("Proof size: ", proof_data_size); + // // info("PublicInputs size: ", public_inputs_size); + + // if (compare_pubins) { + // RootRollupPublicInputs public_inputs; + // uint8_t const* public_inputs_buf_tmp = public_inputs_buf; + // serialize::read(public_inputs_buf_tmp, public_inputs); + // ASSERT_EQ(public_inputs.calldata_hash.size(), expected_public_inputs.calldata_hash.size()); + // for (size_t i = 0; i < public_inputs.calldata_hash.size(); i++) { + // ASSERT_EQ(public_inputs.calldata_hash[i], expected_public_inputs.calldata_hash[i]); + // } + + // std::vector expected_public_inputs_vec; + // serialize::write(expected_public_inputs_vec, expected_public_inputs); + + // ASSERT_EQ(public_inputs_size, expected_public_inputs_vec.size()); + // // Just compare the first 10 bytes of the serialized public outputs + // if (public_inputs_size > 10) { + // // for (size_t 0; i < public_inputs_size; i++) { + // for (size_t i = 0; i < 10; i++) { + // ASSERT_EQ(public_inputs_buf[i], expected_public_inputs_vec[i]); + // } + // } + // } + + // // free((void*)proof_data); + // free((void*)public_inputs_buf); + // } }; TEST_F(root_rollup_tests, native_check_block_hashes_empty_blocks) @@ -149,7 +149,7 @@ TEST_F(root_rollup_tests, native_check_block_hashes_empty_blocks) EXPECT_FALSE(builder.failed()); - run_cbind(inputs, outputs, true); + // run_cbind(inputs, outputs, true); } TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) @@ -300,7 +300,7 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) EXPECT_FALSE(builder.failed()); - run_cbind(rootRollupInputs, outputs, true); + // run_cbind(rootRollupInputs, outputs, true); } } // namespace aztec3::circuits::rollup::root::native_root_rollup_circuit \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp index 38feb1b2a44..197560a64fb 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp @@ -19,23 +19,8 @@ using aztec3::circuits::rollup::native_root_rollup::RootRollupPublicInputs; } // namespace // WASM Cbinds -WASM_EXPORT uint8_t* root_rollup__sim(uint8_t const* root_rollup_inputs_buf, - size_t* root_rollup_public_inputs_size_out, - uint8_t const** root_rollup_public_inputs_buf) -{ - RootRollupInputs root_rollup_inputs; - serialize::read(root_rollup_inputs_buf, root_rollup_inputs); - +CBIND(root_rollup__sim, [](RootRollupInputs const& root_rollup_inputs) { DummyCircuitBuilder builder = DummyCircuitBuilder("root_rollup__sim"); - RootRollupPublicInputs const public_inputs = root_rollup_circuit(builder, root_rollup_inputs); - - // serialize public inputs to bytes vec - std::vector public_inputs_vec; - serialize::write(public_inputs_vec, public_inputs); - // copy public inputs to output buffer - auto* raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); - memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); - *root_rollup_public_inputs_buf = raw_public_inputs_buf; - *root_rollup_public_inputs_size_out = public_inputs_vec.size(); - return builder.alloc_and_serialize_first_failure(); -} \ No newline at end of file + auto const& public_inputs = root_rollup_circuit(builder, root_rollup_inputs); + return builder.result_or_error(public_inputs); +}); \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.h b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.h index b430e8d1907..5105580e922 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.h +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.h @@ -5,6 +5,4 @@ #include #include -WASM_EXPORT uint8_t* root_rollup__sim(uint8_t const* root_rollup_inputs_buf, - size_t* root_rollup_public_inputs_size_out, - uint8_t const** root_rollup_public_inputs_buf); \ No newline at end of file +CBIND_DECL(root_rollup__sim); \ No newline at end of file From 366cea8b0ced142e08b73d41dbd0cb6a4634e79f Mon Sep 17 00:00:00 2001 From: jeanmon Date: Mon, 11 Sep 2023 11:26:31 +0000 Subject: [PATCH 4/8] 2117 - generate circuits.gen.ts and reconcile data structures --- .../abis/rollup/root/root_rollup_inputs.hpp | 4 +- .../root/native_root_rollup_circuit.cpp | 4 +- .../circuits/rollup/test_utils/utils.cpp | 2 +- .../circuits.js/src/cbind/circuits.gen.ts | 316 ++++++++++++++++++ yarn-project/circuits.js/src/cbind/types.ts | 2 + .../src/structs/rollup/root_rollup.ts | 30 +- .../circuits.js/src/tests/factories.ts | 8 +- .../block_builder/solo_block_builder.test.ts | 8 +- .../src/block_builder/solo_block_builder.ts | 36 +- .../src/block_builder/types.ts | 2 +- 10 files changed, 370 insertions(+), 42 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp index d8a5ee84196..b035e04eded 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp @@ -19,7 +19,7 @@ template struct RootRollupInputs { std::array, 2> previous_rollup_data{}; // inputs required to process l1 to l2 messages - std::array l1_to_l2_messages{}; + std::array new_l1_to_l2_messages{}; std::array new_l1_to_l2_message_tree_root_sibling_path{}; AppendOnlyTreeSnapshot start_l1_to_l2_message_tree_snapshot{}; @@ -30,7 +30,7 @@ template struct RootRollupInputs { // For serialization, update with new fields MSGPACK_FIELDS(previous_rollup_data, - l1_to_l2_messages, + new_l1_to_l2_messages, new_l1_to_l2_message_tree_root_sibling_path, start_l1_to_l2_message_tree_snapshot, start_historic_blocks_tree_snapshot, diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp index cef291d1c27..87115157dc9 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp @@ -92,7 +92,7 @@ RootRollupPublicInputs root_rollup_circuit(DummyBuilder& builder, RootRollupInpu // Check correct l1 to l2 tree given // Compute subtree inserting l1 to l2 messages - auto l1_to_l2_subtree_root = calculate_subtree(rootRollupInputs.l1_to_l2_messages); + auto l1_to_l2_subtree_root = calculate_subtree(rootRollupInputs.new_l1_to_l2_messages); // Insert subtree into the l1 to l2 data tree const auto empty_l1_to_l2_subtree_root = components::calculate_empty_tree_root(L1_TO_L2_MSG_SUBTREE_HEIGHT); @@ -143,7 +143,7 @@ RootRollupPublicInputs root_rollup_circuit(DummyBuilder& builder, RootRollupInpu .start_historic_blocks_tree_snapshot = rootRollupInputs.start_historic_blocks_tree_snapshot, .end_historic_blocks_tree_snapshot = end_historic_blocks_tree_snapshot, .calldata_hash = components::compute_calldata_hash(rootRollupInputs.previous_rollup_data), - .l1_to_l2_messages_hash = compute_messages_hash(rootRollupInputs.l1_to_l2_messages) + .l1_to_l2_messages_hash = compute_messages_hash(rootRollupInputs.new_l1_to_l2_messages) }; return public_inputs; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp index e9c952dd30d..5b18741ffa0 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp @@ -412,7 +412,7 @@ RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& builder, RootRollupInputs rootRollupInputs = { .previous_rollup_data = get_previous_rollup_data(builder, std::move(kernel_data)), - .l1_to_l2_messages = l1_to_l2_messages, + .new_l1_to_l2_messages = l1_to_l2_messages, .new_l1_to_l2_message_tree_root_sibling_path = l1_to_l2_tree_sibling_path, .start_l1_to_l2_message_tree_snapshot = start_l1_to_l2_msg_tree_snapshot, .start_historic_blocks_tree_snapshot = start_historic_blocks_tree_snapshot, diff --git a/yarn-project/circuits.js/src/cbind/circuits.gen.ts b/yarn-project/circuits.js/src/cbind/circuits.gen.ts index 2a1722fc757..8daa35a5add 100644 --- a/yarn-project/circuits.js/src/cbind/circuits.gen.ts +++ b/yarn-project/circuits.js/src/cbind/circuits.gen.ts @@ -53,6 +53,8 @@ import { PublicDataUpdateRequest, PublicKernelInputs, ReadRequestMembershipWitness, + RootRollupInputs, + RootRollupPublicInputs, TxContext, TxRequest, VerificationKeyData, @@ -2574,6 +2576,314 @@ export function fromMergeRollupInputs(o: MergeRollupInputs): MsgpackMergeRollupI }; } +interface MsgpackRootRollupInputs { + previous_rollup_data: Tuple; + new_l1_to_l2_messages: Tuple; + new_l1_to_l2_message_tree_root_sibling_path: Tuple; + start_l1_to_l2_message_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + start_historic_blocks_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + new_historic_blocks_tree_sibling_path: Tuple; +} + +export function toRootRollupInputs(o: MsgpackRootRollupInputs): RootRollupInputs { + if (o.previous_rollup_data === undefined) { + throw new Error('Expected previous_rollup_data in RootRollupInputs deserialization'); + } + if (o.new_l1_to_l2_messages === undefined) { + throw new Error('Expected new_l1_to_l2_messages in RootRollupInputs deserialization'); + } + if (o.new_l1_to_l2_message_tree_root_sibling_path === undefined) { + throw new Error('Expected new_l1_to_l2_message_tree_root_sibling_path in RootRollupInputs deserialization'); + } + if (o.start_l1_to_l2_message_tree_snapshot === undefined) { + throw new Error('Expected start_l1_to_l2_message_tree_snapshot in RootRollupInputs deserialization'); + } + if (o.start_historic_blocks_tree_snapshot === undefined) { + throw new Error('Expected start_historic_blocks_tree_snapshot in RootRollupInputs deserialization'); + } + if (o.new_historic_blocks_tree_sibling_path === undefined) { + throw new Error('Expected new_historic_blocks_tree_sibling_path in RootRollupInputs deserialization'); + } + return new RootRollupInputs( + mapTuple(o.previous_rollup_data, (v: MsgpackPreviousRollupData) => toPreviousRollupData(v)), + mapTuple(o.new_l1_to_l2_messages, (v: Buffer) => Fr.fromBuffer(v)), + mapTuple(o.new_l1_to_l2_message_tree_root_sibling_path, (v: Buffer) => Fr.fromBuffer(v)), + toAppendOnlyTreeSnapshot(o.start_l1_to_l2_message_tree_snapshot), + toAppendOnlyTreeSnapshot(o.start_historic_blocks_tree_snapshot), + mapTuple(o.new_historic_blocks_tree_sibling_path, (v: Buffer) => Fr.fromBuffer(v)), + ); +} + +export function fromRootRollupInputs(o: RootRollupInputs): MsgpackRootRollupInputs { + if (o.previousRollupData === undefined) { + throw new Error('Expected previousRollupData in RootRollupInputs serialization'); + } + if (o.newL1ToL2Messages === undefined) { + throw new Error('Expected newL1ToL2Messages in RootRollupInputs serialization'); + } + if (o.newL1ToL2MessageTreeRootSiblingPath === undefined) { + throw new Error('Expected newL1ToL2MessageTreeRootSiblingPath in RootRollupInputs serialization'); + } + if (o.startL1ToL2MessageTreeSnapshot === undefined) { + throw new Error('Expected startL1ToL2MessageTreeSnapshot in RootRollupInputs serialization'); + } + if (o.startHistoricBlocksTreeSnapshot === undefined) { + throw new Error('Expected startHistoricBlocksTreeSnapshot in RootRollupInputs serialization'); + } + if (o.newHistoricBlocksTreeSiblingPath === undefined) { + throw new Error('Expected newHistoricBlocksTreeSiblingPath in RootRollupInputs serialization'); + } + return { + previous_rollup_data: mapTuple(o.previousRollupData, (v: PreviousRollupData) => fromPreviousRollupData(v)), + new_l1_to_l2_messages: mapTuple(o.newL1ToL2Messages, (v: Fr) => toBuffer(v)), + new_l1_to_l2_message_tree_root_sibling_path: mapTuple(o.newL1ToL2MessageTreeRootSiblingPath, (v: Fr) => + toBuffer(v), + ), + start_l1_to_l2_message_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startL1ToL2MessageTreeSnapshot), + start_historic_blocks_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startHistoricBlocksTreeSnapshot), + new_historic_blocks_tree_sibling_path: mapTuple(o.newHistoricBlocksTreeSiblingPath, (v: Fr) => toBuffer(v)), + }; +} + +interface MsgpackRootRollupPublicInputs { + end_aggregation_object: MsgpackNativeAggregationState; + global_variables: MsgpackGlobalVariables; + start_private_data_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + end_private_data_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + start_nullifier_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + end_nullifier_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + start_contract_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + end_contract_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + start_public_data_tree_root: Buffer; + end_public_data_tree_root: Buffer; + start_tree_of_historic_private_data_tree_roots_snapshot: MsgpackAppendOnlyTreeSnapshot; + end_tree_of_historic_private_data_tree_roots_snapshot: MsgpackAppendOnlyTreeSnapshot; + start_tree_of_historic_contract_tree_roots_snapshot: MsgpackAppendOnlyTreeSnapshot; + end_tree_of_historic_contract_tree_roots_snapshot: MsgpackAppendOnlyTreeSnapshot; + start_l1_to_l2_messages_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + end_l1_to_l2_messages_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + start_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot: MsgpackAppendOnlyTreeSnapshot; + end_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot: MsgpackAppendOnlyTreeSnapshot; + start_historic_blocks_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + end_historic_blocks_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + calldata_hash: Tuple; + l1_to_l2_messages_hash: Tuple; +} + +export function toRootRollupPublicInputs(o: MsgpackRootRollupPublicInputs): RootRollupPublicInputs { + if (o.end_aggregation_object === undefined) { + throw new Error('Expected end_aggregation_object in RootRollupPublicInputs deserialization'); + } + if (o.global_variables === undefined) { + throw new Error('Expected global_variables in RootRollupPublicInputs deserialization'); + } + if (o.start_private_data_tree_snapshot === undefined) { + throw new Error('Expected start_private_data_tree_snapshot in RootRollupPublicInputs deserialization'); + } + if (o.end_private_data_tree_snapshot === undefined) { + throw new Error('Expected end_private_data_tree_snapshot in RootRollupPublicInputs deserialization'); + } + if (o.start_nullifier_tree_snapshot === undefined) { + throw new Error('Expected start_nullifier_tree_snapshot in RootRollupPublicInputs deserialization'); + } + if (o.end_nullifier_tree_snapshot === undefined) { + throw new Error('Expected end_nullifier_tree_snapshot in RootRollupPublicInputs deserialization'); + } + if (o.start_contract_tree_snapshot === undefined) { + throw new Error('Expected start_contract_tree_snapshot in RootRollupPublicInputs deserialization'); + } + if (o.end_contract_tree_snapshot === undefined) { + throw new Error('Expected end_contract_tree_snapshot in RootRollupPublicInputs deserialization'); + } + if (o.start_public_data_tree_root === undefined) { + throw new Error('Expected start_public_data_tree_root in RootRollupPublicInputs deserialization'); + } + if (o.end_public_data_tree_root === undefined) { + throw new Error('Expected end_public_data_tree_root in RootRollupPublicInputs deserialization'); + } + if (o.start_tree_of_historic_private_data_tree_roots_snapshot === undefined) { + throw new Error( + 'Expected start_tree_of_historic_private_data_tree_roots_snapshot in RootRollupPublicInputs deserialization', + ); + } + if (o.end_tree_of_historic_private_data_tree_roots_snapshot === undefined) { + throw new Error( + 'Expected end_tree_of_historic_private_data_tree_roots_snapshot in RootRollupPublicInputs deserialization', + ); + } + if (o.start_tree_of_historic_contract_tree_roots_snapshot === undefined) { + throw new Error( + 'Expected start_tree_of_historic_contract_tree_roots_snapshot in RootRollupPublicInputs deserialization', + ); + } + if (o.end_tree_of_historic_contract_tree_roots_snapshot === undefined) { + throw new Error( + 'Expected end_tree_of_historic_contract_tree_roots_snapshot in RootRollupPublicInputs deserialization', + ); + } + if (o.start_l1_to_l2_messages_tree_snapshot === undefined) { + throw new Error('Expected start_l1_to_l2_messages_tree_snapshot in RootRollupPublicInputs deserialization'); + } + if (o.end_l1_to_l2_messages_tree_snapshot === undefined) { + throw new Error('Expected end_l1_to_l2_messages_tree_snapshot in RootRollupPublicInputs deserialization'); + } + if (o.start_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot === undefined) { + throw new Error( + 'Expected start_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot in RootRollupPublicInputs deserialization', + ); + } + if (o.end_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot === undefined) { + throw new Error( + 'Expected end_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot in RootRollupPublicInputs deserialization', + ); + } + if (o.start_historic_blocks_tree_snapshot === undefined) { + throw new Error('Expected start_historic_blocks_tree_snapshot in RootRollupPublicInputs deserialization'); + } + if (o.end_historic_blocks_tree_snapshot === undefined) { + throw new Error('Expected end_historic_blocks_tree_snapshot in RootRollupPublicInputs deserialization'); + } + if (o.calldata_hash === undefined) { + throw new Error('Expected calldata_hash in RootRollupPublicInputs deserialization'); + } + if (o.l1_to_l2_messages_hash === undefined) { + throw new Error('Expected l1_to_l2_messages_hash in RootRollupPublicInputs deserialization'); + } + return new RootRollupPublicInputs( + toNativeAggregationState(o.end_aggregation_object), + toGlobalVariables(o.global_variables), + toAppendOnlyTreeSnapshot(o.start_private_data_tree_snapshot), + toAppendOnlyTreeSnapshot(o.end_private_data_tree_snapshot), + toAppendOnlyTreeSnapshot(o.start_nullifier_tree_snapshot), + toAppendOnlyTreeSnapshot(o.end_nullifier_tree_snapshot), + toAppendOnlyTreeSnapshot(o.start_contract_tree_snapshot), + toAppendOnlyTreeSnapshot(o.end_contract_tree_snapshot), + Fr.fromBuffer(o.start_public_data_tree_root), + Fr.fromBuffer(o.end_public_data_tree_root), + toAppendOnlyTreeSnapshot(o.start_tree_of_historic_private_data_tree_roots_snapshot), + toAppendOnlyTreeSnapshot(o.end_tree_of_historic_private_data_tree_roots_snapshot), + toAppendOnlyTreeSnapshot(o.start_tree_of_historic_contract_tree_roots_snapshot), + toAppendOnlyTreeSnapshot(o.end_tree_of_historic_contract_tree_roots_snapshot), + toAppendOnlyTreeSnapshot(o.start_l1_to_l2_messages_tree_snapshot), + toAppendOnlyTreeSnapshot(o.end_l1_to_l2_messages_tree_snapshot), + toAppendOnlyTreeSnapshot(o.start_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot), + toAppendOnlyTreeSnapshot(o.end_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot), + toAppendOnlyTreeSnapshot(o.start_historic_blocks_tree_snapshot), + toAppendOnlyTreeSnapshot(o.end_historic_blocks_tree_snapshot), + mapTuple(o.calldata_hash, (v: Buffer) => Fr.fromBuffer(v)), + mapTuple(o.l1_to_l2_messages_hash, (v: Buffer) => Fr.fromBuffer(v)), + ); +} + +export function fromRootRollupPublicInputs(o: RootRollupPublicInputs): MsgpackRootRollupPublicInputs { + if (o.endAggregationObject === undefined) { + throw new Error('Expected endAggregationObject in RootRollupPublicInputs serialization'); + } + if (o.globalVariables === undefined) { + throw new Error('Expected globalVariables in RootRollupPublicInputs serialization'); + } + if (o.startPrivateDataTreeSnapshot === undefined) { + throw new Error('Expected startPrivateDataTreeSnapshot in RootRollupPublicInputs serialization'); + } + if (o.endPrivateDataTreeSnapshot === undefined) { + throw new Error('Expected endPrivateDataTreeSnapshot in RootRollupPublicInputs serialization'); + } + if (o.startNullifierTreeSnapshot === undefined) { + throw new Error('Expected startNullifierTreeSnapshot in RootRollupPublicInputs serialization'); + } + if (o.endNullifierTreeSnapshot === undefined) { + throw new Error('Expected endNullifierTreeSnapshot in RootRollupPublicInputs serialization'); + } + if (o.startContractTreeSnapshot === undefined) { + throw new Error('Expected startContractTreeSnapshot in RootRollupPublicInputs serialization'); + } + if (o.endContractTreeSnapshot === undefined) { + throw new Error('Expected endContractTreeSnapshot in RootRollupPublicInputs serialization'); + } + if (o.startPublicDataTreeRoot === undefined) { + throw new Error('Expected startPublicDataTreeRoot in RootRollupPublicInputs serialization'); + } + if (o.endPublicDataTreeRoot === undefined) { + throw new Error('Expected endPublicDataTreeRoot in RootRollupPublicInputs serialization'); + } + if (o.startTreeOfHistoricPrivateDataTreeRootsSnapshot === undefined) { + throw new Error('Expected startTreeOfHistoricPrivateDataTreeRootsSnapshot in RootRollupPublicInputs serialization'); + } + if (o.endTreeOfHistoricPrivateDataTreeRootsSnapshot === undefined) { + throw new Error('Expected endTreeOfHistoricPrivateDataTreeRootsSnapshot in RootRollupPublicInputs serialization'); + } + if (o.startTreeOfHistoricContractTreeRootsSnapshot === undefined) { + throw new Error('Expected startTreeOfHistoricContractTreeRootsSnapshot in RootRollupPublicInputs serialization'); + } + if (o.endTreeOfHistoricContractTreeRootsSnapshot === undefined) { + throw new Error('Expected endTreeOfHistoricContractTreeRootsSnapshot in RootRollupPublicInputs serialization'); + } + if (o.startL1ToL2MessagesTreeSnapshot === undefined) { + throw new Error('Expected startL1ToL2MessagesTreeSnapshot in RootRollupPublicInputs serialization'); + } + if (o.endL1ToL2MessagesTreeSnapshot === undefined) { + throw new Error('Expected endL1ToL2MessagesTreeSnapshot in RootRollupPublicInputs serialization'); + } + if (o.startTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot === undefined) { + throw new Error( + 'Expected startTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot in RootRollupPublicInputs serialization', + ); + } + if (o.endTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot === undefined) { + throw new Error( + 'Expected endTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot in RootRollupPublicInputs serialization', + ); + } + if (o.startHistoricBlocksTreeSnapshot === undefined) { + throw new Error('Expected startHistoricBlocksTreeSnapshot in RootRollupPublicInputs serialization'); + } + if (o.endHistoricBlocksTreeSnapshot === undefined) { + throw new Error('Expected endHistoricBlocksTreeSnapshot in RootRollupPublicInputs serialization'); + } + if (o.calldataHash === undefined) { + throw new Error('Expected calldataHash in RootRollupPublicInputs serialization'); + } + if (o.l1ToL2MessagesHash === undefined) { + throw new Error('Expected l1ToL2MessagesHash in RootRollupPublicInputs serialization'); + } + return { + end_aggregation_object: fromNativeAggregationState(o.endAggregationObject), + global_variables: fromGlobalVariables(o.globalVariables), + start_private_data_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startPrivateDataTreeSnapshot), + end_private_data_tree_snapshot: fromAppendOnlyTreeSnapshot(o.endPrivateDataTreeSnapshot), + start_nullifier_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startNullifierTreeSnapshot), + end_nullifier_tree_snapshot: fromAppendOnlyTreeSnapshot(o.endNullifierTreeSnapshot), + start_contract_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startContractTreeSnapshot), + end_contract_tree_snapshot: fromAppendOnlyTreeSnapshot(o.endContractTreeSnapshot), + start_public_data_tree_root: toBuffer(o.startPublicDataTreeRoot), + end_public_data_tree_root: toBuffer(o.endPublicDataTreeRoot), + start_tree_of_historic_private_data_tree_roots_snapshot: fromAppendOnlyTreeSnapshot( + o.startTreeOfHistoricPrivateDataTreeRootsSnapshot, + ), + end_tree_of_historic_private_data_tree_roots_snapshot: fromAppendOnlyTreeSnapshot( + o.endTreeOfHistoricPrivateDataTreeRootsSnapshot, + ), + start_tree_of_historic_contract_tree_roots_snapshot: fromAppendOnlyTreeSnapshot( + o.startTreeOfHistoricContractTreeRootsSnapshot, + ), + end_tree_of_historic_contract_tree_roots_snapshot: fromAppendOnlyTreeSnapshot( + o.endTreeOfHistoricContractTreeRootsSnapshot, + ), + start_l1_to_l2_messages_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startL1ToL2MessagesTreeSnapshot), + end_l1_to_l2_messages_tree_snapshot: fromAppendOnlyTreeSnapshot(o.endL1ToL2MessagesTreeSnapshot), + start_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot: fromAppendOnlyTreeSnapshot( + o.startTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot, + ), + end_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot: fromAppendOnlyTreeSnapshot( + o.endTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot, + ), + start_historic_blocks_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startHistoricBlocksTreeSnapshot), + end_historic_blocks_tree_snapshot: fromAppendOnlyTreeSnapshot(o.endHistoricBlocksTreeSnapshot), + calldata_hash: mapTuple(o.calldataHash, (v: Fr) => toBuffer(v)), + l1_to_l2_messages_hash: mapTuple(o.l1ToL2MessagesHash, (v: Fr) => toBuffer(v)), + }; +} + export function abisComputeCommitmentNonce(wasm: IWasmModule, arg0: Fr, arg1: Fr): Fr { return Fr.fromBuffer(callCbind(wasm, 'abis__compute_commitment_nonce', [toBuffer(arg0), toBuffer(arg1)])); } @@ -2680,3 +2990,9 @@ export function mergeRollupSim( callCbind(wasm, 'merge_rollup__sim', [fromMergeRollupInputs(arg0)]), ); } +export function rootRollupSim(wasm: IWasmModule, arg0: RootRollupInputs): CircuitError | RootRollupPublicInputs { + return ((v: MsgpackCircuitError | MsgpackRootRollupPublicInputs) => + isCircuitError(v) ? toCircuitError(v) : toRootRollupPublicInputs(v))( + callCbind(wasm, 'root_rollup__sim', [fromRootRollupInputs(arg0)]), + ); +} diff --git a/yarn-project/circuits.js/src/cbind/types.ts b/yarn-project/circuits.js/src/cbind/types.ts index c3f7a5eac9e..dfe90681ffc 100644 --- a/yarn-project/circuits.js/src/cbind/types.ts +++ b/yarn-project/circuits.js/src/cbind/types.ts @@ -122,6 +122,8 @@ export { BaseOrMergeRollupPublicInputs, ConstantRollupData, MergeRollupInputs, + RootRollupInputs, + RootRollupPublicInputs, } from '../structs/index.js'; export { FunctionSelector } from '@aztec/foundation/abi'; diff --git a/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts b/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts index 740087e6d81..dcceb101f79 100644 --- a/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts +++ b/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts @@ -1,5 +1,5 @@ import { Fr } from '@aztec/foundation/fields'; -import { BufferReader } from '@aztec/foundation/serialize'; +import { BufferReader, Tuple } from '@aztec/foundation/serialize'; import { HISTORIC_BLOCKS_TREE_HEIGHT, @@ -27,11 +27,11 @@ export class RootRollupInputs { /** * New L1 to L2 messages. */ - public newL1ToL2Messages: Fr[], + public newL1ToL2Messages: Tuple, /** * Sibling path of the new L1 to L2 message tree root. */ - public newL1ToL2MessageTreeRootSiblingPath: Fr[], + public newL1ToL2MessageTreeRootSiblingPath: Tuple, /** * Snapshot of the L1 to L2 message tree at the start of the rollup. */ @@ -43,12 +43,8 @@ export class RootRollupInputs { /** * Sibling path of the new historic block roots tree root. */ - public newHistoricBlocksTreeSiblingPath: Fr[], - ) { - assertMemberLength(this, 'newL1ToL2MessageTreeRootSiblingPath', L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH); - assertMemberLength(this, 'newHistoricBlocksTreeSiblingPath', HISTORIC_BLOCKS_TREE_HEIGHT); - assertMemberLength(this, 'newL1ToL2Messages', NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP); - } + public newHistoricBlocksTreeSiblingPath: Tuple, + ) {} toBuffer() { return serializeToBuffer(...RootRollupInputs.getFields(this)); @@ -144,20 +140,20 @@ export class RootRollupPublicInputs { /** * Snapshot of the L1 to L2 message tree at the start of the rollup. */ - public startL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot, + public startL1ToL2MessagesTreeSnapshot: AppendOnlyTreeSnapshot, /** * Snapshot of the L1 to L2 message tree at the end of the rollup. */ - public endL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot, + public endL1ToL2MessagesTreeSnapshot: AppendOnlyTreeSnapshot, /** * Snapshot of the historic L1 to L2 message tree roots tree at the start of the rollup. */ - public startTreeOfHistoricL1ToL2MessageTreeRootsSnapshot: AppendOnlyTreeSnapshot, + public startTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot: AppendOnlyTreeSnapshot, /** * Snapshot of the historic L1 to L2 message tree roots tree at the end of the rollup. */ - public endTreeOfHistoricL1ToL2MessageTreeRootsSnapshot: AppendOnlyTreeSnapshot, + public endTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot: AppendOnlyTreeSnapshot, /** * Snapshot of the historic blocks tree roots tree at the start of the rollup. @@ -194,10 +190,10 @@ export class RootRollupPublicInputs { fields.endTreeOfHistoricPrivateDataTreeRootsSnapshot, fields.startTreeOfHistoricContractTreeRootsSnapshot, fields.endTreeOfHistoricContractTreeRootsSnapshot, - fields.startL1ToL2MessageTreeSnapshot, - fields.endL1ToL2MessageTreeSnapshot, - fields.startTreeOfHistoricL1ToL2MessageTreeRootsSnapshot, - fields.endTreeOfHistoricL1ToL2MessageTreeRootsSnapshot, + fields.startL1ToL2MessagesTreeSnapshot, + fields.endL1ToL2MessagesTreeSnapshot, + fields.startTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot, + fields.endTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot, fields.startHistoricBlocksTreeSnapshot, fields.endHistoricBlocksTreeSnapshot, fields.calldataHash, diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index ad0beb0c05c..2bbd35a704e 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -850,10 +850,10 @@ export function makeRootRollupPublicInputs( endTreeOfHistoricPrivateDataTreeRootsSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), startTreeOfHistoricContractTreeRootsSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), endTreeOfHistoricContractTreeRootsSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), - startL1ToL2MessageTreeSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), - endL1ToL2MessageTreeSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), - startTreeOfHistoricL1ToL2MessageTreeRootsSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), - endTreeOfHistoricL1ToL2MessageTreeRootsSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), + startL1ToL2MessagesTreeSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), + endL1ToL2MessagesTreeSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), + startTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), + endTreeOfHistoricL1ToL2MessagesTreeRootsSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), startHistoricBlocksTreeSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), endHistoricBlocksTreeSnapshot: makeAppendOnlyTreeSnapshot((seed += 0x100)), calldataHash: [new Fr(1n), new Fr(2n)], diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts index 74a355905b9..42d566237ed 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts @@ -157,7 +157,7 @@ describe('sequencer/solo_block_builder', () => { rootRollupOutput.endPrivateDataTreeSnapshot.root, rootRollupOutput.endNullifierTreeSnapshot.root, rootRollupOutput.endContractTreeSnapshot.root, - rootRollupOutput.endL1ToL2MessageTreeSnapshot.root, + rootRollupOutput.endL1ToL2MessagesTreeSnapshot.root, rootRollupOutput.endPublicDataTreeRoot, ); await expectsDb.appendLeaves(MerkleTreeId.BLOCKS_TREE, [blockHash.toBuffer()]); @@ -208,7 +208,7 @@ describe('sequencer/solo_block_builder', () => { rootRollupOutput.endPrivateDataTreeSnapshot = await getTreeSnapshot(MerkleTreeId.PRIVATE_DATA_TREE); rootRollupOutput.endPublicDataTreeRoot = (await getTreeSnapshot(MerkleTreeId.PUBLIC_DATA_TREE)).root; - rootRollupOutput.endL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGES_TREE); + rootRollupOutput.endL1ToL2MessagesTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGES_TREE); // Calculate block hash rootRollupOutput.globalVariables = globalVariables; @@ -241,8 +241,8 @@ describe('sequencer/solo_block_builder', () => { endContractTreeSnapshot: rootRollupOutput.endContractTreeSnapshot, startPublicDataTreeRoot: rootRollupOutput.startPublicDataTreeRoot, endPublicDataTreeRoot: rootRollupOutput.endPublicDataTreeRoot, - startL1ToL2MessageTreeSnapshot: rootRollupOutput.startL1ToL2MessageTreeSnapshot, - endL1ToL2MessageTreeSnapshot: rootRollupOutput.endL1ToL2MessageTreeSnapshot, + startL1ToL2MessageTreeSnapshot: rootRollupOutput.startL1ToL2MessagesTreeSnapshot, + endL1ToL2MessageTreeSnapshot: rootRollupOutput.endL1ToL2MessagesTreeSnapshot, startHistoricBlocksTreeSnapshot: rootRollupOutput.startHistoricBlocksTreeSnapshot, endHistoricBlocksTreeSnapshot: rootRollupOutput.endHistoricBlocksTreeSnapshot, newCommitments, diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts index 29298836852..333c07adffa 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts @@ -7,6 +7,7 @@ import { GlobalVariables, HISTORIC_BLOCKS_TREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_HEIGHT, + L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, MembershipWitness, MergeRollupInputs, NULLIFIER_TREE_HEIGHT, @@ -29,7 +30,7 @@ import { toBigIntBE } from '@aztec/foundation/bigint-buffer'; import { padArrayEnd } from '@aztec/foundation/collection'; import { Fr } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; -import { assertLength } from '@aztec/foundation/serialize'; +import { Tuple, assertLength } from '@aztec/foundation/serialize'; import { ContractData, L2Block, L2BlockL2Logs, MerkleTreeId, PublicDataWrite, TxL2Logs } from '@aztec/types'; import { MerkleTreeOperations, computeGlobalVariablesHash } from '@aztec/world-state'; @@ -109,7 +110,7 @@ export class SoloBlockBuilder implements BlockBuilder { endNullifierTreeSnapshot, endContractTreeSnapshot, endPublicDataTreeRoot, - endL1ToL2MessageTreeSnapshot, + endL1ToL2MessagesTreeSnapshot: endL1ToL2MessageTreeSnapshot, endHistoricBlocksTreeSnapshot, } = circuitsOutput; @@ -207,7 +208,7 @@ export class SoloBlockBuilder implements BlockBuilder { } // padArrayEnd throws if the array is already full. Otherwise it pads till we reach the required size - newL1ToL2Messages = padArrayEnd(newL1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP); + const newL1ToL2MessagesTuple = padArrayEnd(newL1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP); // Run the base rollup circuits for the txs const baseRollupOutputs: [BaseOrMergeRollupPublicInputs, Proof][] = []; @@ -230,7 +231,7 @@ export class SoloBlockBuilder implements BlockBuilder { // Run the root rollup with the last two merge rollups (or base, if no merge layers) const [mergeOutputLeft, mergeOutputRight] = mergeRollupInputs; - return this.rootRollupCircuit(mergeOutputLeft, mergeOutputRight, newL1ToL2Messages); + return this.rootRollupCircuit(mergeOutputLeft, mergeOutputRight, newL1ToL2MessagesTuple); } protected async baseRollupCircuit( @@ -276,7 +277,7 @@ export class SoloBlockBuilder implements BlockBuilder { protected async rootRollupCircuit( left: [BaseOrMergeRollupPublicInputs, Proof], right: [BaseOrMergeRollupPublicInputs, Proof], - newL1ToL2Messages: Fr[], + newL1ToL2Messages: Tuple, ): Promise<[RootRollupPublicInputs, Proof]> { this.debug(`Running root rollup circuit`); const rootInput = await this.getRootRollupInput(...left, ...right, newL1ToL2Messages); @@ -351,7 +352,7 @@ export class SoloBlockBuilder implements BlockBuilder { await Promise.all([ this.validateTrees(rootOutput), this.validateTree(rootOutput, MerkleTreeId.BLOCKS_TREE, 'HistoricBlocks'), - this.validateTree(rootOutput, MerkleTreeId.L1_TO_L2_MESSAGES_TREE, 'L1ToL2Message'), + this.validateTree(rootOutput, MerkleTreeId.L1_TO_L2_MESSAGES_TREE, 'L1ToL2Messages'), ]); } @@ -359,7 +360,7 @@ export class SoloBlockBuilder implements BlockBuilder { protected async validateRootTree( rootOutput: RootRollupPublicInputs, treeId: MerkleTreeId, - name: 'Contract' | 'PrivateData' | 'L1ToL2Message', + name: 'Contract' | 'PrivateData' | 'L1ToL2Messages', ) { const localTree = await this.getTreeSnapshot(treeId); const simulatedTree = rootOutput[`endTreeOfHistoric${name}TreeRootsSnapshot`]; @@ -400,7 +401,7 @@ export class SoloBlockBuilder implements BlockBuilder { protected validateSimulatedTree( localTree: AppendOnlyTreeSnapshot, simulatedTree: AppendOnlyTreeSnapshot, - name: 'PrivateData' | 'Contract' | 'Nullifier' | 'L1ToL2Message' | 'HistoricBlocks', + name: 'PrivateData' | 'Contract' | 'Nullifier' | 'L1ToL2Messages' | 'HistoricBlocks', label?: string, ) { if (!simulatedTree.root.toBuffer().equals(localTree.root.toBuffer())) { @@ -421,7 +422,7 @@ export class SoloBlockBuilder implements BlockBuilder { rollupProofLeft: Proof, rollupOutputRight: BaseOrMergeRollupPublicInputs, rollupProofRight: Proof, - newL1ToL2Messages: Fr[], + newL1ToL2Messages: Tuple, ) { const vk = this.getVerificationKey(rollupOutputLeft.rollupType); const previousRollupData: RootRollupInputs['previousRollupData'] = [ @@ -437,17 +438,30 @@ export class SoloBlockBuilder implements BlockBuilder { return path.toFieldArray(); }; - const newL1ToL2MessageTreeRootSiblingPath = await this.getSubtreeSiblingPath( + const newL1ToL2MessageTreeRootSiblingPathArray = await this.getSubtreeSiblingPath( MerkleTreeId.L1_TO_L2_MESSAGES_TREE, L1_TO_L2_MSG_SUBTREE_HEIGHT, ); + const newL1ToL2MessageTreeRootSiblingPath = makeTuple( + L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, + i => + i < newL1ToL2MessageTreeRootSiblingPathArray.length ? newL1ToL2MessageTreeRootSiblingPathArray[i] : Fr.ZERO, + 0, + ); + // Get tree snapshots const startL1ToL2MessageTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGES_TREE); // Get historic block tree roots const startHistoricBlocksTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.BLOCKS_TREE); - const newHistoricBlocksTreeSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.BLOCKS_TREE); + const newHistoricBlocksTreeSiblingPathArray = await getRootTreeSiblingPath(MerkleTreeId.BLOCKS_TREE); + + const newHistoricBlocksTreeSiblingPath = makeTuple( + HISTORIC_BLOCKS_TREE_HEIGHT, + i => (i < newHistoricBlocksTreeSiblingPathArray.length ? newHistoricBlocksTreeSiblingPathArray[i] : Fr.ZERO), + 0, + ); return RootRollupInputs.from({ previousRollupData, diff --git a/yarn-project/sequencer-client/src/block_builder/types.ts b/yarn-project/sequencer-client/src/block_builder/types.ts index 167f6183cda..356c78b8064 100644 --- a/yarn-project/sequencer-client/src/block_builder/types.ts +++ b/yarn-project/sequencer-client/src/block_builder/types.ts @@ -5,7 +5,7 @@ import { AppendOnlyTreeSnapshot, BaseOrMergeRollupPublicInputs, RootRollupPublic */ export type AllowedTreeNames = T extends RootRollupPublicInputs - ? 'PrivateData' | 'Contract' | 'Nullifier' | 'L1ToL2Message' | 'HistoricBlocks' + ? 'PrivateData' | 'Contract' | 'Nullifier' | 'L1ToL2Messages' | 'HistoricBlocks' : 'PrivateData' | 'Contract' | 'Nullifier'; /** From 289068346631c50cce921be06ebe03d6be395f73 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Mon, 11 Sep 2023 11:58:50 +0000 Subject: [PATCH 5/8] 2117 - activate msgpack cbind method --- .../src/rollup/rollup_wasm_wrapper.test.ts | 18 ++++++++++++++---- .../src/rollup/rollup_wasm_wrapper.ts | 11 +---------- .../sequencer-client/src/simulator/rollup.ts | 8 +++++++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.test.ts b/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.test.ts index abbcbf241e6..c7c4d945fcf 100644 --- a/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.test.ts +++ b/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.test.ts @@ -1,7 +1,14 @@ -import { AggregationObject, CircuitError, MergeRollupInputs, RootRollupInputs, VerificationKey } from '../index.js'; +import { + AggregationObject, + CircuitError, + MergeRollupInputs, + RootRollupInputs, + RootRollupPublicInputs, + VerificationKey, +} from '../index.js'; import { makeBaseRollupInputs, makeMergeRollupInputs, makeRootRollupInputs } from '../tests/factories.js'; import { CircuitsWasm } from '../wasm/circuits_wasm.js'; -import { RollupWasmWrapper, mergeRollupSim } from './rollup_wasm_wrapper.js'; +import { RollupWasmWrapper, mergeRollupSim, rootRollupSim } from './rollup_wasm_wrapper.js'; describe('rollup/rollup_wasm_wrapper', () => { let wasm: CircuitsWasm; @@ -101,8 +108,11 @@ describe('rollup/rollup_wasm_wrapper', () => { } fixPreviousRollupInputs(input); - const output = rollupWasm.simulateRootRollup(input); - expect(output.startNullifierTreeSnapshot).toEqual( + const output = rootRollupSim(wasm, input); + expect(output instanceof RootRollupPublicInputs).toBeTruthy(); + + const publicInputs = output as RootRollupPublicInputs; + expect(publicInputs.startNullifierTreeSnapshot).toEqual( input.previousRollupData[0].baseOrMergeRollupPublicInputs.startNullifierTreeSnapshot, ); }, 15_000); diff --git a/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts b/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts index 0518ba02180..95e5455ebae 100644 --- a/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts +++ b/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts @@ -2,7 +2,7 @@ import { BaseOrMergeRollupPublicInputs, BaseRollupInputs, RootRollupInputs, Root import { callWasm } from '../utils/call_wasm.js'; import { CircuitsWasm } from '../wasm/circuits_wasm.js'; -export { mergeRollupSim } from '../cbind/circuits.gen.js'; +export { mergeRollupSim, rootRollupSim } from '../cbind/circuits.gen.js'; /** * A wrapper around `CircuitsWasm` used to expose only the functions relevant for rollup circuits. @@ -19,13 +19,4 @@ export class RollupWasmWrapper { public simulateBaseRollup(baseRollupInputs: BaseRollupInputs): BaseOrMergeRollupPublicInputs { return callWasm(this.wasm, 'base_rollup__sim', baseRollupInputs, BaseOrMergeRollupPublicInputs); } - - /** - * Simulates the root rollup circuit from its inputs. - * @param rootRollupInputs - Inputs to the circuit. - * @returns Public inputs of the root rollup circuit. - */ - public simulateRootRollup(rootRollupInputs: RootRollupInputs): RootRollupPublicInputs { - return callWasm(this.wasm, 'root_rollup__sim', rootRollupInputs, RootRollupPublicInputs); - } } diff --git a/yarn-project/sequencer-client/src/simulator/rollup.ts b/yarn-project/sequencer-client/src/simulator/rollup.ts index addd8590e19..3c971f14794 100644 --- a/yarn-project/sequencer-client/src/simulator/rollup.ts +++ b/yarn-project/sequencer-client/src/simulator/rollup.ts @@ -8,6 +8,7 @@ import { RootRollupInputs, RootRollupPublicInputs, mergeRollupSim, + rootRollupSim, } from '@aztec/circuits.js'; import { RollupSimulator } from './index.js'; @@ -60,6 +61,11 @@ export class WasmRollupCircuitSimulator implements RollupSimulator { * @returns The public inputs as outputs of the simulation. */ rootRollupCircuit(input: RootRollupInputs): Promise { - return Promise.resolve(this.rollupWasmWrapper.simulateRootRollup(input)); + const result = rootRollupSim(this.wasm, input); + if (result instanceof CircuitError) { + throw new CircuitError(result.code, result.message); + } + + return Promise.resolve(result); } } From 8661b597f6e49e9841be2a0cf961448d613379ce Mon Sep 17 00:00:00 2001 From: jeanmon Date: Mon, 11 Sep 2023 12:28:50 +0000 Subject: [PATCH 6/8] 2117 - adapt snapshot for root rollup --- .../src/structs/rollup/__snapshots__/root_rollup.test.ts.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap index 7f33416b083..ab9d210c901 100644 --- a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap @@ -130,7 +130,7 @@ vk_sibling_path: leaf_index: 0x1120 sibling_path: [ 0x1120 0x1121 0x1122 0x1123 0x1124 0x1125 0x1126 0x1127 ] ] -l1_to_l2_messages: [ 0x2100 0x2101 0x2102 0x2103 0x2104 0x2105 0x2106 0x2107 0x2108 0x2109 0x210a 0x210b 0x210c 0x210d 0x210e 0x210f ] +new_l1_to_l2_messages: [ 0x2100 0x2101 0x2102 0x2103 0x2104 0x2105 0x2106 0x2107 0x2108 0x2109 0x210a 0x210b 0x210c 0x210d 0x210e 0x210f ] new_l1_to_l2_message_tree_root_sibling_path: [ 0x2100 0x2101 0x2102 0x2103 0x2104 0x2105 0x2106 0x2107 0x2108 0x2109 0x210a 0x210b ] start_l1_to_l2_message_tree_snapshot: root: 0x2200 next_available_leaf_index: 8704 From 46340dbca73a3a26b220f5732d06f7973c8af3c7 Mon Sep 17 00:00:00 2001 From: jeanmon Date: Mon, 11 Sep 2023 14:04:41 +0000 Subject: [PATCH 7/8] 2117 - remove some unused imports in TS --- yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts | 2 +- yarn-project/circuits.js/src/structs/rollup/root_rollup.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts b/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts index 95e5455ebae..429d34bb666 100644 --- a/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts +++ b/yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts @@ -1,4 +1,4 @@ -import { BaseOrMergeRollupPublicInputs, BaseRollupInputs, RootRollupInputs, RootRollupPublicInputs } from '../index.js'; +import { BaseOrMergeRollupPublicInputs, BaseRollupInputs } from '../index.js'; import { callWasm } from '../utils/call_wasm.js'; import { CircuitsWasm } from '../wasm/circuits_wasm.js'; diff --git a/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts b/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts index dcceb101f79..2c174a83fa7 100644 --- a/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts +++ b/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts @@ -6,7 +6,7 @@ import { L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, } from '../../cbind/constants.gen.js'; -import { FieldsOf, assertMemberLength } from '../../utils/jsUtils.js'; +import { FieldsOf } from '../../utils/jsUtils.js'; import { serializeToBuffer } from '../../utils/serialize.js'; import { AggregationObject } from '../aggregation_object.js'; import { GlobalVariables } from '../global_variables.js'; From 1916038fd80afaaf29f205e308bd9b77d9ec282a Mon Sep 17 00:00:00 2001 From: jeanmon Date: Tue, 12 Sep 2023 07:41:17 +0000 Subject: [PATCH 8/8] 2117 - address feedback of David --- .../abis/rollup/root/root_rollup_inputs.hpp | 8 ++-- .../aztec3/circuits/rollup/merge/.test.cpp | 5 +++ .../src/aztec3/circuits/rollup/root/.test.cpp | 5 +++ .../root/native_root_rollup_circuit.cpp | 6 +-- .../circuits/rollup/test_utils/utils.cpp | 4 +- .../src/synchroniser/synchroniser.ts | 2 +- .../circuits.js/src/cbind/circuits.gen.ts | 28 ++++++------- .../__snapshots__/root_rollup.test.ts.snap | 4 +- .../src/structs/rollup/root_rollup.ts | 8 ++-- .../block_builder/solo_block_builder.test.ts | 4 +- .../src/block_builder/solo_block_builder.ts | 18 ++++----- yarn-project/types/src/l2_block.ts | 40 +++++++++---------- .../server_world_state_synchroniser.test.ts | 4 +- .../src/world-state-db/merkle_trees.ts | 2 +- 14 files changed, 74 insertions(+), 64 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp index b035e04eded..372390a8c05 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp @@ -20,9 +20,9 @@ template struct RootRollupInputs { // inputs required to process l1 to l2 messages std::array new_l1_to_l2_messages{}; - std::array new_l1_to_l2_message_tree_root_sibling_path{}; + std::array new_l1_to_l2_messages_tree_root_sibling_path{}; - AppendOnlyTreeSnapshot start_l1_to_l2_message_tree_snapshot{}; + AppendOnlyTreeSnapshot start_l1_to_l2_messages_tree_snapshot{}; // inputs required to add the block hash AppendOnlyTreeSnapshot start_historic_blocks_tree_snapshot{}; @@ -31,8 +31,8 @@ template struct RootRollupInputs { // For serialization, update with new fields MSGPACK_FIELDS(previous_rollup_data, new_l1_to_l2_messages, - new_l1_to_l2_message_tree_root_sibling_path, - start_l1_to_l2_message_tree_snapshot, + new_l1_to_l2_messages_tree_root_sibling_path, + start_l1_to_l2_messages_tree_snapshot, start_historic_blocks_tree_snapshot, new_historic_blocks_tree_sibling_path); bool operator==(RootRollupInputs const&) const = default; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp index 5aa4a30e619..b32cd6be371 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp @@ -28,6 +28,9 @@ class merge_rollup_tests : public ::testing::Test { protected: static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../barretenberg/cpp/srs_db/ignition"); } + // TODO(1998): uncomment once https://github.com/AztecProtocol/aztec-packages/issues/1998 is solved and + // use new pattern such as call_func_and_wrapper from test_helper.hpp + // static void run_cbind(MergeRollupInputs& merge_rollup_inputs, // BaseOrMergeRollupPublicInputs& expected_public_inputs, // bool compare_pubins = true) @@ -299,6 +302,8 @@ TEST_F(merge_rollup_tests, native_merge_cbind) ASSERT_FALSE(builder.failed()); BaseOrMergeRollupPublicInputs ignored_public_inputs; + + // TODO(1998): see above // run_cbind(inputs, ignored_public_inputs, false); } } // namespace aztec3::circuits::rollup::merge::native_merge_rollup_circuit diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp index ded030ebcd5..aff8660d432 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -64,6 +64,9 @@ class root_rollup_tests : public ::testing::Test { protected: static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../barretenberg/cpp/srs_db/ignition"); } + // TODO(1998): uncomment once https://github.com/AztecProtocol/aztec-packages/issues/1998 is solved and + // use new pattern such as call_func_and_wrapper from test_helper.hpp + // static void run_cbind(RootRollupInputs& root_rollup_inputs, // RootRollupPublicInputs& expected_public_inputs, // bool compare_pubins = true) @@ -149,6 +152,7 @@ TEST_F(root_rollup_tests, native_check_block_hashes_empty_blocks) EXPECT_FALSE(builder.failed()); + // TODO(1998): see above // run_cbind(inputs, outputs, true); } @@ -300,6 +304,7 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) EXPECT_FALSE(builder.failed()); + // TODO(1998): see above // run_cbind(rootRollupInputs, outputs, true); } diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp index 87115157dc9..3456108f791 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp @@ -98,8 +98,8 @@ RootRollupPublicInputs root_rollup_circuit(DummyBuilder& builder, RootRollupInpu const auto empty_l1_to_l2_subtree_root = components::calculate_empty_tree_root(L1_TO_L2_MSG_SUBTREE_HEIGHT); auto new_l1_to_l2_messages_tree_snapshot = components::insert_subtree_to_snapshot_tree( builder, - rootRollupInputs.start_l1_to_l2_message_tree_snapshot, - rootRollupInputs.new_l1_to_l2_message_tree_root_sibling_path, + rootRollupInputs.start_l1_to_l2_messages_tree_snapshot, + rootRollupInputs.new_l1_to_l2_messages_tree_root_sibling_path, empty_l1_to_l2_subtree_root, l1_to_l2_subtree_root, L1_TO_L2_MSG_SUBTREE_HEIGHT, @@ -138,7 +138,7 @@ RootRollupPublicInputs root_rollup_circuit(DummyBuilder& builder, RootRollupInpu .end_contract_tree_snapshot = right.end_contract_tree_snapshot, .start_public_data_tree_root = left.start_public_data_tree_root, .end_public_data_tree_root = right.end_public_data_tree_root, - .start_l1_to_l2_messages_tree_snapshot = rootRollupInputs.start_l1_to_l2_message_tree_snapshot, + .start_l1_to_l2_messages_tree_snapshot = rootRollupInputs.start_l1_to_l2_messages_tree_snapshot, .end_l1_to_l2_messages_tree_snapshot = new_l1_to_l2_messages_tree_snapshot, .start_historic_blocks_tree_snapshot = rootRollupInputs.start_historic_blocks_tree_snapshot, .end_historic_blocks_tree_snapshot = end_historic_blocks_tree_snapshot, diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp index 5b18741ffa0..0727fe73ae8 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp @@ -413,8 +413,8 @@ RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& builder, RootRollupInputs rootRollupInputs = { .previous_rollup_data = get_previous_rollup_data(builder, std::move(kernel_data)), .new_l1_to_l2_messages = l1_to_l2_messages, - .new_l1_to_l2_message_tree_root_sibling_path = l1_to_l2_tree_sibling_path, - .start_l1_to_l2_message_tree_snapshot = start_l1_to_l2_msg_tree_snapshot, + .new_l1_to_l2_messages_tree_root_sibling_path = l1_to_l2_tree_sibling_path, + .start_l1_to_l2_messages_tree_snapshot = start_l1_to_l2_msg_tree_snapshot, .start_historic_blocks_tree_snapshot = start_historic_blocks_tree_snapshot, .new_historic_blocks_tree_sibling_path = blocks_tree_sibling_path, }; diff --git a/yarn-project/aztec-rpc/src/synchroniser/synchroniser.ts b/yarn-project/aztec-rpc/src/synchroniser/synchroniser.ts index f4e3a978b83..57a0471addb 100644 --- a/yarn-project/aztec-rpc/src/synchroniser/synchroniser.ts +++ b/yarn-project/aztec-rpc/src/synchroniser/synchroniser.ts @@ -199,7 +199,7 @@ export class Synchroniser { block.endPrivateDataTreeSnapshot.root, block.endNullifierTreeSnapshot.root, block.endContractTreeSnapshot.root, - block.endL1ToL2MessageTreeSnapshot.root, + block.endL1ToL2MessagesTreeSnapshot.root, block.endHistoricBlocksTreeSnapshot.root, Fr.ZERO, // todo: private kernel vk tree root block.endPublicDataTreeRoot, diff --git a/yarn-project/circuits.js/src/cbind/circuits.gen.ts b/yarn-project/circuits.js/src/cbind/circuits.gen.ts index 8daa35a5add..3a257d984b1 100644 --- a/yarn-project/circuits.js/src/cbind/circuits.gen.ts +++ b/yarn-project/circuits.js/src/cbind/circuits.gen.ts @@ -2579,8 +2579,8 @@ export function fromMergeRollupInputs(o: MergeRollupInputs): MsgpackMergeRollupI interface MsgpackRootRollupInputs { previous_rollup_data: Tuple; new_l1_to_l2_messages: Tuple; - new_l1_to_l2_message_tree_root_sibling_path: Tuple; - start_l1_to_l2_message_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; + new_l1_to_l2_messages_tree_root_sibling_path: Tuple; + start_l1_to_l2_messages_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; start_historic_blocks_tree_snapshot: MsgpackAppendOnlyTreeSnapshot; new_historic_blocks_tree_sibling_path: Tuple; } @@ -2592,11 +2592,11 @@ export function toRootRollupInputs(o: MsgpackRootRollupInputs): RootRollupInputs if (o.new_l1_to_l2_messages === undefined) { throw new Error('Expected new_l1_to_l2_messages in RootRollupInputs deserialization'); } - if (o.new_l1_to_l2_message_tree_root_sibling_path === undefined) { - throw new Error('Expected new_l1_to_l2_message_tree_root_sibling_path in RootRollupInputs deserialization'); + if (o.new_l1_to_l2_messages_tree_root_sibling_path === undefined) { + throw new Error('Expected new_l1_to_l2_messages_tree_root_sibling_path in RootRollupInputs deserialization'); } - if (o.start_l1_to_l2_message_tree_snapshot === undefined) { - throw new Error('Expected start_l1_to_l2_message_tree_snapshot in RootRollupInputs deserialization'); + if (o.start_l1_to_l2_messages_tree_snapshot === undefined) { + throw new Error('Expected start_l1_to_l2_messages_tree_snapshot in RootRollupInputs deserialization'); } if (o.start_historic_blocks_tree_snapshot === undefined) { throw new Error('Expected start_historic_blocks_tree_snapshot in RootRollupInputs deserialization'); @@ -2607,8 +2607,8 @@ export function toRootRollupInputs(o: MsgpackRootRollupInputs): RootRollupInputs return new RootRollupInputs( mapTuple(o.previous_rollup_data, (v: MsgpackPreviousRollupData) => toPreviousRollupData(v)), mapTuple(o.new_l1_to_l2_messages, (v: Buffer) => Fr.fromBuffer(v)), - mapTuple(o.new_l1_to_l2_message_tree_root_sibling_path, (v: Buffer) => Fr.fromBuffer(v)), - toAppendOnlyTreeSnapshot(o.start_l1_to_l2_message_tree_snapshot), + mapTuple(o.new_l1_to_l2_messages_tree_root_sibling_path, (v: Buffer) => Fr.fromBuffer(v)), + toAppendOnlyTreeSnapshot(o.start_l1_to_l2_messages_tree_snapshot), toAppendOnlyTreeSnapshot(o.start_historic_blocks_tree_snapshot), mapTuple(o.new_historic_blocks_tree_sibling_path, (v: Buffer) => Fr.fromBuffer(v)), ); @@ -2621,11 +2621,11 @@ export function fromRootRollupInputs(o: RootRollupInputs): MsgpackRootRollupInpu if (o.newL1ToL2Messages === undefined) { throw new Error('Expected newL1ToL2Messages in RootRollupInputs serialization'); } - if (o.newL1ToL2MessageTreeRootSiblingPath === undefined) { - throw new Error('Expected newL1ToL2MessageTreeRootSiblingPath in RootRollupInputs serialization'); + if (o.newL1ToL2MessagesTreeRootSiblingPath === undefined) { + throw new Error('Expected newL1ToL2MessagesTreeRootSiblingPath in RootRollupInputs serialization'); } - if (o.startL1ToL2MessageTreeSnapshot === undefined) { - throw new Error('Expected startL1ToL2MessageTreeSnapshot in RootRollupInputs serialization'); + if (o.startL1ToL2MessagesTreeSnapshot === undefined) { + throw new Error('Expected startL1ToL2MessagesTreeSnapshot in RootRollupInputs serialization'); } if (o.startHistoricBlocksTreeSnapshot === undefined) { throw new Error('Expected startHistoricBlocksTreeSnapshot in RootRollupInputs serialization'); @@ -2636,10 +2636,10 @@ export function fromRootRollupInputs(o: RootRollupInputs): MsgpackRootRollupInpu return { previous_rollup_data: mapTuple(o.previousRollupData, (v: PreviousRollupData) => fromPreviousRollupData(v)), new_l1_to_l2_messages: mapTuple(o.newL1ToL2Messages, (v: Fr) => toBuffer(v)), - new_l1_to_l2_message_tree_root_sibling_path: mapTuple(o.newL1ToL2MessageTreeRootSiblingPath, (v: Fr) => + new_l1_to_l2_messages_tree_root_sibling_path: mapTuple(o.newL1ToL2MessagesTreeRootSiblingPath, (v: Fr) => toBuffer(v), ), - start_l1_to_l2_message_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startL1ToL2MessageTreeSnapshot), + start_l1_to_l2_messages_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startL1ToL2MessagesTreeSnapshot), start_historic_blocks_tree_snapshot: fromAppendOnlyTreeSnapshot(o.startHistoricBlocksTreeSnapshot), new_historic_blocks_tree_sibling_path: mapTuple(o.newHistoricBlocksTreeSiblingPath, (v: Fr) => toBuffer(v)), }; diff --git a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap index ab9d210c901..21421dd626f 100644 --- a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap @@ -131,8 +131,8 @@ sibling_path: [ 0x1120 0x1121 0x1122 0x1123 0x1124 0x1125 0x1126 0x1127 ] ] new_l1_to_l2_messages: [ 0x2100 0x2101 0x2102 0x2103 0x2104 0x2105 0x2106 0x2107 0x2108 0x2109 0x210a 0x210b 0x210c 0x210d 0x210e 0x210f ] -new_l1_to_l2_message_tree_root_sibling_path: [ 0x2100 0x2101 0x2102 0x2103 0x2104 0x2105 0x2106 0x2107 0x2108 0x2109 0x210a 0x210b ] -start_l1_to_l2_message_tree_snapshot: root: 0x2200 +new_l1_to_l2_messages_tree_root_sibling_path: [ 0x2100 0x2101 0x2102 0x2103 0x2104 0x2105 0x2106 0x2107 0x2108 0x2109 0x210a 0x210b ] +start_l1_to_l2_messages_tree_snapshot: root: 0x2200 next_available_leaf_index: 8704 start_historic_blocks_tree_snapshot: root: 0x2200 diff --git a/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts b/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts index 2c174a83fa7..4a3d98ef7ff 100644 --- a/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts +++ b/yarn-project/circuits.js/src/structs/rollup/root_rollup.ts @@ -31,11 +31,11 @@ export class RootRollupInputs { /** * Sibling path of the new L1 to L2 message tree root. */ - public newL1ToL2MessageTreeRootSiblingPath: Tuple, + public newL1ToL2MessagesTreeRootSiblingPath: Tuple, /** * Snapshot of the L1 to L2 message tree at the start of the rollup. */ - public startL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot, + public startL1ToL2MessagesTreeSnapshot: AppendOnlyTreeSnapshot, /** * Snapshot of the historic block roots tree at the start of the rollup. */ @@ -58,8 +58,8 @@ export class RootRollupInputs { return [ fields.previousRollupData, fields.newL1ToL2Messages, - fields.newL1ToL2MessageTreeRootSiblingPath, - fields.startL1ToL2MessageTreeSnapshot, + fields.newL1ToL2MessagesTreeRootSiblingPath, + fields.startL1ToL2MessagesTreeSnapshot, fields.startHistoricBlocksTreeSnapshot, fields.newHistoricBlocksTreeSiblingPath, ] as const; diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts index 42d566237ed..e675e093de9 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts @@ -241,8 +241,8 @@ describe('sequencer/solo_block_builder', () => { endContractTreeSnapshot: rootRollupOutput.endContractTreeSnapshot, startPublicDataTreeRoot: rootRollupOutput.startPublicDataTreeRoot, endPublicDataTreeRoot: rootRollupOutput.endPublicDataTreeRoot, - startL1ToL2MessageTreeSnapshot: rootRollupOutput.startL1ToL2MessagesTreeSnapshot, - endL1ToL2MessageTreeSnapshot: rootRollupOutput.endL1ToL2MessagesTreeSnapshot, + startL1ToL2MessagesTreeSnapshot: rootRollupOutput.startL1ToL2MessagesTreeSnapshot, + endL1ToL2MessagesTreeSnapshot: rootRollupOutput.endL1ToL2MessagesTreeSnapshot, startHistoricBlocksTreeSnapshot: rootRollupOutput.startHistoricBlocksTreeSnapshot, endHistoricBlocksTreeSnapshot: rootRollupOutput.endHistoricBlocksTreeSnapshot, newCommitments, diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts index 333c07adffa..10285ee6256 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts @@ -110,7 +110,7 @@ export class SoloBlockBuilder implements BlockBuilder { endNullifierTreeSnapshot, endContractTreeSnapshot, endPublicDataTreeRoot, - endL1ToL2MessagesTreeSnapshot: endL1ToL2MessageTreeSnapshot, + endL1ToL2MessagesTreeSnapshot, endHistoricBlocksTreeSnapshot, } = circuitsOutput; @@ -150,8 +150,8 @@ export class SoloBlockBuilder implements BlockBuilder { endContractTreeSnapshot, startPublicDataTreeRoot: startPublicDataTreeSnapshot.root, endPublicDataTreeRoot, - startL1ToL2MessageTreeSnapshot, - endL1ToL2MessageTreeSnapshot, + startL1ToL2MessagesTreeSnapshot: startL1ToL2MessageTreeSnapshot, + endL1ToL2MessagesTreeSnapshot, startHistoricBlocksTreeSnapshot, endHistoricBlocksTreeSnapshot, newCommitments, @@ -438,20 +438,20 @@ export class SoloBlockBuilder implements BlockBuilder { return path.toFieldArray(); }; - const newL1ToL2MessageTreeRootSiblingPathArray = await this.getSubtreeSiblingPath( + const newL1ToL2MessagesTreeRootSiblingPathArray = await this.getSubtreeSiblingPath( MerkleTreeId.L1_TO_L2_MESSAGES_TREE, L1_TO_L2_MSG_SUBTREE_HEIGHT, ); - const newL1ToL2MessageTreeRootSiblingPath = makeTuple( + const newL1ToL2MessagesTreeRootSiblingPath = makeTuple( L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, i => - i < newL1ToL2MessageTreeRootSiblingPathArray.length ? newL1ToL2MessageTreeRootSiblingPathArray[i] : Fr.ZERO, + i < newL1ToL2MessagesTreeRootSiblingPathArray.length ? newL1ToL2MessagesTreeRootSiblingPathArray[i] : Fr.ZERO, 0, ); // Get tree snapshots - const startL1ToL2MessageTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGES_TREE); + const startL1ToL2MessagesTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGES_TREE); // Get historic block tree roots const startHistoricBlocksTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.BLOCKS_TREE); @@ -466,8 +466,8 @@ export class SoloBlockBuilder implements BlockBuilder { return RootRollupInputs.from({ previousRollupData, newL1ToL2Messages, - newL1ToL2MessageTreeRootSiblingPath, - startL1ToL2MessageTreeSnapshot, + newL1ToL2MessagesTreeRootSiblingPath, + startL1ToL2MessagesTreeSnapshot, startHistoricBlocksTreeSnapshot, newHistoricBlocksTreeSiblingPath, }); diff --git a/yarn-project/types/src/l2_block.ts b/yarn-project/types/src/l2_block.ts index 5a552e593f4..a3a7c1e7a20 100644 --- a/yarn-project/types/src/l2_block.ts +++ b/yarn-project/types/src/l2_block.ts @@ -78,7 +78,7 @@ export class L2Block { /** * The tree snapshot of the L2 message tree at the start of the rollup. */ - public startL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot, + public startL1ToL2MessagesTreeSnapshot: AppendOnlyTreeSnapshot, /** * The tree snapshot of the historic blocks tree at the start of the rollup. */ @@ -102,7 +102,7 @@ export class L2Block { /** * The tree snapshot of the L2 message tree at the end of the rollup. */ - public endL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot, + public endL1ToL2MessagesTreeSnapshot: AppendOnlyTreeSnapshot, /** * The tree snapshot of the historic blocks tree at the end of the rollup. */ @@ -188,13 +188,13 @@ export class L2Block { startNullifierTreeSnapshot: makeAppendOnlyTreeSnapshot(0), startContractTreeSnapshot: makeAppendOnlyTreeSnapshot(0), startPublicDataTreeRoot: Fr.random(), - startL1ToL2MessageTreeSnapshot: makeAppendOnlyTreeSnapshot(0), + startL1ToL2MessagesTreeSnapshot: makeAppendOnlyTreeSnapshot(0), startHistoricBlocksTreeSnapshot: makeAppendOnlyTreeSnapshot(0), endPrivateDataTreeSnapshot: makeAppendOnlyTreeSnapshot(newCommitments.length), endNullifierTreeSnapshot: makeAppendOnlyTreeSnapshot(newNullifiers.length), endContractTreeSnapshot: makeAppendOnlyTreeSnapshot(newContracts.length), endPublicDataTreeRoot: Fr.random(), - endL1ToL2MessageTreeSnapshot: makeAppendOnlyTreeSnapshot(1), + endL1ToL2MessagesTreeSnapshot: makeAppendOnlyTreeSnapshot(1), endHistoricBlocksTreeSnapshot: makeAppendOnlyTreeSnapshot(1), newCommitments, newNullifiers, @@ -243,7 +243,7 @@ export class L2Block { /** * The tree snapshot of the L2 message tree at the start of the rollup. */ - startL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot; + startL1ToL2MessagesTreeSnapshot: AppendOnlyTreeSnapshot; /** * The tree snapshot of the historic blocks tree at the start of the rollup. */ @@ -267,7 +267,7 @@ export class L2Block { /** * The tree snapshot of the L2 message tree at the end of the rollup. */ - endL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot; + endL1ToL2MessagesTreeSnapshot: AppendOnlyTreeSnapshot; /** * The tree snapshot of the historic blocks tree at the end of the rollup. */ @@ -318,13 +318,13 @@ export class L2Block { fields.startNullifierTreeSnapshot, fields.startContractTreeSnapshot, fields.startPublicDataTreeRoot, - fields.startL1ToL2MessageTreeSnapshot, + fields.startL1ToL2MessagesTreeSnapshot, fields.startHistoricBlocksTreeSnapshot, fields.endPrivateDataTreeSnapshot, fields.endNullifierTreeSnapshot, fields.endContractTreeSnapshot, fields.endPublicDataTreeRoot, - fields.endL1ToL2MessageTreeSnapshot, + fields.endL1ToL2MessagesTreeSnapshot, fields.endHistoricBlocksTreeSnapshot, fields.newCommitments, fields.newNullifiers, @@ -354,13 +354,13 @@ export class L2Block { this.startNullifierTreeSnapshot, this.startContractTreeSnapshot, this.startPublicDataTreeRoot, - this.startL1ToL2MessageTreeSnapshot, + this.startL1ToL2MessagesTreeSnapshot, this.startHistoricBlocksTreeSnapshot, this.endPrivateDataTreeSnapshot, this.endNullifierTreeSnapshot, this.endContractTreeSnapshot, this.endPublicDataTreeRoot, - this.endL1ToL2MessageTreeSnapshot, + this.endL1ToL2MessagesTreeSnapshot, this.endHistoricBlocksTreeSnapshot, this.newCommitments.length, this.newCommitments, @@ -401,13 +401,13 @@ export class L2Block { const startNullifierTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot); const startContractTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot); const startPublicDataTreeRoot = reader.readObject(Fr); - const startL1ToL2MessageTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot); + const startL1ToL2MessagesTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot); const startHistoricBlocksTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot); const endPrivateDataTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot); const endNullifierTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot); const endContractTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot); const endPublicDataTreeRoot = reader.readObject(Fr); - const endL1ToL2MessageTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot); + const endL1ToL2MessagesTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot); const endHistoricBlocksTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot); const newCommitments = reader.readVector(Fr); const newNullifiers = reader.readVector(Fr); @@ -427,13 +427,13 @@ export class L2Block { startNullifierTreeSnapshot, startContractTreeSnapshot, startPublicDataTreeRoot, - startL1ToL2MessageTreeSnapshot, + startL1ToL2MessagesTreeSnapshot: startL1ToL2MessagesTreeSnapshot, startHistoricBlocksTreeSnapshot, endPrivateDataTreeSnapshot, endNullifierTreeSnapshot, endContractTreeSnapshot, endPublicDataTreeRoot, - endL1ToL2MessageTreeSnapshot, + endL1ToL2MessagesTreeSnapshot, endHistoricBlocksTreeSnapshot, newCommitments, newNullifiers, @@ -502,13 +502,13 @@ export class L2Block { this.startNullifierTreeSnapshot, this.startContractTreeSnapshot, this.startPublicDataTreeRoot, - this.startL1ToL2MessageTreeSnapshot, + this.startL1ToL2MessagesTreeSnapshot, this.startHistoricBlocksTreeSnapshot, this.endPrivateDataTreeSnapshot, this.endNullifierTreeSnapshot, this.endContractTreeSnapshot, this.endPublicDataTreeRoot, - this.endL1ToL2MessageTreeSnapshot, + this.endL1ToL2MessagesTreeSnapshot, this.endHistoricBlocksTreeSnapshot, this.getCalldataHash(), this.getL1ToL2MessagesHash(), @@ -528,7 +528,7 @@ export class L2Block { this.startNullifierTreeSnapshot, this.startContractTreeSnapshot, this.startPublicDataTreeRoot, - this.startL1ToL2MessageTreeSnapshot, + this.startL1ToL2MessagesTreeSnapshot, this.startHistoricBlocksTreeSnapshot, ); return sha256(inputValue); @@ -545,7 +545,7 @@ export class L2Block { this.endNullifierTreeSnapshot, this.endContractTreeSnapshot, this.endPublicDataTreeRoot, - this.endL1ToL2MessageTreeSnapshot, + this.endL1ToL2MessagesTreeSnapshot, this.endHistoricBlocksTreeSnapshot, ); return sha256(inputValue); @@ -741,14 +741,14 @@ export class L2Block { `startNullifierTreeSnapshot: ${inspectTreeSnapshot(this.startNullifierTreeSnapshot)}`, `startContractTreeSnapshot: ${inspectTreeSnapshot(this.startContractTreeSnapshot)}`, `startPublicDataTreeRoot: ${this.startPublicDataTreeRoot.toString()}`, - `startL1ToL2MessageTreeSnapshot: ${inspectTreeSnapshot(this.startL1ToL2MessageTreeSnapshot)}`, + `startL1ToL2MessagesTreeSnapshot: ${inspectTreeSnapshot(this.startL1ToL2MessagesTreeSnapshot)}`, `startHistoricBlocksTreeSnapshot: ${inspectTreeSnapshot(this.startHistoricBlocksTreeSnapshot)}`, `endPrivateDataTreeSnapshot: ${inspectTreeSnapshot(this.endPrivateDataTreeSnapshot)}`, `endNullifierTreeSnapshot: ${inspectTreeSnapshot(this.endNullifierTreeSnapshot)}`, `endContractTreeSnapshot: ${inspectTreeSnapshot(this.endContractTreeSnapshot)}`, `endPublicDataTreeRoot: ${this.endPublicDataTreeRoot.toString()}`, `endPublicDataTreeRoot: ${this.endPublicDataTreeRoot.toString()}`, - `endL1ToL2MessageTreeSnapshot: ${inspectTreeSnapshot(this.endL1ToL2MessageTreeSnapshot)}`, + `endL1ToL2MessagesTreeSnapshot: ${inspectTreeSnapshot(this.endL1ToL2MessagesTreeSnapshot)}`, `endHistoricBlocksTreeSnapshot: ${inspectTreeSnapshot(this.endHistoricBlocksTreeSnapshot)}`, `newCommitments: ${inspectFrArray(this.newCommitments)}`, `newNullifiers: ${inspectFrArray(this.newNullifiers)}`, diff --git a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts index cdc1121a5e6..d4fafd16e3d 100644 --- a/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts +++ b/yarn-project/world-state/src/synchroniser/server_world_state_synchroniser.test.ts @@ -76,13 +76,13 @@ const getMockBlock = (blockNumber: number, newContractsCommitments?: Buffer[]) = startNullifierTreeSnapshot: getMockTreeSnapshot(), startContractTreeSnapshot: getMockTreeSnapshot(), startPublicDataTreeRoot: Fr.random(), - startL1ToL2MessageTreeSnapshot: getMockTreeSnapshot(), + startL1ToL2MessagesTreeSnapshot: getMockTreeSnapshot(), startHistoricBlocksTreeSnapshot: getMockTreeSnapshot(), endPrivateDataTreeSnapshot: getMockTreeSnapshot(), endNullifierTreeSnapshot: getMockTreeSnapshot(), endContractTreeSnapshot: getMockTreeSnapshot(), endPublicDataTreeRoot: Fr.random(), - endL1ToL2MessageTreeSnapshot: getMockTreeSnapshot(), + endL1ToL2MessagesTreeSnapshot: getMockTreeSnapshot(), endHistoricBlocksTreeSnapshot: getMockTreeSnapshot(), newCommitments: times(MAX_NEW_COMMITMENTS_PER_TX, Fr.random), newNullifiers: times(MAX_NEW_NULLIFIERS_PER_TX, Fr.random), diff --git a/yarn-project/world-state/src/world-state-db/merkle_trees.ts b/yarn-project/world-state/src/world-state-db/merkle_trees.ts index 23166d50787..b4cd63846a7 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_trees.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_trees.ts @@ -536,7 +536,7 @@ export class MerkleTrees implements MerkleTreeDb { compareRoot(l2Block.endNullifierTreeSnapshot.root, MerkleTreeId.NULLIFIER_TREE), compareRoot(l2Block.endPrivateDataTreeSnapshot.root, MerkleTreeId.PRIVATE_DATA_TREE), compareRoot(l2Block.endPublicDataTreeRoot, MerkleTreeId.PUBLIC_DATA_TREE), - compareRoot(l2Block.endL1ToL2MessageTreeSnapshot.root, MerkleTreeId.L1_TO_L2_MESSAGES_TREE), + compareRoot(l2Block.endL1ToL2MessagesTreeSnapshot.root, MerkleTreeId.L1_TO_L2_MESSAGES_TREE), compareRoot(l2Block.endHistoricBlocksTreeSnapshot.root, MerkleTreeId.BLOCKS_TREE), ]; const ourBlock = rootChecks.every(x => x);