Skip to content

Commit

Permalink
fix: use scroll_rpc for eth_getProof on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
benluelo committed Apr 28, 2024
1 parent 13949f8 commit 10d909e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 26 deletions.
44 changes: 44 additions & 0 deletions lib/chain-utils/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ pub trait EthereumChain:

/// The address of the [`IBCHandler`] smart contract deployed natively on this chain.
fn ibc_handler_address(&self) -> H160;

fn get_proof(
&self,
address: H160,
location: U256,
block: u64,
) -> impl Future<Output = unionlabs::ibc::lightclients::ethereum::storage_proof::StorageProof>;
}

pub trait EthereumChainExt: EthereumChain {
Expand All @@ -100,6 +107,43 @@ impl<C: ChainSpec, S: EthereumSignersConfig> EthereumChain for Ethereum<C, S> {
fn ibc_handler_address(&self) -> H160 {
self.ibc_handler_address
}

async fn get_proof(
&self,
address: H160,
location: U256,
block: u64,
) -> unionlabs::ibc::lightclients::ethereum::storage_proof::StorageProof {
let proof = self
.provider
.get_proof(
ethers::types::H160::from(address),
vec![location.to_be_bytes().into()],
Some(block.into()),
)
.await
.unwrap();

let proof = match <[_; 1]>::try_from(proof.storage_proof) {
Ok([proof]) => proof,
Err(invalid) => {
panic!("received invalid response from eth_getProof, expected length of 1 but got `{invalid:#?}`");
}
};

unionlabs::ibc::lightclients::ethereum::storage_proof::StorageProof {
proofs: [unionlabs::ibc::lightclients::ethereum::proof::Proof {
key: U256::from_be_bytes(proof.key.to_fixed_bytes()),
value: proof.value.into(),
proof: proof
.proof
.into_iter()
.map(|bytes| bytes.to_vec())
.collect(),
}]
.to_vec(),
}
}
}

// TODO(benluelo): Generic over middleware?
Expand Down
33 changes: 33 additions & 0 deletions lib/chain-utils/src/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,39 @@ impl EthereumChain for Scroll {
fn ibc_handler_address(&self) -> H160 {
self.ibc_handler_address
}

async fn get_proof(
&self,
address: H160,
location: U256,
block: u64,
) -> unionlabs::ibc::lightclients::ethereum::storage_proof::StorageProof {
let proof = self
.scroll_rpc
.get_proof(address, [location], scroll_rpc::BlockId::Number(block))
.await
.unwrap();

let proof = match <[_; 1]>::try_from(proof.storage_proof) {
Ok([proof]) => proof,
Err(invalid) => {
panic!("received invalid response from eth_getProof, expected length of 1 but got `{invalid:#?}`");
}
};

unionlabs::ibc::lightclients::ethereum::storage_proof::StorageProof {
proofs: [unionlabs::ibc::lightclients::ethereum::proof::Proof {
key: proof.key,
value: proof.value,
proof: proof
.proof
.into_iter()
.map(|bytes| bytes.to_vec())
.collect(),
}]
.to_vec(),
}
}
}

#[derive(Debug, thiserror::Error)]
Expand Down
30 changes: 4 additions & 26 deletions lib/relay-message/src/chain_impls/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,37 +567,15 @@ where
.await;

let proof = c
.provider()
.get_proof(
ethers::types::H160::from(c.ibc_handler_address()),
vec![location.into()],
Some(execution_height.into()),
c.ibc_handler_address(),
U256::from_be_bytes(location),
execution_height,
)
.await
.unwrap();
.await;

tracing::info!(?proof);

let proof = match <[_; 1]>::try_from(proof.storage_proof) {
Ok([proof]) => proof,
Err(invalid) => {
panic!("received invalid response from eth_getProof, expected length of 1 but got `{invalid:#?}`");
}
};

let proof = unionlabs::ibc::lightclients::ethereum::storage_proof::StorageProof {
proofs: [unionlabs::ibc::lightclients::ethereum::proof::Proof {
key: U256::from_be_bytes(proof.key.to_fixed_bytes()),
value: proof.value.into(),
proof: proof
.proof
.into_iter()
.map(|bytes| bytes.to_vec())
.collect(),
}]
.to_vec(),
};

match get_proof.path {
Path::ClientState(path) => Data::from(IbcProof::<_, Hc, Tr> {
proof,
Expand Down

0 comments on commit 10d909e

Please sign in to comment.