Skip to content

Commit

Permalink
fix: p256 verify output is a 32-bytes array
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Sep 5, 2024
1 parent bd54558 commit c27ebb7
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions crates/evm/src/precompiles/p256verify.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,43 @@ use utils::helpers::{U256Trait, ToBytes, FromBytes};

const P256VERIFY_PRECOMPILE_GAS_COST: u128 = 3450;

const ONE_32_BYTES: [
u8
; 32] = [
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x01
];

impl P256Verify of Precompile {
#[inline(always)]
fn address() -> EthAddress {
Expand Down Expand Up @@ -62,7 +99,7 @@ impl P256Verify of Precompile {
return Result::Ok((gas, [].span()));
}

return Result::Ok((gas, [1].span()));
return Result::Ok((gas, ONE_32_BYTES.span()));
}
}

Expand Down Expand Up @@ -105,7 +142,7 @@ mod tests {

let (gas, result) = P256Verify::exec(calldata.span()).unwrap();

let result: u256 = result.from_be_bytes().unwrap();
let result: u256 = result.from_be_bytes().expect('p256verify_precompile_test');
assert_eq!(result, 0x01);
assert_eq!(gas, 3450);
}
Expand Down

0 comments on commit c27ebb7

Please sign in to comment.