Skip to content

Commit

Permalink
Check that public data tree root follows from left to right rollup (#396
Browse files Browse the repository at this point in the history
)

* Check that public data tree root follows from left to right rollup

* Fix rollup circuits wasm test
  • Loading branch information
spalladino authored Apr 27, 2023
1 parent 12e44a2 commit 6d2a29f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ void assert_prev_rollups_follow_on_from_each_other(DummyComposer& composer,
composer.do_assert(left.end_contract_tree_snapshot == right.start_contract_tree_snapshot,
"input proofs have different contract tree snapshots",
utils::CircuitErrorCode::CONTRACT_TREE_SNAPSHOT_MISMATCH);
composer.do_assert(left.end_public_data_tree_snapshot == right.start_public_data_tree_snapshot,
"input proofs have different public data tree snapshots",
utils::CircuitErrorCode::CONTRACT_TREE_SNAPSHOT_MISMATCH);
}

} // namespace aztec3::circuits::rollup::components
6 changes: 6 additions & 0 deletions circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ TEST_F(merge_rollup_tests, native_start_and_end_snapshots)
inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot);
ASSERT_EQ(outputs.end_contract_tree_snapshot,
inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot);

ASSERT_EQ(outputs.start_public_data_tree_snapshot,
inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_public_data_tree_snapshot);
ASSERT_EQ(outputs.end_public_data_tree_snapshot,
inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_public_data_tree_snapshot);

ASSERT_FALSE(composer.failed());
}

Expand Down
16 changes: 12 additions & 4 deletions circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,24 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic)
RootRollupPublicInputs outputs =
aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit(composer, rootRollupInputs);

// Check data trees
// Check private data trees
ASSERT_EQ(
outputs.start_private_data_tree_snapshot,
rootRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_private_data_tree_snapshot);
ASSERT_EQ(
outputs.end_private_data_tree_snapshot,
rootRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_private_data_tree_snapshot);
AppendOnlyTreeSnapshot<NT> expected_data_tree_snapshot = { .root = data_tree.root(),
.next_available_leaf_index = 16 };
ASSERT_EQ(outputs.end_private_data_tree_snapshot, expected_data_tree_snapshot);
AppendOnlyTreeSnapshot<NT> expected_private_data_tree_snapshot = { .root = data_tree.root(),
.next_available_leaf_index = 16 };
ASSERT_EQ(outputs.end_private_data_tree_snapshot, expected_private_data_tree_snapshot);

// Check public data trees
ASSERT_EQ(
outputs.start_public_data_tree_snapshot,
rootRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_public_data_tree_snapshot);
ASSERT_EQ(
outputs.end_public_data_tree_snapshot,
rootRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_public_data_tree_snapshot);

// check contract trees
ASSERT_EQ(outputs.start_contract_tree_snapshot,
Expand Down
3 changes: 2 additions & 1 deletion circuits/cpp/src/aztec3/utils/circuit_errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ enum CircuitErrorCode : uint16_t {
PRIVATE_DATA_TREE_SNAPSHOT_MISMATCH = 7004,
NULLIFIER_TREE_SNAPSHOT_MISMATCH = 7005,
CONTRACT_TREE_SNAPSHOT_MISMATCH = 7006,
MEMBERSHIP_CHECK_FAILED = 7007,
PUBLIC_DATA_TREE_SNAPSHOT_MISMATCH = 7007,
MEMBERSHIP_CHECK_FAILED = 7008,

ROOT_CIRCUIT_FAILED = 8000,
};
Expand Down
30 changes: 16 additions & 14 deletions yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { AggregationObject, CircuitError, VerificationKey } from '../index.js';
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';

// TODO: All these tests are currently failing with segfaults.
// Note that base and root rollup sim are called ok from the circuit_powered_block_builder,
// so the problem must be with an invalid input we're providing.
describe('rollup/rollup_wasm_wrapper', () => {
let wasm: CircuitsWasm;
let rollupWasm: RollupWasmWrapper;
Expand All @@ -25,20 +22,25 @@ describe('rollup/rollup_wasm_wrapper', () => {
return input;
};

const makeMergeRollupInputsForCircuit = () => {
const input = makeMergeRollupInputs();
for (const previousData of input.previousRollupData) {
previousData.vk = VerificationKey.makeFake();
previousData.publicInputs.endAggregationObject = AggregationObject.makeFake();
}
// fix inputs to make it compatible with the merge circuit requirements
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.startPublicDataTreeSnapshot =
input.previousRollupData[0].publicInputs.endPublicDataTreeSnapshot;
};

const makeMergeRollupInputsForCircuit = () => {
const input = makeMergeRollupInputs();
for (const previousData of input.previousRollupData) {
previousData.vk = VerificationKey.makeFake();
previousData.publicInputs.endAggregationObject = AggregationObject.makeFake();
}
fixPreviousRollupInputs(input);
return input;
};

Expand Down Expand Up @@ -85,18 +87,18 @@ describe('rollup/rollup_wasm_wrapper', () => {
}
});

it.skip('calls root_rollup__sim', async () => {
it('calls root_rollup__sim', async () => {
const input = makeRootRollupInputs();

for (const rd of input.previousRollupData) {
rd.vk = VerificationKey.makeFake();
rd.publicInputs.endAggregationObject = AggregationObject.makeFake();
rd.publicInputs = await rollupWasm.simulateBaseRollup(makeBaseRollupInputsForCircuit());
}
fixPreviousRollupInputs(input);

const output = await rollupWasm.simulateRootRollup(input);
expect(output.startNullifierTreeSnapshot).toEqual(
input.previousRollupData[0].publicInputs.startNullifierTreeSnapshot,
);
});
}, 15_000);
});

0 comments on commit 6d2a29f

Please sign in to comment.