Skip to content

fix execution result incorrectly collecting logs when building tx#979

Merged
rahul-kothari merged 2 commits into
masterfrom
rk/fix_callstackcollection
Jul 7, 2023
Merged

fix execution result incorrectly collecting logs when building tx#979
rahul-kothari merged 2 commits into
masterfrom
rk/fix_callstackcollection

Conversation

@rahul-kothari

@rahul-kothari rahul-kothari commented Jul 6, 2023

Copy link
Copy Markdown
Contributor

Description

When Noir calls multiple child contract functions (say child1 followed by child2), the circuit and ACVM uses a call stack so it first executes child2 followed by child1. Same happens when creating the calldata hash (especially when collecting logs and hashing them all).

Whereas in TS, when we are collecting logs to build the TX object (for sending it to sequencer), it did a flatMap which collected child1 first rather than child2 i.e. it did a queue rather than a stack like thing. This resulted in a mismatch between the circuit's calldata hash AND the L2Block's getCalldataHash() which is checked before publishing block on L1.

Thanks to @suyash67 and @jeanmon for sticking it out with me for debugging this. S/O also to @sirasistant who made it easier to spot this.

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.

@spalladino spalladino left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add a test that reproduces this one, so we don't accidentally get bit by it again?

std::array<uint8_t, num_bytes> calldata_hash_inputs_bytes;
// Convert all into a buffer, then copy into the array, then hash
for (size_t i = 0; i < calldata_hash_inputs.size() - 4; i++) { // -4 because logs are processed out of the loop
for (size_t i = 0; i < calldata_hash_inputs.size() - 8; i++) { // -8 because logs are processed out of the loop

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why was this change needed? Change in the number of logs emitted per tx? If so, should it be related to a constant?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I submitted a new commit with additional comments and used the constant NUM_FIELDS_PER_SHA256 wherever it made sense to me.

@jeanmon

jeanmon commented Jul 7, 2023

Copy link
Copy Markdown
Contributor

Should we add a test that reproduces this one, so we don't accidentally get bit by it again?

@spalladino absolutely! I think that after the hackaton we will add e2e test which captures this. Right @rahul-kothari ?

@rahul-kothari

Copy link
Copy Markdown
Contributor Author

@spalladino #987 - will do it next sprint

@rahul-kothari rahul-kothari merged commit 5adf419 into master Jul 7, 2023
@rahul-kothari rahul-kothari deleted the rk/fix_callstackcollection branch July 7, 2023 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants