From de11d6538a9922412853c394c0421b40bd8fc423 Mon Sep 17 00:00:00 2001 From: superstar0402 Date: Wed, 6 Mar 2024 18:43:11 +0000 Subject: [PATCH] feat(avm): storage (#4673) ## Overview Works around brillig blowup issue by altering the read and write opcodes to take in arrays of data. This is potentially just a short term fix. - Reading and writing to storage now take in arrays, code will not compile without this change, due to an ssa issue ->[ ISSUE ](https://github.com/AztecProtocol/aztec-packages/issues/4979) - Tag checks on memory now just make sure the tag is LESS than uint64, rather than asserting that the memory tag is uint32, this should be fine. - We had to blow up the memory space of the avm to u64 as the entire noir compiler works with u64s. Arrays will not work unless we either - Make the avm 64 bit addressable ( probably fine ) - Make noir 32 bit addressable ( requires alot of buy in ) https://github.com/AztecProtocol/aztec-packages/pull/4814 --------- Co-authored-by: sirasistant --- aztec/src/context.nr | 11 ++++++++--- aztec/src/oracle/storage.nr | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/aztec/src/context.nr b/aztec/src/context.nr index 09162c6..9f5ae7e 100644 --- a/aztec/src/context.nr +++ b/aztec/src/context.nr @@ -14,18 +14,23 @@ use avm::AVMContext; struct Context { private: Option<&mut PrivateContext>, public: Option<&mut PublicContext>, + public_vm: Option<&mut AVMContext>, } impl Context { pub fn private(context: &mut PrivateContext) -> Context { - Context { private: Option::some(context), public: Option::none() } + Context { private: Option::some(context), public: Option::none(), public_vm: Option::none() } } pub fn public(context: &mut PublicContext) -> Context { - Context { public: Option::some(context), private: Option::none() } + Context { public: Option::some(context), private: Option::none(), public_vm: Option::none() } + } + + pub fn public_vm(context: &mut AVMContext) -> Context { + Context { public_vm: Option::some(context), public: Option::none(), private: Option::none() } } pub fn none() -> Context { - Context { public: Option::none(), private: Option::none() } + Context { public: Option::none(), private: Option::none(), public_vm: Option::none() } } } diff --git a/aztec/src/oracle/storage.nr b/aztec/src/oracle/storage.nr index 72bec83..ad9b148 100644 --- a/aztec/src/oracle/storage.nr +++ b/aztec/src/oracle/storage.nr @@ -12,8 +12,8 @@ pub fn storage_read(storage_slot: Field) -> [Field; N] { } #[oracle(storageWrite)] -fn storage_write_oracle(_storage_slot: Field, _values: [Field; N]) -> [Field; N] {} +fn storage_write_oracle(_storage_slot: Field, _values: [Field; N]) -> Field {} unconstrained pub fn storage_write(storage_slot: Field, fields: [Field; N]) { - let _hash = storage_write_oracle(storage_slot, fields); + let _ = storage_write_oracle(storage_slot, fields); }