Skip to content

Commit

Permalink
revert delegate verification
Browse files Browse the repository at this point in the history
  • Loading branch information
akaladarshi committed Feb 5, 2025
1 parent 856a7f9 commit 3221430
Showing 1 changed file with 1 addition and 48 deletions.
49 changes: 1 addition & 48 deletions src/shim/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use super::{
fvm_shared_latest::{self, commcid::Commitment},
version::NetworkVersion,
};
use crate::rpc::eth::types::EthAddress;
use crate::utils::encoding::keccak_256;
use bls_signatures::{PublicKey as BlsPublicKey, Signature as BlsSignature};
use cid::Cid;
use fvm_ipld_encoding::{
Expand Down Expand Up @@ -138,7 +136,7 @@ impl Signature {
match self.sig_type {
SignatureType::Bls => verify_bls_sig(&self.bytes, data, addr),
SignatureType::Secp256k1 => verify_secp256k1_sig(&self.bytes, data, addr),
SignatureType::Delegated => verify_delegated_sig(&self.bytes, data, addr),
SignatureType::Delegated => Ok(()), // TODO: Implement delegated signature verification
}
}

Expand Down Expand Up @@ -214,51 +212,6 @@ pub fn cid_to_replica_commitment_v1(c: &Cid) -> Result<Commitment, &'static str>
fvm_shared_latest::commcid::cid_to_replica_commitment_v1(c)
}

/// Returns `String` error if a delegated signature is invalid.
/// TODO(fvm_shared): add verify delegated signature to [`fvm_shared_latest::crypto::signature::ops`]
pub fn verify_delegated_sig(
signature: &[u8],
data: &[u8],
addr: &crate::shim::address::Address,
) -> Result<(), String> {
use super::fvm_shared_latest::{
address::Protocol::Delegated,
crypto::signature::{ops::recover_secp_public_key, SECP_SIG_LEN},
};

if addr.protocol() != Delegated {
return Err(format!(
"cannot validate a delegated signature against a {} address expected",
addr.protocol(),
));
}

if signature.len() != SECP_SIG_LEN {
return Err(format!(
"invalid delegated signature length. Was {}, must be {}",
signature.len(),
SECP_SIG_LEN
));
}

let hash = keccak_256(data);
let mut sig = [0u8; SECP_SIG_LEN];
sig[..].copy_from_slice(signature);
let pub_key = recover_secp_public_key(&hash, &sig).map_err(|e| e.to_string())?;

let eth_addr =
EthAddress::eth_address_from_pub_key(&pub_key.serialize()).map_err(|e| e.to_string())?;

let rec_addr = eth_addr.to_filecoin_address().map_err(|e| e.to_string())?;

// check address against recovered address
if rec_addr == *addr {
Ok(())
} else {
Err("Delegated signature verification failed".to_owned())
}
}

/// Signature variants for Filecoin signatures.
#[derive(
Clone,
Expand Down

0 comments on commit 3221430

Please sign in to comment.