-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Overview
The opcodes that return the size of code associated with codes needs to be optimised. This is because the code which is loaded from the database needs to be authenticated / constrained via hashing. Instead scroll implements an optimisation in which the code size is stored within the account data structure. My proposal would be to make use of the ExternalContext to store this information. Alternatively we could keep a cache of this information in the database data structure and whenever we load an account from the state trie we populate the code info object with the information.
Design
A proposed design of the cache that would store this data looks as follows:
type KeccakCodeHash = B256;
type PoseidenCodeHash = B256;
type CodeSize = usize;
pub struct ScrollCodeInfo {
inner: HashMap<KeccakCodeHash, (PoseidenCodeHash, CodeSize)>,
}
impl ScrollCodeInfo {
pub fn new(
scroll_account_info: impl Iterator<Item = (KeccakCodeHash, PoseidenCodeHash, CodeSize)>,
) -> Self {
Self {
inner: scroll_account_info.collect(),
}
}
pub fn code_size(&self, keccak_code_hash: &KeccakCodeHash) -> Option<CodeSize> {
self.inner.get(keccak_code_hash).map(|(_, size)| *size)
}
pub fn poseiden_code_hash(
&self,
keccak_code_hash: &KeccakCodeHash,
) -> Option<PoseidenCodeHash> {
self.inner
.get(keccak_code_hash)
.map(|(poseiden_code_hash, _)| *poseiden_code_hash)
}
pub fn insert(
&mut self,
keccak_code_hash: KeccakCodeHash,
poseiden_code_hash: PoseidenCodeHash,
code_size: CodeSize,
) {
self.inner
.insert(keccak_code_hash, (poseiden_code_hash, code_size));
}
}Metadata
Metadata
Assignees
Labels
No labels