Skip to content

refactor!: nuking NoteHeader#11942

Merged
benesjan merged 5 commits into
masterfrom
02-12-refactor_removing_noteheader_out_of_note
Feb 18, 2025
Merged

refactor!: nuking NoteHeader#11942
benesjan merged 5 commits into
masterfrom
02-12-refactor_removing_noteheader_out_of_note

Conversation

@benesjan

@benesjan benesjan commented Feb 12, 2025

Copy link
Copy Markdown
Contributor

Fixes #11860
Fixes #11861

benesjan commented Feb 12, 2025

Copy link
Copy Markdown
Contributor Author

@benesjan benesjan force-pushed the 02-12-refactor_removing_noteheader_out_of_note branch from 5bc7d98 to d2bafea Compare February 12, 2025 14:05
@benesjan benesjan marked this pull request as ready for review February 12, 2025 16:26
@github-actions

github-actions Bot commented Feb 12, 2025

Copy link
Copy Markdown
Contributor

Changes to public function bytecode sizes

Generated at commit: 00dc4ac93a0efd7d07c8e79427700b30898599df, compared to commit: 5efdd57c2c19daed3bb5d60fff915e9618b4a146

🧾 Summary (100% most significant diffs)

Program Bytecode size in bytes (+/-) %
AvmGadgetsTest::keccak_hash +106 ❌ +4.89%
Test::consume_message_from_arbitrary_sender_public +282 ❌ +3.76%
AvmGadgetsTest::sha256_hash_10 +112 ❌ +3.38%
AvmGadgetsTest::sha256_hash_20 +112 ❌ +3.32%
AvmGadgetsTest::sha256_hash_30 +112 ❌ +3.24%
AvmGadgetsTest::sha256_hash_40 +112 ❌ +3.19%
AvmGadgetsTest::sha256_hash_50 +112 ❌ +3.11%
Test::consume_mint_to_public_message +318 ❌ +3.02%
AvmGadgetsTest::sha256_hash_60 +112 ❌ +3.01%
AvmTest::u128_addition_overflow +36 ❌ +2.84%
AvmGadgetsTest::sha256_hash_256 +156 ❌ +2.61%
TokenBridge::claim_public +318 ❌ +2.57%
AvmGadgetsTest::sha256_hash_255 +156 ❌ +2.56%
AvmGadgetsTest::sha256_hash_70 +112 ❌ +2.46%
AvmGadgetsTest::sha256_hash_80 +112 ❌ +2.42%
AvmGadgetsTest::sha256_hash_90 +112 ❌ +2.38%
TokenBridge::exit_to_l1_public +184 ❌ +2.36%
AvmGadgetsTest::sha256_hash_100 +112 ❌ +2.35%
Uniswap::swap_public +341 ❌ +2.31%
AvmGadgetsTest::sha256_hash_512 +156 ❌ +2.01%
AvmGadgetsTest::sha256_hash_511 +156 ❌ +1.98%
TokenBridge::public_dispatch +372 ❌ +1.81%
Test::public_dispatch +318 ❌ +1.75%
Uniswap::public_dispatch +359 ❌ +1.50%
DocsExample::public_dispatch +64 ❌ +1.32%
AvmTest::bulk_testing +218 ❌ +0.99%
NFT::constructor +41 ❌ +0.91%
AvmGadgetsTest::public_dispatch +420 ❌ +0.88%
Token::constructor +41 ❌ +0.85%
AvmGadgetsTest::sha256_hash_2048 +156 ❌ +0.84%
AvmTest::emit_public_log +18 ❌ +0.76%
AppSubscription::constructor +23 ❌ +0.65%
AvmTest::external_call_to_divide_by_zero_recovers +18 ❌ +0.64%
Token::transfer_in_public +23 ❌ +0.53%
Parent::public_nested_static_call +18 ❌ +0.51%
AppSubscription::public_dispatch +23 ❌ +0.49%
AvmTest::public_dispatch +254 ❌ +0.44%
NFT::finalize_transfer_to_private +18 ❌ +0.39%
NFT::_finalize_transfer_to_private_unsafe +18 ❌ +0.39%
Token::finalize_mint_to_private +18 ❌ +0.38%
Token::_finalize_mint_to_private_unsafe +18 ❌ +0.37%
Token::finalize_transfer_to_private +18 ❌ +0.35%
Token::_finalize_transfer_to_private_unsafe +18 ❌ +0.35%
Token::public_dispatch +105 ❌ +0.33%
NFT::public_dispatch +82 ❌ +0.32%
Uniswap::_approve_bridge_and_exit_input_asset_to_L1 +18 ❌ +0.27%
Parent::public_dispatch +18 ❌ +0.24%
TokenBlacklist::shield -5 ✅ -0.09%
TokenBlacklist::mint_private -5 ✅ -0.14%
TokenBlacklist::public_dispatch -210 ✅ -0.88%

