Skip to content

Commit

Permalink
feat: TXE fixes to avm opcodes and missing oracles, forced ci failure…
Browse files Browse the repository at this point in the history
… (#7252)

Makes CI fail in case TXE test fail. Noticed they were broken, but
master was still green and removed some unnecessary commands in the
docker build.

Also reverted some of the changes from
AztecProtocol/aztec-packages#7237 since we need
the length of the data we're about to read in `avmOpcodeStorageRead`
(the oracle cannot obtain this information from the assigned output
variable.
  • Loading branch information
Thunkar authored and AztecBot committed Jul 3, 2024
1 parent d2b5ea6 commit 102def9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
4 changes: 2 additions & 2 deletions aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ unconstrained fn call_static<RET_SIZE>(
}

unconstrained fn storage_read<N>(storage_slot: Field) -> [Field; N] {
storage_read_opcode(storage_slot)
storage_read_opcode(storage_slot, N)
}

unconstrained fn storage_write<N>(storage_slot: Field, values: [Field; N]) {
Expand Down Expand Up @@ -373,7 +373,7 @@ unconstrained fn call_static_opcode<RET_SIZE>(
// ^ return data ^ success

#[oracle(avmOpcodeStorageRead)]
unconstrained fn storage_read_opcode<N>(storage_slot: Field) -> [Field; N] {}
unconstrained fn storage_read_opcode<N>(storage_slot: Field, length: Field) -> [Field; N] {}

#[oracle(avmOpcodeStorageWrite)]
unconstrained fn storage_write_opcode<N>(storage_slot: Field, values: [Field; N]) {}
Expand Down
24 changes: 20 additions & 4 deletions aztec/src/state_vars/shared_mutable/test.nr
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,11 @@ fn test_get_current_value_in_private_bad_value_hints() {
let private_state_var = in_private(&mut env, schedule_block_number);

let mocked: ScheduledValueChange<Field> = ScheduledValueChange::new(0, new_value + 1, schedule_block_number);
let _ = OracleMock::mock("storageRead").with_params((private_state_var.get_value_change_storage_slot(), 3)).returns(mocked.serialize()).times(1);
let _ = OracleMock::mock("storageRead").with_params(
(
env.contract_address().to_field(), private_state_var.get_value_change_storage_slot(), schedule_block_number, 3
)
).returns(mocked.serialize()).times(1);

let _ = private_state_var.get_current_value_in_private();
}
Expand All @@ -291,7 +295,11 @@ fn test_get_current_value_in_private_bad_delay_hints() {
let private_state_var = in_private(&mut env, schedule_block_number);

let mocked: ScheduledDelayChange<TEST_INITIAL_DELAY> = ScheduledDelayChange::new(Option::none(), Option::some(42), schedule_block_number);
let _ = OracleMock::mock("storageRead").with_params((private_state_var.get_delay_change_storage_slot(), 1)).returns(mocked.serialize()).times(1);
let _ = OracleMock::mock("storageRead").with_params(
(
env.contract_address().to_field(), private_state_var.get_delay_change_storage_slot(), schedule_block_number, 1
)
).returns(mocked.serialize()).times(1);

let _ = private_state_var.get_current_value_in_private();
}
Expand All @@ -304,7 +312,11 @@ fn test_get_current_value_in_private_bad_zero_hash_value_hints() {
let state_var = in_private(&mut env, historical_block_number);

let mocked: ScheduledValueChange<Field> = ScheduledValueChange::new(0, new_value, 0);
let _ = OracleMock::mock("storageRead").with_params((state_var.get_value_change_storage_slot(), 3)).returns(mocked.serialize()).times(1);
let _ = OracleMock::mock("storageRead").with_params(
(
env.contract_address().to_field(), state_var.get_value_change_storage_slot(), historical_block_number, 3
)
).returns(mocked.serialize()).times(1);

let _ = state_var.get_current_value_in_private();
}
Expand All @@ -317,7 +329,11 @@ fn test_get_current_value_in_private_bad_zero_hash_delay_hints() {
let state_var = in_private(&mut env, historical_block_number);

let mocked: ScheduledDelayChange<TEST_INITIAL_DELAY> = ScheduledDelayChange::new(Option::none(), Option::some(new_delay), 0);
let _ = OracleMock::mock("storageRead").with_params((state_var.get_delay_change_storage_slot(), 1)).returns(mocked.serialize()).times(1);
let _ = OracleMock::mock("storageRead").with_params(
(
env.contract_address().to_field(), state_var.get_delay_change_storage_slot(), historical_block_number, 1
)
).returns(mocked.serialize()).times(1);

let _ = state_var.get_current_value_in_private();
}
13 changes: 13 additions & 0 deletions aztec/src/test/helpers/cheatcodes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ unconstrained pub fn add_note_hashes(contractAddress: AztecAddress, inner_note_h
oracle_add_note_hashes(contractAddress, inner_note_hashes)
}

unconstrained pub fn get_function_selector() -> FunctionSelector {
oracle_get_function_selector()
}

unconstrained pub fn set_fn_selector(selector: FunctionSelector) {
oracle_set_function_selector(selector)
}

#[oracle(reset)]
fn oracle_reset() {}

Expand Down Expand Up @@ -181,3 +189,8 @@ fn oracle_add_nullifiers(contractAddress: AztecAddress, nullifiers: [Field]) {}
#[oracle(addNoteHashes)]
fn oracle_add_note_hashes(contractAddress: AztecAddress, inner_note_hashes: [Field]) {}

#[oracle(getFunctionSelector)]
fn oracle_get_function_selector() -> FunctionSelector {}

#[oracle(setFunctionSelector)]
fn oracle_set_function_selector(selector: FunctionSelector) {}
11 changes: 10 additions & 1 deletion aztec/src/test/helpers/test_environment.nr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ impl TestEnvironment {
cheatcodes::get_block_number()
}

fn contract_address(self) -> AztecAddress {
cheatcodes::get_contract_address()
}

fn advance_block_to(&mut self, block_number: u32) {
let difference = block_number - cheatcodes::get_block_number();
self.advance_block_by(difference);
Expand All @@ -40,7 +44,8 @@ impl TestEnvironment {
}

fn public(self) -> PublicContext {
PublicContext::empty()
let mut inputs = cheatcodes::get_public_context_inputs();
PublicContext::new(inputs)
}

fn private(&mut self) -> PrivateContext {
Expand Down Expand Up @@ -159,15 +164,19 @@ impl TestEnvironment {
let original_fn = call_interface.get_original();
let original_msg_sender = cheatcodes::get_msg_sender();
let original_contract_address = cheatcodes::get_contract_address();
let original_fn_selector = cheatcodes::get_function_selector();
let target_address = call_interface.get_contract_address();
let fn_selector = call_interface.get_selector();

cheatcodes::set_fn_selector(fn_selector);
cheatcodes::set_contract_address(target_address);
cheatcodes::set_msg_sender(original_contract_address);
let mut inputs = cheatcodes::get_public_context_inputs();
inputs.args_hash = hash_args(call_interface.get_args());
inputs.is_static_call = call_interface.get_is_static();
let result = original_fn(inputs);

cheatcodes::set_fn_selector(original_fn_selector);
cheatcodes::set_contract_address(original_contract_address);
cheatcodes::set_msg_sender(original_msg_sender);
result
Expand Down
3 changes: 3 additions & 0 deletions aztec/src/test/helpers/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@ impl<N> Deployer<N> {
let original_fn = call_interface.get_original();
let original_msg_sender = cheatcodes::get_msg_sender();
let original_contract_address = cheatcodes::get_contract_address();
let original_fn_selector = cheatcodes::get_function_selector();

cheatcodes::set_fn_selector(call_interface.get_selector());
cheatcodes::set_contract_address(instance.to_address());
cheatcodes::set_msg_sender(original_contract_address);
let mut inputs = cheatcodes::get_public_context_inputs();
inputs.args_hash = hash_args(call_interface.get_args());
let _result: T = original_fn(inputs);

cheatcodes::set_fn_selector(original_fn_selector);
cheatcodes::set_contract_address(original_contract_address);
cheatcodes::set_msg_sender(original_msg_sender);
instance
Expand Down

0 comments on commit 102def9

Please sign in to comment.