Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add E2E calldataHash test (sol/ts/cpp) #431

Merged
merged 12 commits into from
May 4, 2023

Conversation

LHerskind
Copy link
Contributor

@LHerskind LHerskind commented May 2, 2023

Description

Fixes #390 and #399.

  • Updates calldata hash in cpp to include the public writes;
  • Check that cpp/sol/ts all get same calldata hash;
  • Update contract tree prep in test_utils/utils.cpp to have proper index and tree generation.
  • Removes unused standalone_block_builder
  • Renames circuit_block_builder to solo_block_builder

l2-block-publisher tests are unfunctional since #408 was merged in. But @benesjan is addresseing this with #458.

Checklist:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • The branch has been merged or rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.

@LHerskind LHerskind changed the title test: add E2E calldataHash (sol/ts/cpp) Add E2E calldataHash test (sol/ts/cpp) May 2, 2023
@LHerskind LHerskind marked this pull request as ready for review May 2, 2023 19:14
@LHerskind LHerskind requested review from Maddiaa0, spalladino and rahul-kothari and removed request for Maddiaa0 May 2, 2023 19:14
@LHerskind LHerskind marked this pull request as draft May 3, 2023 09:37
@LHerskind LHerskind marked this pull request as ready for review May 3, 2023 09:54
@LHerskind LHerskind linked an issue May 3, 2023 that may be closed by this pull request
@LHerskind LHerskind marked this pull request as draft May 3, 2023 13:01
@LHerskind LHerskind force-pushed the lh/circuit-public-calldata-hash branch from d1702c4 to 2a95d3a Compare May 3, 2023 17:25
circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp Outdated Show resolved Hide resolved
@@ -183,7 +180,7 @@ TEST_F(root_rollup_tests, native_check_block_hashes_empty_blocks)
EXPECT_FALSE(composer.failed());

// Expected hash of public inputs for an empty L2 block. Also used in the contract tests.
fr const expected_hash = uint256_t("11840efc30e9fcbdd0aae30da2a5b441132420b4f0cc4ffd6bdc41888845f775");
fr const expected_hash = uint256_t("23f698e487c4e1b7383889f8864bc19591773d136c364c01d980bd13d0786ba1");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we recalculate this value? Is it viable to calculate it on the fly in the test instead of hardcoding?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its values from the l2-block-publisher.test.ts, there to make sure that they are on par.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LHerskind please put there a comment that the value is from l2-block-publisher.test.ts

@@ -120,6 +120,43 @@ export class RootRollupPublicInputs {
return new RootRollupPublicInputs(...RootRollupPublicInputs.getFields(fields));
}

static makeFake() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename to empty()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was my original name, but used makefake as it cointained the aggregation object that was named makefake so assumed there was a reason the underlying was not called empty and that it should convey that as well.

expect(l2Block.number).toEqual(blockNumber);
expect(l2Block.getCalldataHash()).toEqual(rootRollupPublicInputs.sha256CalldataHash());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this check is the only reason why we're exposing the root rollup simulation output from the block builder, then I'd make it a responsibility of the block builder to make this check instead, and revert the change to its interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cheethas and I spoke about it. Main annoyance with that it broke some tests, but probably better to fix those mocks anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goodbye StandaloneBlockBuilder, you served well!

We could use this opportunity to rename the circuit_block_builder to just block_builder. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please i beg

Copy link
Contributor Author

@LHerskind LHerskind May 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, what should we do with the interface? Currently there is a BlockBuilder interface, should we still keep that or just have the block builder?

Copy link
Contributor Author

@LHerskind LHerskind May 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On interfaces, is there a reason we are not naming them starting on I or similar, always have a headache looking through the code and not knowing if it is an interface or not before following it to the root.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to SoloBlockBuilder as we will probably see the distributed block builder further down the road, and not having issues with interface and class having same name

Comment on lines 134 to 138
// 8 commitments (4 per kernel) -> 8 fields
// 8 nullifiers (4 per kernel) -> 8 fields
// 8 public state transitions (4 per kernel) -> 16 fields
// 2 contract deployments (1 per kernel) -> 6 fields
std::array<NT::fr, 38> calldata_hash_inputs;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this 38 could be derived out of constants in constants.hpp using constexprs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as long as we are not adding new types or anything but extending current lists should be fine.

return await makeProcessedTx(publicTx, kernelOutput, makeProof());
};

it('Build 2 blocks of 4 txs building on each other', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the actual block builder here, rather than manually assembling the block? Seems like it'd lead to less duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just good ol' debt.

@LHerskind LHerskind force-pushed the lh/circuit-public-calldata-hash branch from 615c7e2 to 8daacbe Compare May 4, 2023 06:51
@benesjan benesjan self-requested a review May 4, 2023 10:21
Copy link
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just went through the comments from Santiago and Sean and they mostly seem sufficiently addressed. Once you address my comments feel free to merge it.

kernel_data[1].public_inputs.end.new_commitments[i] = fr(i + 4 + 1);
std::vector<uint8_t> input_data = test_utils::utils::get_empty_calldata_leaf();

// Update commitment and nullifiers in kernels and testing byte array.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Update commitment and nullifiers in kernels and testing byte array.
// Update commitments and nullifiers in kernels and testing byte array.


// Update commitment and nullifiers in kernels and testing byte array.
// Commitments and nullifiers are 32 bytes long, so we can update them in the byte array by offsetting by 32 bytes
// for every insertion As there are two kernels in every leaf, nullifiers are offset by 8 elements (8*32) To insert
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// for every insertion As there are two kernels in every leaf, nullifiers are offset by 8 elements (8*32) To insert
// for every insertion. As there are two kernels in every leaf, nullifiers are offset by 8 elements (8*32). To insert

// Update commitment and nullifiers in kernels and testing byte array.
// Commitments and nullifiers are 32 bytes long, so we can update them in the byte array by offsetting by 32 bytes
// for every insertion As there are two kernels in every leaf, nullifiers are offset by 8 elements (8*32) To insert
// correctly, the insertions of values from the second kernel must be offset by 4*32 bytes (kernel_offset) Further
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// correctly, the insertions of values from the second kernel must be offset by 4*32 bytes (kernel_offset) Further
// correctly, the insertions of values from the second kernel must be offset by 4*32 bytes (kernel_offset). Further

@@ -183,7 +180,7 @@ TEST_F(root_rollup_tests, native_check_block_hashes_empty_blocks)
EXPECT_FALSE(composer.failed());

// Expected hash of public inputs for an empty L2 block. Also used in the contract tests.
fr const expected_hash = uint256_t("11840efc30e9fcbdd0aae30da2a5b441132420b4f0cc4ffd6bdc41888845f775");
fr const expected_hash = uint256_t("23f698e487c4e1b7383889f8864bc19591773d136c364c01d980bd13d0786ba1");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LHerskind please put there a comment that the value is from l2-block-publisher.test.ts

@LHerskind LHerskind marked this pull request as ready for review May 4, 2023 10:29
@LHerskind LHerskind merged commit 9abcbc9 into master May 4, 2023
@LHerskind LHerskind deleted the lh/circuit-public-calldata-hash branch May 4, 2023 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants