Skip to content

Commit

Permalink
Tests refactoring for BLS
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Feb 19, 2025
1 parent 49f4147 commit 3bc45e0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions engine-precompiles/src/bls12_381/g1_msm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{msm_required_gas, G1_INPUT_ITEM_LENGTH, SCALAR_LENGTH};
use crate::prelude::types::{make_address, Address, EthGas};
use crate::prelude::{vec, Borrowed, Vec};
use crate::prelude::{Borrowed, Vec};
use crate::{EvmPrecompileResult, Precompile, PrecompileOutput};
use evm::{Context, ExitError};

Expand Down Expand Up @@ -84,7 +84,7 @@ impl BlsG1Msm {

let zero_slice = &[0; FP_LENGTH];
let k = input.len() / INPUT_LENGTH;
let mut g1_input = vec![0u8; k * (2 * FP_LENGTH + SCALAR_LENGTH)];
let mut g1_input = crate::vec![0u8; k * (2 * FP_LENGTH + SCALAR_LENGTH)];
for i in 0..k {
let (p0_x, p0_y) =
extract_g1(&input[i * INPUT_LENGTH..i * INPUT_LENGTH + G1_INPUT_ITEM_LENGTH])?;
Expand Down
4 changes: 2 additions & 2 deletions engine-precompiles/src/bls12_381/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! # BLS12-381
//!
//! Represents [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537)
use crate::prelude::{vec, Borrowed, Vec};
use crate::prelude::Borrowed;
use evm::ExitError;

mod g1_add;
Expand Down Expand Up @@ -78,7 +78,7 @@ pub fn extract_g1(input: &[u8]) -> Result<(&[u8; FP_LENGTH], &[u8; FP_LENGTH]),

#[cfg(feature = "contract")]
#[must_use]
pub(super) fn padding_g1_result(output: &[u8; 2 * FP_LENGTH]) -> Vec<u8> {
pub(super) fn padding_g1_result(output: &[u8; 2 * FP_LENGTH]) -> crate::Vec<u8> {
let mut result = vec![0u8; 2 * PADDED_FP_LENGTH];
result[PADDING_LENGTH..PADDED_FP_LENGTH].copy_from_slice(&output[..FP_LENGTH]);
result[PADDING_LENGTH + PADDED_FP_LENGTH..2 * PADDED_FP_LENGTH]
Expand Down
14 changes: 14 additions & 0 deletions engine-tests/src/tests/bls12_381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,41 +237,49 @@ fn check_wasm_submit(address: Address, input: Vec<u8>, expected_output: &[u8]) {
}

#[test]
#[ignore]
fn test_bls12_381_g1_add() {
run_bls12_381_transaction_call("src/tests/res/bls/bls12_381_g1_add/");
}

#[test]
#[ignore]
fn test_bls12_381_g1_mul() {
run_bls12_381_transaction_call("src/tests/res/bls/bls12_381_g1_mul/");
}

#[test]
#[ignore]
fn test_bls12_381_g2_add() {
run_bls12_381_transaction_call("src/tests/res/bls/bls12_381_g2_add/");
}

#[test]
#[ignore]
fn test_bls12_381_g2_mul() {
run_bls12_381_transaction_call("src/tests/res/bls/bls12_381_g2_mul/");
}

#[test]
#[ignore]
fn test_bls12_381_pairing() {
run_bls12_381_transaction_call("src/tests/res/bls/bls12_381_pair/");
}

#[test]
#[ignore]
fn test_bls12_381_map_fp_to_g1() {
run_bls12_381_transaction_call("src/tests/res/bls/bls12_381_map_fp_to_g1/");
}

#[test]
#[ignore]
fn test_bls12_381_map_fp2_to_g2() {
run_bls12_381_transaction_call("src/tests/res/bls/bls12_381_map_fp2_to_g2/");
}

#[test]
#[ignore]
fn test_bls12_381_g1_add_standalone() {
run_bls12_381_standalone(
&bls12_381::BlsG1Add,
Expand All @@ -281,6 +289,7 @@ fn test_bls12_381_g1_add_standalone() {
}

#[test]
#[ignore]
fn test_bls12_381_g1_mul_standalone() {
run_bls12_381_standalone(
&bls12_381::BlsG1Msm,
Expand All @@ -290,6 +299,7 @@ fn test_bls12_381_g1_mul_standalone() {
}

#[test]
#[ignore]
fn test_bls12_381_g2_add_standalone() {
run_bls12_381_standalone(
&bls12_381::BlsG2Add,
Expand All @@ -299,6 +309,7 @@ fn test_bls12_381_g2_add_standalone() {
}

#[test]
#[ignore]
fn test_bls12_381_g2_mul_standalone() {
run_bls12_381_standalone(
&bls12_381::BlsG2Msm,
Expand All @@ -308,6 +319,7 @@ fn test_bls12_381_g2_mul_standalone() {
}

#[test]
#[ignore]
fn test_bls12_381_pair_standalone() {
run_bls12_381_standalone(
&bls12_381::BlsPairingCheck,
Expand All @@ -317,6 +329,7 @@ fn test_bls12_381_pair_standalone() {
}

#[test]
#[ignore]
fn test_bls12_381_map_fp_to_g1_standalone() {
run_bls12_381_standalone(
&bls12_381::BlsMapFpToG1,
Expand All @@ -326,6 +339,7 @@ fn test_bls12_381_map_fp_to_g1_standalone() {
}

#[test]
#[ignore]
fn test_bls12_381_map_fp2_to_g2_standalone() {
run_bls12_381_standalone(
&bls12_381::BlsMapFp2ToG2,
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/repro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn repro_8ru7VEA() {
block_timestamp: 1_648_829_935_343_349_589,
input_path: "src/tests/res/input_8ru7VEA.hex",
evm_gas_used: 1_732_181,
near_gas_used: 232,
near_gas_used: 231,
});
}

Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/uniswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn test_uniswap_input_multihop() {

let (_amount_out, _evm_gas, profile) = context.exact_input(&tokens, INPUT_AMOUNT.into());

assert_eq!(118, profile.all_gas() / 1_000_000_000_000);
assert_eq!(117, profile.all_gas() / 1_000_000_000_000);
}

#[test]
Expand Down

0 comments on commit 3bc45e0

Please sign in to comment.