Full diff report 👇
Program Bytecode size in bytes (+/-) %
AvmGadgetsTest::keccak_hash 2,275 (+106) +4.89%
Test::consume_message_from_arbitrary_sender_public 7,780 (+282) +3.76%
AvmGadgetsTest::sha256_hash_10 3,429 (+112) +3.38%
AvmGadgetsTest::sha256_hash_20 3,482 (+112) +3.32%
AvmGadgetsTest::sha256_hash_30 3,571 (+112) +3.24%
AvmGadgetsTest::sha256_hash_40 3,622 (+112) +3.19%
AvmGadgetsTest::sha256_hash_50 3,716 (+112) +3.11%
Test::consume_mint_to_public_message 10,852 (+318) +3.02%
AvmGadgetsTest::sha256_hash_60 3,829 (+112) +3.01%
AvmTest::u128_addition_overflow 1,302 (+36) +2.84%
AvmGadgetsTest::sha256_hash_256 6,130 (+156) +2.61%
TokenBridge::claim_public 12,711 (+318) +2.57%
AvmGadgetsTest::sha256_hash_255 6,238 (+156) +2.56%
AvmGadgetsTest::sha256_hash_70 4,669 (+112) +2.46%
AvmGadgetsTest::sha256_hash_80 4,739 (+112) +2.42%
AvmGadgetsTest::sha256_hash_90 4,809 (+112) +2.38%
TokenBridge::exit_to_l1_public 7,986 (+184) +2.36%
AvmGadgetsTest::sha256_hash_100 4,879 (+112) +2.35%
Uniswap::swap_public 15,084 (+341) +2.31%
AvmGadgetsTest::sha256_hash_512 7,916 (+156) +2.01%
AvmGadgetsTest::sha256_hash_511 8,042 (+156) +1.98%
TokenBridge::public_dispatch 20,907 (+372) +1.81%
Test::public_dispatch 18,464 (+318) +1.75%
Uniswap::public_dispatch 24,274 (+359) +1.50%
DocsExample::public_dispatch 4,925 (+64) +1.32%
AvmTest::bulk_testing 22,138 (+218) +0.99%
NFT::constructor 4,538 (+41) +0.91%
AvmGadgetsTest::public_dispatch 48,084 (+420) +0.88%
Token::constructor 4,847 (+41) +0.85%
AvmGadgetsTest::sha256_hash_2048 18,673 (+156) +0.84%
AvmTest::emit_public_log 2,390 (+18) +0.76%
AppSubscription::constructor 3,587 (+23) +0.65%
AvmTest::external_call_to_divide_by_zero_recovers 2,828 (+18) +0.64%
Token::transfer_in_public 4,351 (+23) +0.53%
Parent::public_nested_static_call 3,514 (+18) +0.51%
AppSubscription::public_dispatch 4,731 (+23) +0.49%
AvmTest::public_dispatch 58,583 (+254) +0.44%
NFT::finalize_transfer_to_private 4,606 (+18) +0.39%
NFT::_finalize_transfer_to_private_unsafe 4,653 (+18) +0.39%
Token::finalize_mint_to_private 4,805 (+18) +0.38%
Token::_finalize_mint_to_private_unsafe 4,852 (+18) +0.37%
Token::finalize_transfer_to_private 5,131 (+18) +0.35%
Token::_finalize_transfer_to_private_unsafe 5,178 (+18) +0.35%
Token::public_dispatch 32,282 (+105) +0.33%
NFT::public_dispatch 25,467 (+82) +0.32%
Uniswap::_approve_bridge_and_exit_input_asset_to_L1 6,617 (+18) +0.27%
Parent::public_dispatch 7,637 (+18) +0.24%
TokenBlacklist::shield 5,581 (-5) -0.09%
TokenBlacklist::mint_private 3,520 (-5) -0.14%
TokenBlacklist::public_dispatch 23,579 (-210) -0.88%

