Skip to content

Commit 64664aa

Browse files
authored
Merge pull request #16 from peaqnetwork/release-eip
Add EIP2 signature check
2 parents 436885f + 232ad0e commit 64664aa

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

frame/ethereum/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,26 @@ impl<T: Config> Pallet<T> {
382382
}
383383
}
384384
fn recover_signer(transaction: &Transaction) -> Option<H160> {
385+
/// The order of the secp256k1 curve, divided by two.
386+
///
387+
/// Signatures that should be checked according to EIP-2 should have an S value less than or equal to this:
388+
///
389+
/// `57896044618658097711785492504343953926418782139537452191302581570759080747168`
390+
const SECP256K1N_HALF: H256 = H256([
391+
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
392+
0xff, 0xff, 0x5d, 0x57, 0x6e, 0x73, 0x57, 0xa4, 0x50, 0x1d, 0xdf, 0xe9, 0x2f, 0x46,
393+
0x68, 0x1b, 0x20, 0xa0,
394+
]);
395+
let s_value = match transaction {
396+
Transaction::Legacy(t) => *t.signature.s(),
397+
Transaction::EIP2930(t) => t.s,
398+
Transaction::EIP1559(t) => t.s,
399+
};
400+
401+
if s_value > SECP256K1N_HALF {
402+
return None;
403+
}
404+
385405
let mut sig = [0u8; 65];
386406
let mut msg = [0u8; 32];
387407
match transaction {

0 commit comments

Comments
 (0)