starkware-libs / cairo

Cairo is the first Turing-complete language for creating provable programs for general computation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Individual storage access

ArielElp opened this issue · comments

This feature allows reducing the number of actual storage accesses (system calls) that need to be performed to access individual struct members in storage.

Consider the following contract storage:

Struct MyStruct {
   a: usize,
   b: usize
}

#[storage]
struct Storage {
   my_struct: MyStruct
}

So far, to read the member "a" we had to perform two storage_read syscalls. With this feature we'll be able to write the following:

fn read_single_member(self: ContractState) {
   let a = self.my_struct.a().read() // the function `a` returns a new `StoragePointer` that represents a specific location in storage
}

If MyStruct contained specific types which are allowed in storage but do not implement the Store trait, such as Map:

Struct MyStruct {
   a: usize,
   b: usize,
   c: Map<usize, size>
}

Then we can never read MyStruct entirely. Accessing a or b will have to be done via the above.