Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,23 @@ impl<T: Config> Pallet<T> {
}

fn recover_signer(transaction: &Transaction) -> Option<H160> {
// EIP-2 related
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2.md#specification
const SECP256K1N_HALF: H256 = H256([
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding some more context:

Suggested change
const SECP256K1N_HALF: H256 = H256([
/// The order of the secp256k1 curve, divided by two.
///
/// Signatures that should be checked according to EIP-2 should have an S value less than or equal to this:
///
/// `57896044618658097711785492504343953926418782139537452191302581570759080747168`
const SECP256K1N_HALF: H256 = H256([

0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x5d, 0x57, 0x6e, 0x73, 0x57, 0xa4, 0x50, 0x1d, 0xdf, 0xe9, 0x2f, 0x46,
0x68, 0x1b, 0x20, 0xa0,
]);
let s_value = match transaction {
Transaction::Legacy(t) => *t.signature.s(),
Transaction::EIP2930(t) => t.s,
Transaction::EIP1559(t) => t.s,
};

if s_value > SECP256K1N_HALF {
return None;
}

let mut sig = [0u8; 65];
let mut msg = [0u8; 32];
match transaction {
Expand Down
Loading