Skip to content

Commit

Permalink
fix sender
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-shashank committed Oct 14, 2024
1 parent cfff41c commit c2cd796
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 13 deletions.
72 changes: 60 additions & 12 deletions src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use super::{derive_eip_155_chain_id, validate_eip155_chain_id};
use crate::shim::crypto::Signature;
use crate::shim::fvm_shared_latest;
use anyhow::{bail, ensure, Context};
use bytes::BufMut;
use bytes::BytesMut;
Expand Down Expand Up @@ -225,19 +226,12 @@ impl EthTx {

fn sender(&self) -> anyhow::Result<Address> {
let hash = keccak_hash::keccak(self.rlp_unsigned_message()?);
let msg = libsecp256k1::Message::parse(hash.as_fixed_bytes());
let sig = self.signature()?;
let sig_data = self.to_verifiable_signature(sig.bytes().to_vec())?;
let rec_sig = libsecp256k1::Signature::parse_standard(
sig_data
.get(..64)
.context("failed to get a range of values")?
.try_into()
.context("slice should be 64 bytes")?,
)?;
let rec_id =
libsecp256k1::RecoveryId::parse(*sig_data.get(64).context("failed to get value")?)?;
let pubkey = libsecp256k1::recover(&msg, &rec_sig, &rec_id)?;
let sig_data = self.to_verifiable_signature(sig.bytes().to_vec())?[..]
.try_into()
.expect("Incorrect signature length");
let pubkey =
fvm_shared_latest::crypto::signature::ops::recover_secp_public_key(&hash.0, &sig_data)?;
let eth_addr = EthAddress::eth_address_from_pub_key(&pubkey.serialize())?;
eth_addr.to_filecoin_address()
}
Expand Down Expand Up @@ -926,5 +920,59 @@ pub(crate) mod tests {

let result = parse_eip1559_tx(&raw_tx);
assert!(result.is_ok());

if let EthTx::Eip1559(tx) = result.unwrap() {
// Assert chain ID
assert_eq!(tx.chain_id, 1);

// Assert nonce
assert_eq!(tx.nonce, 241);

// Assert max fee per gas
assert_eq!(tx.max_fee_per_gas, BigInt::from(91097072255u64));

// Assert max priority fee per gas
assert_eq!(tx.max_priority_fee_per_gas, BigInt::from(1000000000u64));

// Assert gas limit
assert_eq!(tx.gas_limit, 21000);

// Assert recipient address
assert_eq!(
tx.to.unwrap(),
EthAddress::from_str("0xe0e5d2b4edcc473b988b44b4d13c3972cb6694cb").unwrap()
);

// Assert value
assert_eq!(tx.value, BigInt::from(138078072511761950u64));

// Assert input data (not explicitly given in your values, assuming it's empty for now)
assert!(tx.input.is_empty());

// Assert v, r, s
assert_eq!(tx.v, BigInt::from(1u8));
assert_eq!(
tx.r,
BigInt::from_bytes_be(
Sign::Plus,
&hex::decode(
"7eb3335f4fd4de25ec3452c08882f28fb098b2eaa37a332941f918d869f5c2ad"
)
.unwrap()
)
);
assert_eq!(
tx.s,
BigInt::from_bytes_be(
Sign::Plus,
&hex::decode(
"59b9d4aa997c7fa34f1b167f98a12432bb1a4a35660d723a9c19bb76b4cd025d"
)
.unwrap()
)
);
} else {
panic!("Expected EIP-1559 transaction");
}
}
}
2 changes: 1 addition & 1 deletion src/tool/subcommands/api_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ fn eth_tests_with_tipset<DB: Blockstore>(store: &Arc<DB>, shared_tipset: &Tipset
),
RpcTest::identity(EthGetTransactionHashByCid::request((block_cid,)).unwrap()),
RpcTest::identity(
EthSendRawTransaction::request((EthBytes(hex::decode("e6808609184e72a0008303000094b0920c523d582040f2bcb1bd7fb1c7c1ecebdb3480801c8080").unwrap()),))
EthSendRawTransaction::request((EthBytes(hex::decode("02f8740181f1843b9aca00851535cf027f82520894e0e5d2b4edcc473b988b44b4d13c3972cb6694cb8801ea8d467f558e1e80c001a07eb3335f4fd4de25ec3452c08882f28fb098b2eaa37a332941f918d869f5c2ada059b9d4aa997c7fa34f1b167f98a12432bb1a4a35660d723a9c19bb76b4cd025d").unwrap()),))
.unwrap(),
),
];
Expand Down

0 comments on commit c2cd796

Please sign in to comment.