Skip to content
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

Make getContractStorage not throw if the account does not exist #3479

Closed
jochem-brouwer opened this issue Jul 1, 2024 · 0 comments · Fixed by #3536
Closed

Make getContractStorage not throw if the account does not exist #3479

jochem-brouwer opened this issue Jul 1, 2024 · 0 comments · Fixed by #3536

Comments

@jochem-brouwer
Copy link
Member

Currently in the DefaultStateManager once getContractStorage gets called on a non-existing account, the function throws getContractStorage() called on non-existing account. This is inconsistent with the other state managers (RPC does not throw, and Verkle also does not seem to throw). Also, getAccount does return undefined if it does not exist (and an empty account if the account exists).

There are only some calls to getContractStorage, the first is in DefaultStateManager which gets proof items. This has commented out that it should throw for non-existing accounts:

async getProof(address: Address, storageSlots: Uint8Array[] = []): Promise<Proof> {
await this.flush()
const account = await this.getAccount(address)
if (!account) {
// throw new Error(`getProof() can only be called for an existing account`)
const returnValue: Proof = {
. The other is in EVMs interpreter, which gets storage
async storageLoad(key: Uint8Array, original = false): Promise<Uint8Array> {
if (original) {
return this._stateManager.originalStorageCache.get(this._env.address, key)
} else {
return this._stateManager.getContractStorage(this._env.address, key)
}
}
. Since it is currently not possible to load storage (SLOAD) from other accounts, the account is thus guaranteed to exist. The BLOCKHASH opcode calls into the EIP 2935 history address and would thus throw if this address does not exist, but this is an edge case and no chain which uses this EIP would run into this.

getStorageAt RPC call in client also guards against non-existing accounts by returning the empty storage slot.

In order to make this more consistent, let getContractStorage return empty storage in case the account does not exist. This aligns with reality and also ensures that the caller of this method does not have to do either wrap the call into a try-catch block or checking pre-calling if the account exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants