Skip to content

Commit

Permalink
chore(ethereum-lc): refactor of refactor of refactor
Browse files Browse the repository at this point in the history
Signed-off-by: aeryz <[email protected]>
  • Loading branch information
aeryz committed Nov 3, 2023
1 parent 7f9e244 commit 46cd6c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
25 changes: 7 additions & 18 deletions light-clients/ethereum-light-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ impl IbcClient for EthereumLightClient {
wasm_client_state.data.genesis_validators_root.clone(),
VerificationContext { deps },
)
.map_err(|e| Error::Verification {
context: VerificationError::LightClientUpdate,
error: e.to_string(),
})?;
.map_err(VerificationError::LightClientUpdate)?;

let proof_data = header
.account_update
Expand All @@ -161,10 +158,7 @@ impl IbcClient for EthereumLightClient {
)
})?,
)
.map_err(|e| Error::Verification {
context: VerificationError::AccountStorageRoot,
error: e.to_string(),
})?;
.map_err(VerificationError::AccountStorageRoot)?;

Ok(ContractResult::valid(None))
}
Expand Down Expand Up @@ -420,10 +414,8 @@ fn do_verify_membership(
&rlp::encode(&storage_proof.value.as_slice()),
&storage_proof.proof,
)
.map_err(|e| Error::Verification {
context: VerificationError::Membership,
error: e.to_string(),
})
.map_err(VerificationError::Membership)
.map_err(Into::into)
}

/// Verifies that no value is committed at `path` in the counterparty light client's storage.
Expand All @@ -435,12 +427,9 @@ fn do_verify_non_membership(
) -> Result<(), Error> {
check_commitment_key(path, counterparty_commitment_slot, &storage_proof.key)?;

if verify_storage_absence(storage_root, &storage_proof.key, &storage_proof.proof).map_err(
|e| Error::Verification {
context: VerificationError::NonMembership,
error: e.to_string(),
},
)? {
if verify_storage_absence(storage_root, &storage_proof.key, &storage_proof.proof)
.map_err(VerificationError::NonMembership)?
{
Ok(())
} else {
Err(Error::CounterpartyStorageNotNil)
Expand Down
21 changes: 12 additions & 9 deletions light-clients/ethereum-light-client/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ pub enum Error {
#[error("consensus state not found at height {0}")]
ConsensusStateNotFound(Height),

#[error("verification error: {error} ({context})")]
Verification {
context: VerificationError,
error: String,
},
#[error("verification error ({0})")]
Verification(VerificationError),

#[error("IBC path is empty")]
EmptyIbcPath,
Expand Down Expand Up @@ -130,11 +127,17 @@ impl From<CustomQueryError> for Error {
#[derive(ThisError, Debug, PartialEq)]
pub enum VerificationError {
#[error("light client update")]
LightClientUpdate,
LightClientUpdate(ethereum_verifier::Error),
#[error("account storage root")]
AccountStorageRoot,
AccountStorageRoot(ethereum_verifier::Error),
#[error("membership")]
Membership,
Membership(ethereum_verifier::Error),
#[error("non-membership")]
NonMembership,
NonMembership(ethereum_verifier::Error),
}

impl From<VerificationError> for Error {
fn from(value: VerificationError) -> Self {
Error::Verification(value)
}
}

0 comments on commit 46cd6c9

Please sign in to comment.