diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp index 0218218e12e8..297f39a54c4b 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp @@ -25,7 +25,8 @@ template struct CombinedHistoricTreeRoots { public_data_tree_root == other.public_data_tree_root; }; - template CombinedHistoricTreeRoots> to_circuit_type(Composer& composer) const + template + CombinedHistoricTreeRoots> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); @@ -80,7 +81,8 @@ template void write(std::vector& buf, CombinedHistoricTr write(buf, historic_tree_roots.public_data_tree_root); }; -template std::ostream& operator<<(std::ostream& os, CombinedHistoricTreeRoots const& historic_tree_roots) +template +std::ostream& operator<<(std::ostream& os, CombinedHistoricTreeRoots const& historic_tree_roots) { return os << "private_historic_tree_roots: " << historic_tree_roots.private_historic_tree_roots << "\n" << "public_data_tree_root: " << historic_tree_roots.public_data_tree_root << "\n"; diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp index a509148ad988..e2571be1141e 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp @@ -27,7 +27,8 @@ template struct PrivateHistoricTreeRoots { private_kernel_vk_tree_root == other.private_kernel_vk_tree_root; }; - template PrivateHistoricTreeRoots> to_circuit_type(Composer& composer) const + template + PrivateHistoricTreeRoots> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); @@ -90,7 +91,8 @@ template void write(std::vector& buf, PrivateHistoricTre write(buf, historic_tree_roots.private_kernel_vk_tree_root); }; -template std::ostream& operator<<(std::ostream& os, PrivateHistoricTreeRoots const& historic_tree_roots) +template +std::ostream& operator<<(std::ostream& os, PrivateHistoricTreeRoots const& historic_tree_roots) { return os << "private_data_tree_root: " << historic_tree_roots.private_data_tree_root << "\n" << "nullifier_tree_root: " << historic_tree_roots.nullifier_tree_root << "\n" diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp index a08979f53e47..a6d646d2680d 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp @@ -339,7 +339,7 @@ PrivateInputs do_private_call_get_kernel_inputs(bool const is_constructor, mock_previous_kernel.public_inputs.end.private_call_stack = initial_kernel_private_call_stack; mock_previous_kernel.public_inputs.constants = CombinedConstantData{ .historic_tree_roots = - CombinedHistoricTreeRoots { + CombinedHistoricTreeRoots{ .private_historic_tree_roots = PrivateHistoricTreeRoots{ .private_data_tree_root = private_circuit_public_inputs.historic_private_data_tree_root, diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp index a599dc474cdf..8649bca1057a 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp @@ -144,7 +144,8 @@ void contract_logic(DummyComposer& composer, auto const& purported_contract_tree_root = private_inputs.private_call.call_stack_item.public_inputs.historic_contract_tree_root; auto const& previous_kernel_contract_tree_root = - private_inputs.previous_kernel.public_inputs.constants.historic_tree_roots.private_historic_tree_roots.contract_tree_root; + private_inputs.previous_kernel.public_inputs.constants.historic_tree_roots.private_historic_tree_roots + .contract_tree_root; composer.do_assert(purported_contract_tree_root == previous_kernel_contract_tree_root, "purported_contract_tree_root doesn't match previous_kernel_contract_tree_root"); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp index 145e2b0f159c..3c67daf640a3 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -693,7 +693,8 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_private_data) .root = tree.root(), .next_available_leaf_index = 0, }; - inputs.kernel_data[0].public_inputs.constants.historic_tree_roots.private_historic_tree_roots.private_data_tree_root = fr(0); + inputs.kernel_data[0] + .public_inputs.constants.historic_tree_roots.private_historic_tree_roots.private_data_tree_root = fr(0); // fetch sibling path from hash path (only get the second half of the hash path) auto hash_path = tree.get_hash_path(0); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp index ab4f77b84b40..79d9b124278b 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp @@ -201,8 +201,9 @@ void perform_historical_private_data_tree_membership_checks(DummyComposer& compo auto historic_root = baseRollupInputs.constants.start_tree_of_historic_private_data_tree_roots_snapshot.root; for (size_t i = 0; i < 2; i++) { - NT::fr leaf = baseRollupInputs.kernel_data[i] - .public_inputs.constants.historic_tree_roots.private_historic_tree_roots.private_data_tree_root; + NT::fr leaf = + baseRollupInputs.kernel_data[i] + .public_inputs.constants.historic_tree_roots.private_historic_tree_roots.private_data_tree_root; abis::MembershipWitness historic_root_witness = baseRollupInputs.historic_private_data_tree_root_membership_witnesses[i]; diff --git a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap index 02c843658d3b..6b5c2ce50060 100644 --- a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap +++ b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap @@ -99,41 +99,81 @@ Fr { } `; -exports[`abis wasm bindings hash constructor info 1`] = ` +exports[`abis wasm bindings hash constructor info (max args) 1`] = ` { "data": [ - 36, - 203, - 121, - 198, - 238, - 246, - 39, 11, - 209, - 251, - 234, - 135, - 70, - 0, - 68, - 226, - 184, - 31, - 77, + 83, 126, - 81, - 123, - 23, - 198, - 162, - 185, - 199, - 254, + 59, + 216, + 223, + 139, + 197, + 97, + 118, + 93, + 86, + 72, + 166, + 146, 183, - 90, - 167, + 120, + 217, + 74, + 66, + 45, + 248, + 192, + 209, + 59, + 200, + 244, + 214, + 63, + 239, + 67, + 177, + ], + "type": "Buffer", +} +`; + +exports[`abis wasm bindings hash constructor info 2 args 1`] = ` +{ + "data": [ + 6, + 8, + 191, + 65, + 136, + 96, + 198, + 140, + 203, + 137, + 102, + 172, + 105, + 89, + 77, + 15, + 15, + 196, + 42, + 213, + 11, + 179, 9, + 133, + 16, + 68, + 18, + 76, + 208, + 143, + 149, + 123, ], "type": "Buffer", } diff --git a/yarn-project/circuits.js/src/abis/abis.test.ts b/yarn-project/circuits.js/src/abis/abis.test.ts index d4dd9812009e..969537d8f67b 100644 --- a/yarn-project/circuits.js/src/abis/abis.test.ts +++ b/yarn-project/circuits.js/src/abis/abis.test.ts @@ -1,4 +1,4 @@ -import { Fr, FunctionData, FunctionLeafPreimage, NewContractData } from '../index.js'; +import { ARGS_LENGTH, Fr, FunctionData, FunctionLeafPreimage, NewContractData } from '../index.js'; import { makeEthAddress } from '../tests/factories.js'; import { makeAztecAddress, makeBytes, makeTxRequest, makeVerificationKey } from '../tests/factories.js'; import { CircuitsWasm } from '../wasm/circuits_wasm.js'; @@ -66,15 +66,30 @@ describe('abis wasm bindings', () => { expect(res).toMatchSnapshot(); }); - it('hash constructor info', async () => { + it('hash constructor info 2 args', async () => { const functionData = new FunctionData(Buffer.alloc(4), true, true); // args needs to have a FIXED length of 8, due to a circuit constant `aztec3::ARGS_SIZE`. - const args = [new Fr(0n), new Fr(1n), new Fr(0n), new Fr(1n), new Fr(0n), new Fr(1n), new Fr(0n), new Fr(1n)]; + const args = [new Fr(0n), new Fr(1n)]; const vkHash = Buffer.alloc(32); const res = await hashConstructor(wasm, functionData, args, vkHash); expect(res).toMatchSnapshot(); }); + it('hash constructor info (max args)', async () => { + const functionData = new FunctionData(Buffer.alloc(4), true, true); + const args = Array.from({ length: ARGS_LENGTH }, (v, i) => new Fr(BigInt(i))); + const vkHash = Buffer.alloc(32); + const res = await hashConstructor(wasm, functionData, args, vkHash); + expect(res).toMatchSnapshot(); + }); + + it('hash constructor throws (>max args)', async () => { + const functionData = new FunctionData(Buffer.alloc(4), true, true); + const args = Array.from({ length: ARGS_LENGTH + 1 }, (v, i) => new Fr(BigInt(i))); + const vkHash = Buffer.alloc(32); + await expect(hashConstructor(wasm, functionData, args, vkHash)).rejects.toThrow(); + }); + it('computes a contract address', async () => { const deployerAddr = makeAztecAddress(1); const contractAddrSalt = new Fr(2n); diff --git a/yarn-project/circuits.js/src/abis/abis.ts b/yarn-project/circuits.js/src/abis/abis.ts index b3e0f652a9cc..6f1a89a49bbf 100644 --- a/yarn-project/circuits.js/src/abis/abis.ts +++ b/yarn-project/circuits.js/src/abis/abis.ts @@ -4,6 +4,7 @@ import { CircuitsWasm } from '../wasm/index.js'; import { FunctionData, FUNCTION_SELECTOR_NUM_BYTES, + ARGS_LENGTH, TxRequest, NewContractData, FunctionLeafPreimage, @@ -108,7 +109,13 @@ export async function hashConstructor( args: Fr[], constructorVKHash: Buffer, ) { - const inputVector = serializeToBuffer(args.map(fr => fr.toBuffer())); + if (args.length > ARGS_LENGTH) { + throw new Error(`Expected constructor args to have length <= ${ARGS_LENGTH}! Was: ${args.length}`); + } + const numEmptyArgs = ARGS_LENGTH - args.length; + const emptyArgs = Array.from({ length: numEmptyArgs }, () => new Fr(0n)); + const fullArgs = args.concat(emptyArgs); + const inputVector = serializeToBuffer(fullArgs.map(fr => fr.toBuffer())); wasm.call('pedersen__init'); const result = await inputBuffersToOutputBuffer( wasm,