-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement SyscallHint storage_read (#68)
* Implemnet struct ContractStorageState * Add stuct StorageReadRequest * Add stuct StorageReadResponse * Implemet SyscallHandler::storage_read * Add STORAGE_READ to execute_syscall_hint * Add unfinished unit test * Add unit test test_os_storage_read_hint_ok * Add CachedState unit tests * Add RcRefCell CarriedState.parent_state: Option<Rc<RefCell<CarriedState<T>>>> * Modify State::get_contract_class * Add get_storage test * Add deploy_contract unit test * Modify contract_hash type from vec<u8> to [u8; 32] * Modify SyscallHandler._storage_read return type to Result<Felt,..> * Add State to BusinessLogicSyscallHandler * Remove StateComplete * Remove Storage generics in InMemoryStateReader * Implement Address.to_32_bytes() * Add test * Rename BusinessLogicSyscallHandler.starknet_storage to starknet_storage_state * Check inserts in unit test Co-authored-by: Pedro Fontana <pedro.fontana@lamdaclass.com>
- Loading branch information
Showing
12 changed files
with
333 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::collections::HashSet; | ||
|
||
use felt::Felt; | ||
use num_bigint::BigInt; | ||
|
||
use crate::{core::errors::state_errors::StateError, utils::Address}; | ||
|
||
use super::state_api::{State, StateReader}; | ||
|
||
pub(crate) struct ContractStorageState<T: State + StateReader> { | ||
pub(crate) state: T, | ||
pub(crate) contract_address: Address, | ||
/// Maintain all read request values in chronological order | ||
pub(crate) read_values: Vec<Felt>, | ||
pub(crate) accessed_keys: HashSet<[u8; 32]>, | ||
} | ||
|
||
impl<T: State + StateReader> ContractStorageState<T> { | ||
pub(crate) fn new(state: T, contract_address: Address) -> Self { | ||
Self { | ||
state, | ||
contract_address, | ||
read_values: Vec::new(), | ||
accessed_keys: HashSet::new(), | ||
} | ||
} | ||
|
||
pub(crate) fn read(&mut self, address: &[u8; 32]) -> Result<&Felt, StateError> { | ||
self.accessed_keys.insert(*address); | ||
let value = self | ||
.state | ||
.get_storage_at(&(self.contract_address.clone(), *address))?; | ||
|
||
self.read_values.push(value.clone()); | ||
Ok(value) | ||
} | ||
|
||
pub(crate) fn write(&mut self, address: &[u8; 32], value: Felt) { | ||
self.accessed_keys.insert(*address); | ||
self.state | ||
.set_storage_at(&(self.contract_address.clone(), *address), value); | ||
} | ||
} |
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
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
Oops, something went wrong.