@benesjan benesjan marked this pull request as draft February 13, 2025 07:21
@benesjan benesjan changed the title refactor: removing NoteHeader out of note refactor: removing NoteHeader out of note Feb 13, 2025
@benesjan benesjan marked this pull request as ready for review February 13, 2025 09:21
Base automatically changed from 02-11-refactor_moving_storage_slot_out_of_noteheader to master February 13, 2025 10:00
@benesjan benesjan marked this pull request as draft February 13, 2025 10:03
@benesjan benesjan force-pushed the 02-12-refactor_removing_noteheader_out_of_note branch 2 times, most recently from 8a8bb1f to a722a93 Compare February 13, 2025 10:06
@benesjan benesjan changed the title refactor: removing NoteHeader out of note refactor: nuking NoteHeader Feb 13, 2025
@benesjan benesjan marked this pull request as ready for review February 13, 2025 13:11
Comment thread noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr
Comment thread noir-projects/aztec-nr/aztec/src/note/lifecycle.nr
Comment thread boxes/boxes/react/src/contracts/src/main.nr
Comment thread boxes/boxes/vanilla/src/contracts/src/main.nr
Comment thread noir-projects/aztec-nr/address-note/src/address_note.nr
@github-actions

github-actions Bot commented Feb 13, 2025

Copy link
Copy Markdown
Contributor

Changes to circuit sizes

Generated at commit: 00dc4ac93a0efd7d07c8e79427700b30898599df, compared to commit: 5efdd57c2c19daed3bb5d60fff915e9618b4a146

