-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: split storage access oracles (#7237)
Part of #7230. This splits the storage access oracles that transpile into opcodes, and the ones that are resolved as actual oracle calls by PXE. I took the liberty to introduce some slight improvements, such as removing unused `length` params, write return values, and making the default fns call serialize and deserialize, mirroring the actual usage they had throughout our codebase and cleaning up the callsites. The oracle improvements proposed in #7230 (taking arbitrary addresses and block number) will come in a separate PR, as those require further changes to PXE etc.
- Loading branch information
Showing
12 changed files
with
98 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,43 @@ | ||
use dep::protocol_types::traits::{Deserialize, Serialize}; | ||
use dep::protocol_types::traits::Deserialize; | ||
|
||
#[oracle(storageRead)] | ||
unconstrained fn storage_read_oracle<N>(_storage_slot: Field, _number_of_elements: Field) -> [Field; N] {} | ||
unconstrained fn storage_read_oracle<N>(storage_slot: Field, length: Field) -> [Field; N] {} | ||
|
||
unconstrained fn storage_read_oracle_wrapper<N>(_storage_slot: Field) -> [Field; N] { | ||
storage_read_oracle(_storage_slot, N) | ||
unconstrained pub fn raw_storage_read<N>(storage_slot: Field) -> [Field; N] { | ||
storage_read_oracle(storage_slot, N) | ||
} | ||
|
||
pub fn storage_read<N>(storage_slot: Field) -> [Field; N] { | ||
storage_read_oracle_wrapper(storage_slot) | ||
unconstrained pub fn storage_read<T, N>(storage_slot: Field) -> T where T: Deserialize<N> { | ||
T::deserialize(raw_storage_read(storage_slot)) | ||
} | ||
|
||
#[oracle(storageWrite)] | ||
unconstrained fn storage_write_oracle<N>(_storage_slot: Field, _values: [Field; N]) -> [Field; N] {} | ||
mod tests { | ||
use crate::oracle::storage::{raw_storage_read, storage_read}; | ||
|
||
unconstrained pub fn storage_write<N>(storage_slot: Field, fields: [Field; N]) { | ||
let _hash = storage_write_oracle(storage_slot, fields); | ||
use std::test::OracleMock; | ||
use crate::test::mocks::mock_struct::MockStruct; | ||
|
||
#[test] | ||
fn test_raw_storage_read() { | ||
let slot = 7; | ||
let written = MockStruct { a: 13, b: 42 }; | ||
|
||
let _ = OracleMock::mock("storageRead").with_params((slot, 2)).returns(written.serialize()); | ||
|
||
let read: [Field; 2] = raw_storage_read(slot); | ||
assert_eq(read[0], 13); | ||
assert_eq(read[1], 42); | ||
} | ||
|
||
#[test] | ||
fn test_storage_read() { | ||
let slot = 7; | ||
let written = MockStruct { a: 13, b: 42 }; | ||
|
||
let _ = OracleMock::mock("storageRead").with_params((slot, 2)).returns(written.serialize()); | ||
|
||
let read: MockStruct = storage_read(slot); | ||
assert_eq(read.a, 13); | ||
assert_eq(read.b, 42); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/shared_mutable_private_getter.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters