Skip to content

Commit 77fecc5

Browse files
committed
Prague precompiles refactoring
1 parent 0f44d8d commit 77fecc5

9 files changed

Lines changed: 23 additions & 34 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ sha3 = { version = "0.10", default-features = false }
2525
serde = { version = "1.0", features = ["derive"] }
2626

2727
[patch.crates-io]
28+
# Constrain to v0.14.6 to ensure compatibility with sha3 0.10 and prevent unexpected upgrades
2829
generic-array = { git = "https://github.com/fizyk20/generic-array", rev = "effb209dd7e61b8226e194dec2979314e27598d1" }

evm-tests/jsontests/src/assertions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::config::TestConfig;
44
use crate::types::Spec;
55
use crate::types::{InvalidTxReason, PostState};
66

7-
/// Assert vicinity validation to ensure that test hos expected validation error
7+
/// Assert vicinity validation to ensure that test expected validation error
88
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
99
pub fn assert_vicinity_validation(
1010
reason: &InvalidTxReason,
@@ -16,7 +16,7 @@ pub fn assert_vicinity_validation(
1616
let file_name = &test_config.file_name;
1717
match *spec {
1818
Spec::Istanbul | Spec::Berlin => match reason {
19-
InvalidTxReason::GasPriseEip1559 => {
19+
InvalidTxReason::GasPriceEip1559 => {
2020
for (i, state) in states.iter().enumerate() {
2121
let expected = state.expect_exception.as_deref().unwrap_or_else(|| {
2222
panic!(
@@ -175,7 +175,7 @@ pub fn assert_vicinity_validation(
175175
InvalidTxReason::GasPriceLessThenBlockBaseFee => {
176176
for (i, state) in states.iter().enumerate() {
177177
let expected = state.expect_exception.as_deref().unwrap_or_else(|| {
178-
panic!("expected error message for test: {reason:?} [{spec:?}] {name}:{i})\n{file_name:?}")
178+
panic!("expected error message for test: {reason:?} [{spec:?}] {name}:{i}\n{file_name:?}")
179179
});
180180
let is_checked = expected == "TR_FeeCapLessThanBlocks"
181181
|| expected == "TransactionException.INSUFFICIENT_MAX_FEE_PER_GAS";

evm-tests/jsontests/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ pub mod vm;
2020
mod assertions;
2121
mod config;
2222
mod execution_results;
23-
// TODO
24-
// mod old_precompiles;
2523
mod precompiles;
2624
mod state_dump;
27-
// mod utils;
2825

2926
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
3027
fn main() -> Result<(), String> {

evm-tests/jsontests/src/precompiles.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ mod kzg;
33
use crate::precompiles::kzg::Kzg;
44
use crate::types::Spec;
55
use aurora_engine_modexp::AuroraModExp;
6+
use aurora_engine_precompiles::bls12_381::{
7+
BlsG1Add, BlsG1Msm, BlsG2Add, BlsG2Msm, BlsMapFp2ToG2, BlsMapFpToG1, BlsPairingCheck,
8+
};
69
use aurora_engine_precompiles::{
710
alt_bn256::{Bn256Add, Bn256Mul, Bn256Pair},
811
blake2::Blake2F,
@@ -118,7 +121,14 @@ impl Precompiles {
118121
}
119122

120123
pub fn new_prague() -> Self {
121-
let map = Self::new_cancun().0;
124+
let mut map = Self::new_cancun().0;
125+
map.insert(BlsG1Add::ADDRESS.raw(), Box::new(BlsG1Add));
126+
map.insert(BlsG1Msm::ADDRESS.raw(), Box::new(BlsG1Msm));
127+
map.insert(BlsG2Add::ADDRESS.raw(), Box::new(BlsG2Add));
128+
map.insert(BlsG2Msm::ADDRESS.raw(), Box::new(BlsG2Msm));
129+
map.insert(BlsPairingCheck::ADDRESS.raw(), Box::new(BlsPairingCheck));
130+
map.insert(BlsMapFpToG1::ADDRESS.raw(), Box::new(BlsMapFpToG1));
131+
map.insert(BlsMapFp2ToG2::ADDRESS.raw(), Box::new(BlsMapFp2ToG2));
122132
Self(map)
123133
}
124134
}

evm-tests/jsontests/src/precompiles/kzg.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![allow(clippy::module_inception, clippy::large_stack_arrays)]
22

3-
use aurora_engine_precompiles::{Context, EthGas, ExitError, Precompile, PrecompileOutput};
3+
use aurora_engine_precompiles::{
4+
Context, EthGas, EvmPrecompileResult, ExitError, Precompile, PrecompileOutput,
5+
};
46
use primitive_types::H160;
57
use std::borrow::Cow::Borrowed;
68

@@ -271,7 +273,7 @@ impl Precompile for Kzg {
271273
target_gas: Option<EthGas>,
272274
_context: &Context,
273275
_is_static: bool,
274-
) -> Result<PrecompileOutput, ExitError> {
276+
) -> EvmPrecompileResult {
275277
let cost = Self::required_gas(input)?;
276278
if let Some(target_gas) = target_gas {
277279
if cost > target_gas {

evm-tests/jsontests/src/state.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::assertions::{
44
};
55
use crate::config::TestConfig;
66
use crate::execution_results::{FailedTestDetails, TestExecutionResult};
7-
// TODO: use crate::old_precompiles::JsonPrecompile;
87
use crate::precompiles::Precompiles;
98
use crate::state_dump::{StateTestsDump, StateTestsDumper};
109
use crate::types::account_state::MemoryAccountsState;
@@ -48,17 +47,6 @@ pub fn test(test_config: TestConfig, test: StateTestCase) -> TestExecutionResult
4847
fn test_run(test_config: &TestConfig, test: &StateTestCase) -> TestExecutionResult {
4948
let mut tests_result = TestExecutionResult::new();
5049
for (spec, states) in &test.post_states {
51-
// TODO
52-
if *spec >= Spec::Prague {
53-
continue;
54-
}
55-
56-
// TODO
57-
// if test_config.name != "tests/static/state_tests/stStaticCall/static_callBasicFiller.json::static_callBasic[fork_Prague-state_test-d1-g0-v0]" {
58-
// continue
59-
// }
60-
// println!("{test:?}");
61-
6250
// Run tests for specific EVM hard fork (Spec)
6351
if let Some(s) = test_config.spec.as_ref() {
6452
if s != spec {
@@ -126,8 +114,6 @@ fn test_run(test_config: &TestConfig, test: &StateTestCase) -> TestExecutionResu
126114

127115
for (i, state) in states.iter().enumerate() {
128116
let mut backend = MemoryBackend::new(&vicinity, original_state.0.clone());
129-
// TODO
130-
// println!("\nSTATE BEFORE: {:#?}", backend.state());
131117
tests_result.total += 1;
132118

133119
// Test case may be expected to fail with an unsupported tx type if the current fork is
@@ -214,8 +200,6 @@ fn test_run(test_config: &TestConfig, test: &StateTestCase) -> TestExecutionResu
214200
access_list.clone(),
215201
authorization_list.clone(),
216202
);
217-
// TODO
218-
// println!("\nCALLER: {caller:?}\nTO: {to:?}\nVALUE: {value:?}n{gas_limit:?}\n{:?}\n{:?}\nREASON: {_reason:?}",access_list,authorization_list);
219203
assert_call_exit_exception(state.expect_exception.as_ref(), &test_config.name);
220204
} else {
221205
let code = data;
@@ -292,8 +276,6 @@ fn test_run(test_config: &TestConfig, test: &StateTestCase) -> TestExecutionResu
292276
});
293277
}
294278

295-
// TODO
296-
// println!("\nSTATE AFTER: {:#?}", backend.state());
297279
let backend_state = MemoryAccountsState(backend.state().clone());
298280
let (is_valid_hash, actual_hash) = backend_state.check_valid_hash(&state.hash);
299281
if !is_valid_hash {

evm-tests/jsontests/src/state_dump.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
// TODO: fix it
2-
#![allow(dead_code)]
31
use crate::types::Spec;
42
use aurora_evm::backend::{MemoryAccount, MemoryVicinity};
53
use primitive_types::{H160, H256, U256};
64
use std::collections::BTreeMap;
75

6+
#[allow(dead_code)]
87
#[derive(Default, Debug, Clone)]
98
#[cfg_attr(feature = "dump-state", derive(serde::Serialize, serde::Deserialize))]
109
pub struct StateTestsDump {

evm-tests/jsontests/src/types/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl StateTestCase {
7575
tx.gas_price.or(tx.max_fee_per_gas).unwrap_or_default()
7676
} else {
7777
if tx.max_fee_per_gas.is_some() {
78-
return Err(InvalidTxReason::GasPriseEip1559);
78+
return Err(InvalidTxReason::GasPriceEip1559);
7979
}
8080
tx.gas_price.expect("expect gas price")
8181
};
@@ -267,7 +267,7 @@ pub enum InvalidTxReason {
267267
BlobGasPriceGreaterThanMax,
268268
BlobVersionedHashesNotSupported,
269269
MaxFeePerBlobGasNotSupported,
270-
GasPriseEip1559,
270+
GasPriceEip1559,
271271
AuthorizationListNotExist,
272272
AuthorizationListNotSupported,
273273
InvalidAuthorizationChain,

evm-tests/jsontests/src/utils.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,6 @@ pub mod transaction {
355355
use ethjson::uint::Uint;
356356
use primitive_types::{H160, H256, U256};
357357

358-
// TODO: it will be refactored as old solution inefficient, also will be removed clippy-allow flag
359-
#[allow(clippy::too_many_arguments, clippy::too_many_lines)]
360358
pub fn validate(
361359
tx: &Transaction,
362360
block_gas_limit: U256,
@@ -557,7 +555,7 @@ pub mod transaction {
557555
BlobGasPriceGreaterThanMax,
558556
BlobVersionedHashesNotSupported,
559557
MaxFeePerBlobGasNotSupported,
560-
GasPriseEip1559,
558+
GasPriceEip1559,
561559
AuthorizationListNotExist,
562560
AuthorizationListNotSupported,
563561
InvalidAuthorizationChain,

0 commit comments

Comments
 (0)