🧾 Summary (100% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
rollup_base_public +120,592 ❌ +140.07% +370,468 ❌ +31.68%
rollup_block_merge +24,164 ❌ +362.50% +84,229 ❌ +5.27%
rollup_root +24,164 ❌ +363.37% +84,229 ❌ +0.31%
rollup_base_private +6 ❌ +0.00% +590 ❌ +0.04%
private_kernel_inner -179 ✅ -0.63% -446 ✅ -0.61%
private_kernel_init -179 ✅ -0.95% -446 ✅ -1.11%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
rollup_base_public 206,684 (+120,592) +140.07% 1,540,029 (+370,468) +31.68%
rollup_block_merge 30,830 (+24,164) +362.50% 1,683,390 (+84,229) +5.27%
rollup_root 30,814 (+24,164) +363.37% 26,939,539 (+84,229) +0.31%
rollup_base_private 137,836 (+6) +0.00% 1,637,949 (+590) +0.04%
private_kernel_inner 28,367 (-179) -0.63% 72,233 (-446) -0.61%
private_kernel_init 18,679 (-179) -0.95% 39,846 (-446) -1.11%

Comment thread noir-projects/aztec-nr/aztec/src/macros/events/mod.nr
Comment thread noir-projects/aztec-nr/aztec/src/note/note_emission.nr
Comment thread noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr
Comment thread noir-projects/noir-contracts/contracts/claim_contract/Nargo.toml
Comment thread noir-projects/noir-contracts/contracts/claim_contract/src/main.nr
Comment thread yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts
Comment thread noir-projects/noir-protocol-circuits/crates/types/src/meta/mod.nr
Comment thread noir-projects/noir-protocol-circuits/crates/types/src/meta/mod.nr
Comment thread yarn-project/end-to-end/src/e2e_state_vars.test.ts
@benesjan benesjan changed the title refactor: nuking NoteHeader refactor!: nuking NoteHeader Feb 14, 2025
@benesjan benesjan force-pushed the 02-12-refactor_removing_noteheader_out_of_note branch from aafc224 to 14eb329 Compare February 17, 2025 09:49
@nventuro nventuro self-requested a review February 17, 2025 17:55

@nventuro nventuro 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.

Thanks for tackling this! Left a bunch of comments on questions asked, vague thoughts on future things we'll do, and some observations.

In general please do try to keep things a bit tidier and split across saner changesets. The number of files involved here is massive, as is the linecount, but the vast majority of the changes are trivial, e.g. renaming note to retrieved_note, or T to NOTE in balance_set. However the changes that are not trivial are hidden among those and require careful thinking - it's quite easy to miss these important changes given the noise.

I suggest you go through the diff yourself when submitting as if you were the reviewer, and trying to think if it's easy to spot the things you want for the reader to look at and comment on, or if there's things that could be clarified or removed.

Comment thread noir-projects/aztec-nr/aztec/src/note/retrieved_note.nr
Comment on lines +3 to +10
/// A container of a note and its metadata. Metadata is needed to constrain the note when reading the note from
/// an unconstrained context and to compute the nullifier when destroying a note.
pub struct RetrievedNote<NOTE> {
pub note: NOTE,
pub contract_address: AztecAddress,
pub nonce: Field,
pub note_hash_counter: u32, // a note_hash_counter of 0 means non-transient
}

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 find this name very confusing - at first I thought RetrievedNote meant that you had actually applied constraints and checked that the note exists, but this is just the old note + header struct. This makes sense in terms of the approach I suggested in #11860 (what I called NoteWithData), but the name is quite inapropriate given the direction we're taking (e.g. the other items mentioned in that issue, plus #8589).

I imagine it'd be unlikely for a user to run into this type - the oracle might return this, but there's then two layers of encapsulation:

  • aztec.nr/notes dealing with constraining and returning a proper struct that indicates the note exists
  • the state variable doing things with the read note (e.g. replacing it, removing it, unwrapping it)

Given this I think it's fine to have a descriptive un-sexy name, like NoteWithMetadata or whatever.

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.

Your docs actually start with A container of a note and its metadata. 😛

@benesjan benesjan Feb 18, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Given this I think it's fine to have a descriptive un-sexy name, like NoteWithMetadata or whatever.

I don't really see a difference between RetrievedNote and NoteWithMetadata. Both don't tell me much and I need to open the struct definition to see what that is. Can we just merge this and come up with a nicer name later? I see both as only a temporary placeholder.

@nventuro nventuro Feb 18, 2025

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.

The difference I had in mind was one between a user-facing name and something more internal, but I wasn't actually suggesting that we rename this now, more rambling and gathering my thoughts as I went through the review. I agree the rename can wait, sorry I did not clarify that earlier.

Comment on lines +87 to +93
// TODO: For non-transient notes, the contract address appears to be implicitly checked since we return a siloed
// note hash from the `compute_note_hash_for_read_request(...)` function. Investigate whether this check is needed
// for transient notes and if not, remove it.
assert(
retrieved_note.contract_address.eq(context.this_address()),
"Note contract address mismatch.",
);

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.

This check is almost free anyway, it'd cost more constraints to test if the note is transient and then conditionally do it.

@benesjan benesjan Feb 18, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just wanted a verification from the reviewer that the check is here really only for transient notes. Based on your reaction I see it's the case and I've updated the comment in this commit. LMK if it looks good to you. (will try to not mess the commit link with graphite 😝).

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.

The new comment is fantastic thanks!

Comment thread noir-projects/aztec-nr/aztec/src/note/retrieved_note.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr Outdated
Comment thread noir-projects/noir-contracts/contracts/claim_contract/src/main.nr
Comment thread noir-projects/noir-contracts/contracts/claim_contract/src/main.nr
@benesjan benesjan force-pushed the 02-12-refactor_removing_noteheader_out_of_note branch from edd3cac to b6aa786 Compare February 18, 2025 08:15
@benesjan benesjan marked this pull request as draft February 18, 2025 08:16
@benesjan benesjan marked this pull request as ready for review February 18, 2025 09:26
@benesjan benesjan requested a review from nventuro February 18, 2025 11:17
@benesjan benesjan merged commit 477dc35 into master Feb 18, 2025
@benesjan benesjan deleted the 02-12-refactor_removing_noteheader_out_of_note branch February 18, 2025 14:06
TomAFrench added a commit that referenced this pull request Feb 19, 2025
* master: (245 commits)
  chore: Fix unbound CI variable on release image bootstrap (#12095)
  fix: dry run on grind (#12088)
  fix(spartan): eth-execution logging (#12094)
  fix: aws_handle_evict recovery & termination (#12086)
  chore: Use native acvm when available on orchestrator tests (#11560)
  refactor: function macros cleanup (#12066)
  refactor: remove `addNullifiedNote` from pxe (#11822)
  fix: `#[aztec]` macro warnings (#12038)
  refactor!: Notes implementing `Packable<N>` (#12004)
  chore(ops): add gcloud cli into devbox base image (#12082)
  fix: hotfix grinding
  fix: L1 deployment on reth (#12060)
  fix: Add missing bootstrap fast aliases (#12078)
  fix: hash_str caching (#12074)
  fix: Naive attempt to fix nightly deployments (#12079)
  fix: kind smoke (#12084)
  refactor!: nuking `NoteHeader` (#11942)
  fix: inject dockerhub creds (#12072)
  feat(docs): Note discovery concepts page (#11760)
  chore: cleanup libp2p logger (#12058)
  ...
nventuro added a commit that referenced this pull request Feb 25, 2025
Follow up to #11942.
This improves the readability and management of code that reads and
destroys notes by introducing the `NoteMetadata` struct, which handles
the different combinations of note hash counter and nonce internally.
This is a stepping stone towards #8589.
AztecBot pushed a commit to AztecProtocol/aztec-nr that referenced this pull request Feb 26, 2025
Follow up to AztecProtocol/aztec-packages#11942.
This improves the readability and management of code that reads and
destroys notes by introducing the `NoteMetadata` struct, which handles
the different combinations of note hash counter and nonce internally.
This is a stepping stone towards #8589.
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.

Simplify note macros Remove header from notes

3 participants