Skip to content

code size opcodes #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
frisitano opened this issue Oct 2, 2024 · 0 comments
Open

code size opcodes #11

frisitano opened this issue Oct 2, 2024 · 0 comments

Comments

@frisitano
Copy link
Collaborator

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));
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant