Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions modules/evm/src/precompiles/blake2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl Precompile for Blake2F {
const BLAKE2_F_ARG_LEN: usize = 213;

let input = handle.input();

if input.len() != BLAKE2_F_ARG_LEN {
return Err(PrecompileFailure::Error {
exit_status: ExitError::Other(
Expand All @@ -50,6 +51,7 @@ impl Precompile for Blake2F {

let gas_cost: u64 = (rounds as u64) * Blake2F::GAS_COST_PER_ROUND;
handle.record_cost(gas_cost)?;

let input = handle.input();

// we use from_le_bytes below to effectively swap byte order to LE if architecture is BE
Expand Down
18 changes: 9 additions & 9 deletions modules/evm/src/precompiles/ecrecover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ impl LinearCostPrecompile for ECRecover {
let mut sig = [0u8; 65];

msg[0..32].copy_from_slice(&input[0..32]);
sig[0..32].copy_from_slice(&input[64..96]);
sig[32..64].copy_from_slice(&input[96..128]);

sig[64] = match input[63] {
v if v > 26 && input[32..63] == [0; 31] => v - 27,
_ => {
return Ok((ExitSucceed::Returned, [0u8; 0].to_vec()));
}
};
sig[0..32].copy_from_slice(&input[64..96]); // r
sig[32..64].copy_from_slice(&input[96..128]); // s
sig[64] = input[63]; // v

// v can only be 27 or 28 on the full 32 bytes value.
// https://github.com/ethereum/go-ethereum/blob/a907d7e81aaeea15d80b2d3209ad8e08e3bf49e0/core/vm/contracts.go#L177
if input[32..63] != [0u8; 31] || ![27, 28].contains(&input[63]) {
return Ok((ExitSucceed::Returned, [0u8; 0].to_vec()));
}

let result = match sp_io::crypto::secp256k1_ecdsa_recover(&sig, &msg) {
Ok(pubkey) => {
Expand Down