Skip to content

Commit

Permalink
feat!: rename request_max_block_number (#5675)
Browse files Browse the repository at this point in the history
Follow up from #5490
  • Loading branch information
nventuro committed Apr 11, 2024
1 parent 8c1a7b9 commit c695fcd
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 15 additions & 2 deletions docs/docs/misc/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ impl<T, DELAY> SharedMutable<T, DELAY> {
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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,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);
Expand All @@ -547,7 +547,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
16 changes: 8 additions & 8 deletions yarn-project/end-to-end/src/e2e_max_block_number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ 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();
});
});

describe('with an enqueued public call', () => {
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();
});
});
});
Expand All @@ -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');
});
});
Expand All @@ -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');
});
});
Expand Down

0 comments on commit c695fcd

Please sign in to comment.