Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
fix: returndata on wrong precompile input
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Sep 5, 2024
1 parent ee2c039 commit 6c8dac1
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb 2.7.1
starknet-foundry 0.28.0
starknet-foundry 0.30.0
6 changes: 3 additions & 3 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ dependencies = [
[[package]]
name = "snforge_scarb_plugin"
version = "0.1.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.28.0#4dfe39d96690ed6b3d56971512700de3f58288ea"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.30.0#196f06b251926697c3d66800f2a93ae595e76496"

[[package]]
name = "snforge_std"
version = "0.28.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.28.0#4dfe39d96690ed6b3d56971512700de3f58288ea"
version = "0.30.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.30.0#196f06b251926697c3d66800f2a93ae595e76496"
dependencies = [
"snforge_scarb_plugin",
]
Expand Down
2 changes: 1 addition & 1 deletion crates/alexandria_data_structures/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "0.1.0"
[dependencies]

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.28.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.30.0" }

[scripts]
test = "snforge test --max-n-steps 4294967295"
Expand Down
2 changes: 1 addition & 1 deletion crates/contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ build-external-contracts = ["openzeppelin::token::erc20::erc20::ERC20"]
name = "contracts"

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.28.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.30.0" }
assert_macros = "0.1.0"
snforge_utils = { path = "../snforge_utils" }

Expand Down
2 changes: 1 addition & 1 deletion crates/evm/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ openzeppelin = { path = "../openzeppelin" }
garaga = { git = "https://github.com/keep-starknet-strange/garaga.git" }

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.28.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.30.0" }
snforge_utils = { path = "../snforge_utils" }
assert_macros = "0.1.0"

Expand Down
27 changes: 14 additions & 13 deletions crates/evm/src/precompiles/ec_add.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ impl EcAdd of Precompile {
fn exec(mut input: Span<u8>) -> Result<(u128, Span<u8>), EVMError> {
let gas = BASE_COST;

// Load x1
let bytes_32 = *(input.multi_pop_front::<32>().unwrap());
let x1: u256 = load_word(U256_BYTES_LEN, bytes_32.unbox().span());
// Load y1
let bytes_32 = *(input.multi_pop_front::<32>().unwrap());
let y1: u256 = load_word(U256_BYTES_LEN, bytes_32.unbox().span());
// Load x2
let bytes_32 = *(input.multi_pop_front::<32>().unwrap());
let x2: u256 = load_word(U256_BYTES_LEN, bytes_32.unbox().span());
// Load y2
let bytes_32 = *(input.multi_pop_front::<32>().unwrap());
let y2: u256 = load_word(U256_BYTES_LEN, bytes_32.unbox().span());
let x1_bytes = *(input.multi_pop_front::<32>().unwrap());
let x1: u256 = load_word(U256_BYTES_LEN, x1_bytes.unbox().span());

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

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

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

let (x, y) = match ec_add(x1, y1, x2, y2) {
Option::Some((x, y)) => { (x, y) },
Option::None => (0, 0),
Option::None => {
return Result::Err(EVMError::InvalidParameter('invalid ec_add parameters'));
},
};

let mut result_bytes = array![];
Expand Down
27 changes: 13 additions & 14 deletions crates/evm/src/precompiles/ec_mul.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@ impl EcMul of Precompile {
fn exec(mut input: Span<u8>) -> Result<(u128, Span<u8>), EVMError> {
let gas = BASE_COST;

// from_be_bytes should be used

// Load x
let bytes_32 = *(input.multi_pop_front::<32>().unwrap());
let x: u256 = load_word(U256_BYTES_LEN, bytes_32.unbox().span());
// Load y
let bytes_32 = *(input.multi_pop_front::<32>().unwrap());
let y: u256 = load_word(U256_BYTES_LEN, bytes_32.unbox().span());
// Load s
let bytes_32 = *(input.multi_pop_front::<32>().unwrap());
let s: u256 = load_word(U256_BYTES_LEN, bytes_32.unbox().span());

let (x, y) = match ec_mul(x, y, s) {
let x1_bytes = *(input.multi_pop_front::<32>().unwrap());
let x1: u256 = load_word(U256_BYTES_LEN, x1_bytes.unbox().span());

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

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

let (x, y) = match ec_mul(x1, y1, s) {
Option::Some((x, y)) => { (x, y) },
Option::None => (0, 0),
Option::None => {
return Result::Err(EVMError::InvalidParameter('invalid ec_mul parameters'));
},
};

// Append x and y to the result bytes.
Expand Down
2 changes: 1 addition & 1 deletion crates/openzeppelin/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ starknet.workspace = true
fmt.workspace = true

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.28.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.30.0" }

[scripts]
test = "snforge test --max-n-steps 4294967295"
Expand Down
2 changes: 1 addition & 1 deletion crates/snforge_utils/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ starknet = "2.7.1"
evm = { path = "../evm" }

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.28.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.30.0" }

[[target.starknet-contract]]
sierra = true
Expand Down
2 changes: 1 addition & 1 deletion crates/utils/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ alexandria_data_structures = { path = "../alexandria_data_structures" }
fmt.workspace = true

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.28.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.30.0" }

[scripts]
test = "snforge test --max-n-steps 4294967295"
Expand Down

0 comments on commit 6c8dac1

Please sign in to comment.