Skip to content

Commit

Permalink
fix: y parity in ec_recover
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Sep 18, 2024
1 parent 2c2d12a commit 122c5a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 3 additions & 4 deletions crates/evm/src/precompiles/ec_recover.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use core::traits::Into;
use evm::errors::EVMError;
use evm::precompiles::Precompile;
use utils::helpers::{ToBytes, FromBytes};
use utils::traits::BoolIntoNumeric;
use utils::traits::EthAddressIntoU256;
use utils::traits::{NumericIntoBool, BoolIntoNumeric};

const EC_RECOVER_PRECOMPILE_GAS_COST: u64 = 3000;

Expand All @@ -30,11 +30,10 @@ pub impl EcRecover of Precompile {
let y_parity = match v {
Option::Some(v) => {
let y_parity = v - 27;
if (y_parity == 0 || y_parity == 1) {
y_parity == 1
} else {
if (y_parity != 0 && y_parity != 1) {
return Result::Ok((gas, [].span()));
}
y_parity.into()
},
Option::None => { return Result::Ok((gas, [].span())); }
};
Expand Down
7 changes: 7 additions & 0 deletions crates/utils/src/traits.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ pub impl BoolIntoNumeric<T, +Zero<T>, +One<T>> of Into<bool, T> {
}
}

pub impl NumericIntoBool<T, +Drop<T>, +Zero<T>, +One<T>, +PartialEq<T>> of Into<T, bool> {
#[inline(always)]
fn into(self: T) -> bool {
self != Zero::<T>::zero()
}
}

pub impl EthAddressIntoU256 of Into<EthAddress, u256> {
fn into(self: EthAddress) -> u256 {
let intermediate: felt252 = self.into();
Expand Down

0 comments on commit 122c5a6

Please sign in to comment.