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

Withdrawal proof cache #135

Closed
onbjerg opened this issue Oct 5, 2024 · 2 comments
Closed

Withdrawal proof cache #135

onbjerg opened this issue Oct 5, 2024 · 2 comments
Assignees
Labels
C-enhancement New feature or request

Comments

@onbjerg
Copy link
Member

onbjerg commented Oct 5, 2024

Motivation

To withdraw from an OP stack chain, a user needs to provide a proof on L1 that a withdrawal was included on-chain on L2. To do this, eth_getProof is called to prove a storage slot on the withdrawal contract against an output root.

On Reth, eth_getProof is really expensive due to no historical tries being stored. To prove at an old block, old state is reconstructed in-memory using changesets. The further back you go, the more expensive this operation is, which is why it is [restricted] in Reth.

We could increase this maximum, but it would likely be too impractical to run a node with the resources necessary to actually compute historical proofs on a 1s blocktime chain with activity, gigagas or not.

To solve this, we are going to build an ExEx.

Proposed solution

We will build an ExEx that computes withdrawal proofs and caches them in a separate database. The eth_getProof RPC method is replaced with one that first checks this cache, and thereafter computes a historical proof as usual with the normal constraints on how far back you can go.

The ExEx will look for any new withdrawals and store these. Then, every time an output root is posted on L1, non-proven withdrawals are proven and the resulting proof is stored in the cache.

@onbjerg onbjerg added the C-enhancement New feature or request label Oct 5, 2024
@onbjerg onbjerg self-assigned this Oct 5, 2024
@rkrasiuk
Copy link
Member

rkrasiuk commented Oct 7, 2024

After internal discussion, it seems like we can introduce a satisfactory workaround to avoid the headache of managing additional cache/state. Per @onbjerg's investigation, the only fields from eth_getProof response needed for withdrawals are storage_root and storage_proofs. Since the rest of the state is not needed, we can simply compute the storage proof and corresponding root and expose that through new eth_getStorageProof RPC endpoint. This endpoint can have much more lax limitations on historical state loading.

Here's a plan for implementing this:

  1. Extend StorageRootProvider with new storage_proof method
fn storage_proof(&self, address: Address, slot: B256) -> ProviderResult<StorageProof>;
  1. Extend EthApi new RPC endpoint eth_get_storage_proof
pub struct StorageProofResponse {
  root: B256,
  proof: EIP1186StorageProof,
}


#[method = "getStorageProof"]
async fn get_storage_proof(&self, address: Address, slot: JsonStorageKey, block_number: Option<BlockId>) -> RpcResult<StorageProofResponse>;
  1. Modify the relevant OP stack component to call eth_getStorageProof instead

@onbjerg
Copy link
Member Author

onbjerg commented Oct 24, 2024

Moved this over to Odyssey ithacaxyz/odyssey#72

@onbjerg onbjerg closed this as completed Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants