From 1a6f0bbe91ef9fe5471066096fb1b025239ee5f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Wed, 10 Apr 2024 18:02:04 +0000 Subject: [PATCH] Rename request_max_block_number --- .../writing_contracts/functions/context.md | 2 +- docs/docs/misc/migration_notes.md | 17 +++++++++++++++-- .../aztec/src/context/private_context.nr | 2 +- .../state_vars/shared_mutable/shared_mutable.nr | 5 +++-- .../contracts/test_contract/src/main.nr | 6 ++---- .../src/private_kernel_init.nr | 2 +- .../src/private_kernel_inner.nr | 4 ++-- .../src/tests/private_call_data_builder.nr | 2 +- .../end-to-end/src/e2e_max_block_number.test.ts | 16 ++++++++-------- 9 files changed, 34 insertions(+), 22 deletions(-) diff --git a/docs/docs/developers/contracts/writing_contracts/functions/context.md b/docs/docs/developers/contracts/writing_contracts/functions/context.md index 3f38c5a2259..1bf93ed093f 100644 --- a/docs/docs/developers/contracts/writing_contracts/functions/context.md +++ b/docs/docs/developers/contracts/writing_contracts/functions/context.md @@ -96,7 +96,7 @@ The return values are a set of values that are returned from an applications exe ## Max Block Number -Some data structures impose time constraints, e.g. they may make it so that a value can only be changed after a certain delay. Interacting with these in private involves creating proofs that are only valid as long as they are included before a certain future point in time. To achieve this, the `request_max_block_number` function can be used to set this property: +Some data structures impose time constraints, e.g. they may make it so that a value can only be changed after a certain delay. Interacting with these in private involves creating proofs that are only valid as long as they are included before a certain future point in time. To achieve this, the `set_tx_max_block_number` function can be used to set this property: #include_code max-block-number /noir-projects/aztec-nr/aztec/src/context/private_context.nr rust diff --git a/docs/docs/misc/migration_notes.md b/docs/docs/misc/migration_notes.md index 9b6f7c8cef3..8f4f8b84217 100644 --- a/docs/docs/misc/migration_notes.md +++ b/docs/docs/misc/migration_notes.md @@ -6,6 +6,17 @@ keywords: [sandbox, cli, aztec, notes, migration, updating, upgrading] Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them. +## TBD + +### [Aztec.nr] Rename max block number setter + +The `request_max_block_number` function has been renamed to `set_tx_max_block_number` to better reflect that it is not a getter, and that the setting is transaction-wide. + +```diff +- context.request_max_block_number(value); ++ context.set_tx_max_block_number(value); +``` + ## 0.33 ### [Aztec.nr] Storage struct annotation @@ -52,6 +63,7 @@ Storage layout and note information are now exposed in the TS contract artifact ``` ### [Aztec.nr] rand oracle is now called unsafe_rand + `oracle::rand::rand` has been renamed to `oracle::unsafe_rand::unsafe_rand`. This change was made to communicate that we do not constrain the value in circuit and instead we just trust our PXE. @@ -61,9 +73,10 @@ This change was made to communicate that we do not constrain the value in circui ``` ### [AztecJS] Simulate and get return values for ANY call and introducing `prove()` + Historically it have been possible to "view" `unconstrained` functions to simulate them and get the return values, but not for `public` nor `private` functions. -This has lead to a lot of bad code where we have the same function implemented thrice, once in `private`, once in `public` and once in `unconstrained`. -It is not possible to call `simulate` on any call to get the return values! +This has lead to a lot of bad code where we have the same function implemented thrice, once in `private`, once in `public` and once in `unconstrained`. +It is not possible to call `simulate` on any call to get the return values! However, beware that it currently always returns a Field array of size 4 for private and public. This will change to become similar to the return values of the `unconstrained` functions with proper return types. diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index c3ec9a75604..4c7ff3d374c 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -193,7 +193,7 @@ impl PrivateContext { } // docs:start:max-block-number - pub fn request_max_block_number(&mut self, max_block_number: u32) { + pub fn set_tx_max_block_number(&mut self, max_block_number: u32) { // docs:end:max-block-number self.max_block_number = MaxBlockNumber::min_with_u32(self.max_block_number, max_block_number); } diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr index 8a795b43680..ac6f90b3d6c 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable.nr @@ -54,8 +54,9 @@ impl SharedMutable { let (scheduled_value_change, historical_block_number) = self.historical_read_from_public_storage(*context); let block_horizon = scheduled_value_change.get_block_horizon(historical_block_number); - // Prevent this transaction from being included in any block after the `block_horizon` - context.request_max_block_number(block_horizon); + // We prevent this transaction from being included in any block after the block horizon, ensuring that the + // historical public value matches the current one, since it can only change after the horizon. + context.set_tx_max_block_number(block_horizon); scheduled_value_change.get_current_at(historical_block_number) } diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index 01b05b9a2b6..bbe84101a71 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -68,10 +68,8 @@ contract Test { } #[aztec(private)] - fn request_max_block_number(max_block_number: u32, enqueue_public_call: bool) { - // docs:start:request-max-block-number - context.request_max_block_number(max_block_number); - // docs:end:request-max-block-number + fn set_tx_max_block_number(max_block_number: u32, enqueue_public_call: bool) { + context.set_tx_max_block_number(max_block_number); if enqueue_public_call { let _ = context.call_public_function( diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr index afbdb75445e..30098a39778 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr @@ -400,7 +400,7 @@ mod tests { #[test] fn propagate_max_block_number_request() { let mut builder = PrivateKernelInitInputsBuilder::new(); - builder.private_call.request_max_block_number(42); + builder.private_call.set_tx_max_block_number(42); let public_inputs = builder.execute(); assert_eq(public_inputs.validation_requests.for_rollup.max_block_number.unwrap(), 42); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr index 4faf0831bf9..70453b78eeb 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -546,7 +546,7 @@ mod tests { #[test] fn propagate_max_block_number_request() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - builder.private_call.request_max_block_number(42); + builder.private_call.set_tx_max_block_number(42); let public_inputs = builder.execute(); assert_eq(public_inputs.validation_requests.for_rollup.max_block_number.unwrap(), 42); @@ -558,7 +558,7 @@ mod tests { builder.previous_kernel.max_block_number = MaxBlockNumber::new(13); // A private call requesting a larger max_block_number should not change the current one as that constraint is // already satisfied. - builder.private_call.request_max_block_number(42); + builder.private_call.set_tx_max_block_number(42); let public_inputs = builder.execute(); assert_eq(public_inputs.validation_requests.for_rollup.max_block_number.unwrap(), 13); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr index a7e29d1554b..66a587f3d41 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_call_data_builder.nr @@ -139,7 +139,7 @@ impl PrivateCallDataBuilder { (hashes, call_requests) } - pub fn request_max_block_number(&mut self, max_block_number: u32) { + pub fn set_tx_max_block_number(&mut self, max_block_number: u32) { self.public_inputs.max_block_number = MaxBlockNumber::new(max_block_number); } diff --git a/yarn-project/end-to-end/src/e2e_max_block_number.test.ts b/yarn-project/end-to-end/src/e2e_max_block_number.test.ts index b7c78ff4dde..ed022b3acff 100644 --- a/yarn-project/end-to-end/src/e2e_max_block_number.test.ts +++ b/yarn-project/end-to-end/src/e2e_max_block_number.test.ts @@ -28,13 +28,13 @@ describe('e2e_max_block_number', () => { const enqueuePublicCall = false; it('sets the max block number', async () => { - const tx = await contract.methods.request_max_block_number(maxBlockNumber, enqueuePublicCall).simulate(); + const tx = await contract.methods.set_tx_max_block_number(maxBlockNumber, enqueuePublicCall).simulate(); expect(tx.data.rollupValidationRequests.maxBlockNumber.isSome).toEqual(true); expect(tx.data.rollupValidationRequests.maxBlockNumber.value).toEqual(new Fr(maxBlockNumber)); }); it('does not invalidate the transaction', async () => { - await contract.methods.request_max_block_number(maxBlockNumber, enqueuePublicCall).send().wait(); + await contract.methods.set_tx_max_block_number(maxBlockNumber, enqueuePublicCall).send().wait(); }); }); @@ -42,13 +42,13 @@ describe('e2e_max_block_number', () => { const enqueuePublicCall = true; it('sets the max block number', async () => { - const tx = await contract.methods.request_max_block_number(maxBlockNumber, enqueuePublicCall).simulate(); + const tx = await contract.methods.set_tx_max_block_number(maxBlockNumber, enqueuePublicCall).simulate(); expect(tx.data.rollupValidationRequests.maxBlockNumber.isSome).toEqual(true); expect(tx.data.rollupValidationRequests.maxBlockNumber.value).toEqual(new Fr(maxBlockNumber)); }); it('does not invalidate the transaction', async () => { - await contract.methods.request_max_block_number(maxBlockNumber, enqueuePublicCall).send().wait(); + await contract.methods.set_tx_max_block_number(maxBlockNumber, enqueuePublicCall).send().wait(); }); }); }); @@ -64,14 +64,14 @@ describe('e2e_max_block_number', () => { const enqueuePublicCall = false; it('sets the max block number', async () => { - const tx = await contract.methods.request_max_block_number(maxBlockNumber, enqueuePublicCall).simulate(); + const tx = await contract.methods.set_tx_max_block_number(maxBlockNumber, enqueuePublicCall).simulate(); expect(tx.data.rollupValidationRequests.maxBlockNumber.isSome).toEqual(true); expect(tx.data.rollupValidationRequests.maxBlockNumber.value).toEqual(new Fr(maxBlockNumber)); }); it('invalidates the transaction', async () => { await expect( - contract.methods.request_max_block_number(maxBlockNumber, enqueuePublicCall).send().wait(), + contract.methods.set_tx_max_block_number(maxBlockNumber, enqueuePublicCall).send().wait(), ).rejects.toThrow('dropped'); }); }); @@ -80,14 +80,14 @@ describe('e2e_max_block_number', () => { const enqueuePublicCall = true; it('sets the max block number', async () => { - const tx = await contract.methods.request_max_block_number(maxBlockNumber, enqueuePublicCall).simulate(); + const tx = await contract.methods.set_tx_max_block_number(maxBlockNumber, enqueuePublicCall).simulate(); expect(tx.data.rollupValidationRequests.maxBlockNumber.isSome).toEqual(true); expect(tx.data.rollupValidationRequests.maxBlockNumber.value).toEqual(new Fr(maxBlockNumber)); }); it('invalidates the transaction', async () => { await expect( - contract.methods.request_max_block_number(maxBlockNumber, enqueuePublicCall).send().wait(), + contract.methods.set_tx_max_block_number(maxBlockNumber, enqueuePublicCall).send().wait(), ).rejects.toThrow('dropped'); }); });