Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ template <typename NCT> struct CombinedHistoricTreeRoots {
public_data_tree_root == other.public_data_tree_root;
};

template <typename Composer> CombinedHistoricTreeRoots<CircuitTypes<Composer>> to_circuit_type(Composer& composer) const
template <typename Composer>
CombinedHistoricTreeRoots<CircuitTypes<Composer>> to_circuit_type(Composer& composer) const
{
static_assert((std::is_same<NativeTypes, NCT>::value));

Expand Down Expand Up @@ -80,7 +81,8 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, CombinedHistoricTr
write(buf, historic_tree_roots.public_data_tree_root);
};

template <typename NCT> std::ostream& operator<<(std::ostream& os, CombinedHistoricTreeRoots<NCT> const& historic_tree_roots)
template <typename NCT>
std::ostream& operator<<(std::ostream& os, CombinedHistoricTreeRoots<NCT> 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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ template <typename NCT> struct PrivateHistoricTreeRoots {
private_kernel_vk_tree_root == other.private_kernel_vk_tree_root;
};

template <typename Composer> PrivateHistoricTreeRoots<CircuitTypes<Composer>> to_circuit_type(Composer& composer) const
template <typename Composer>
PrivateHistoricTreeRoots<CircuitTypes<Composer>> to_circuit_type(Composer& composer) const
{
static_assert((std::is_same<NativeTypes, NCT>::value));

Expand Down Expand Up @@ -90,7 +91,8 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, PrivateHistoricTre
write(buf, historic_tree_roots.private_kernel_vk_tree_root);
};

template <typename NCT> std::ostream& operator<<(std::ostream& os, PrivateHistoricTreeRoots<NCT> const& historic_tree_roots)
template <typename NCT>
std::ostream& operator<<(std::ostream& os, PrivateHistoricTreeRoots<NCT> 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"
Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ PrivateInputs<NT> 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<NT>{
.historic_tree_roots =
CombinedHistoricTreeRoots<NT> {
CombinedHistoricTreeRoots<NT>{
.private_historic_tree_roots =
PrivateHistoricTreeRoots<NT>{
.private_data_tree_root = private_circuit_public_inputs.historic_private_data_tree_root,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
3 changes: 2 additions & 1 deletion circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NT, PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT> historic_root_witness =
baseRollupInputs.historic_private_data_tree_root_membership_witnesses[i];

Expand Down
98 changes: 69 additions & 29 deletions yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down
21 changes: 18 additions & 3 deletions yarn-project/circuits.js/src/abis/abis.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion yarn-project/circuits.js/src/abis/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CircuitsWasm } from '../wasm/index.js';
import {
FunctionData,
FUNCTION_SELECTOR_NUM_BYTES,
ARGS_LENGTH,
TxRequest,
NewContractData,
FunctionLeafPreimage,
Expand Down Expand Up @@ -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,
Expand Down