Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ec_precompiles input padding #960

Merged
merged 1 commit into from
Sep 18, 2024
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
7 changes: 5 additions & 2 deletions crates/evm/src/precompiles/ec_add.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use evm::errors::EVMError;
use evm::precompiles::Precompile;
use garaga::core::circuit::AddInputResultTrait2;
use utils::helpers::ToBytes;
use utils::helpers::load_word;
use utils::helpers::{load_word, U8SpanExTrait};


const BASE_COST: u64 = 150;
Expand All @@ -24,9 +24,12 @@ pub impl EcAdd of Precompile {
0x6.try_into().unwrap()
}

fn exec(mut input: Span<u8>) -> Result<(u64, Span<u8>), EVMError> {
fn exec(input: Span<u8>) -> Result<(u64, Span<u8>), EVMError> {
let gas = BASE_COST;

// Pad the input to 128 bytes to avoid out-of-bounds accesses
let mut input = input.pad_right_with_zeroes(128);

let x1_bytes = *(input.multi_pop_front::<32>().unwrap());
let x1: u256 = load_word(U256_BYTES_LEN, x1_bytes.unbox().span());

Expand Down
5 changes: 4 additions & 1 deletion crates/evm/src/precompiles/ec_mul.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use evm::errors::EVMError;
use evm::precompiles::Precompile;

use evm::precompiles::ec_add::{is_on_curve, double_ec_point_unchecked, ec_safe_add};
use utils::helpers::{load_word, ToBytes};
use utils::helpers::{load_word, ToBytes, U8SpanExTrait};

// const BN254_ORDER: u256 = 0x30644E72E131A029B85045B68181585D2833E84879B9709143E1F593F0000001;

Expand All @@ -20,6 +20,9 @@ pub impl EcMul of Precompile {
fn exec(mut input: Span<u8>) -> Result<(u64, Span<u8>), EVMError> {
let gas = BASE_COST;

// Pad the input to 128 bytes to avoid out-of-bounds accesses
let mut input = input.pad_right_with_zeroes(96);

let x1_bytes = *(input.multi_pop_front::<32>().unwrap());
let x1: u256 = load_word(U256_BYTES_LEN, x1_bytes.unbox().span());

Expand Down
Loading