From c27ebb79e95fcb36ce4dc1629ad54733f1324f97 Mon Sep 17 00:00:00 2001 From: enitrat Date: Thu, 5 Sep 2024 13:44:42 +0200 Subject: [PATCH] fix: p256 verify output is a 32-bytes array --- crates/evm/src/precompiles/p256verify.cairo | 41 ++++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/crates/evm/src/precompiles/p256verify.cairo b/crates/evm/src/precompiles/p256verify.cairo index 0105e53f3..bc7ae09be 100644 --- a/crates/evm/src/precompiles/p256verify.cairo +++ b/crates/evm/src/precompiles/p256verify.cairo @@ -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 { @@ -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())); } } @@ -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); }