From e97e8188334d4a8a6a9f4a1e46ea59e8636af986 Mon Sep 17 00:00:00 2001 From: Nicholas Ward Date: Wed, 15 Mar 2023 19:25:51 -0700 Subject: [PATCH] fixed iszero and cleanup --- evm/src/cpu/kernel/tests/bignum.rs | 33 ++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/evm/src/cpu/kernel/tests/bignum.rs b/evm/src/cpu/kernel/tests/bignum.rs index 3e53995b..bce91295 100644 --- a/evm/src/cpu/kernel/tests/bignum.rs +++ b/evm/src/cpu/kernel/tests/bignum.rs @@ -76,12 +76,11 @@ fn prepare_bignum_min(_bit_size: usize) -> (BigUint, U256, Vec) { (a, length, a_limbs) } -fn prepare_bignum_from_test_data(i: usize) -> (BigUint, U256, Vec) { - let a = test_data()[i].clone(); +fn prepare_bignum_from_value(a: BigUint) -> (BigUint, U256, Vec) { let length: U256 = bignum_len(&a).into(); let a_limbs = biguint_to_mem_vec(a.clone()); - (a, length, a_limbs) + (a.clone(), length, a_limbs) } fn prepare_two_bignums_random(bit_size: usize) -> (BigUint, BigUint, U256, Vec) { @@ -128,13 +127,11 @@ fn prepare_two_bignums_zero(_bit_size: usize) -> (BigUint, BigUint, U256, Vec (BigUint, BigUint, U256, Vec) { - let a = test_data()[i].clone(); - let b = test_data()[j].clone(); +fn prepare_two_bignums_from_values(a: BigUint, b: BigUint) -> (BigUint, BigUint, U256, Vec) { let length: U256 = bignum_len(&a).into(); let memory = pad_bignums(&[a.clone(), b.clone()], length.try_into().unwrap()); - (a, b, length, memory) + (a.clone(), b.clone(), length, memory) } fn test_shr_bignum(prepare_bignum_fn: &F) -> Result<()> @@ -372,7 +369,7 @@ fn test_shr_bignum_all() -> Result<()> { let test_data = test_data(); for i in 0..test_data.len() { - test_shr_bignum(&|_| prepare_bignum_from_test_data(i))?; + test_shr_bignum(&|_| prepare_bignum_from_value(test_data[i].clone()))?; } Ok(()) @@ -386,7 +383,9 @@ fn test_iszero_bignum_all() -> Result<()> { let test_data = test_data(); for i in 0..test_data.len() { - test_iszero_bignum(&|_| prepare_bignum_from_test_data(i))?; + if test_data[i] != 0u8.into() { + test_iszero_bignum(&|_| prepare_bignum_from_value(test_data[i].clone()))?; + } } Ok(()) @@ -402,7 +401,9 @@ fn test_cmp_bignum_all() -> Result<()> { let test_data = test_data(); for i in 0..test_data.len() { for j in 0..i { - test_cmp_bignum(&|_| prepare_two_bignums_from_test_data(i, j))?; + test_cmp_bignum(&|_| { + prepare_two_bignums_from_values(test_data[i].clone(), test_data[j].clone()) + })?; } } @@ -420,7 +421,9 @@ fn test_add_bignum_all() -> Result<()> { let test_data = test_data(); for i in 0..test_data.len() { for j in 0..i { - test_add_bignum(&|_| prepare_two_bignums_from_test_data(i, j))?; + test_add_bignum(&|_| { + prepare_two_bignums_from_values(test_data[i].clone(), test_data[j].clone()) + })?; } } @@ -438,7 +441,9 @@ fn test_addmul_bignum_all() -> Result<()> { let test_data = test_data(); for i in 0..test_data.len() { for j in 0..i { - test_addmul_bignum(&|_| prepare_two_bignums_from_test_data(i, j))?; + test_addmul_bignum(&|_| { + prepare_two_bignums_from_values(test_data[i].clone(), test_data[j].clone()) + })?; } } @@ -456,7 +461,9 @@ fn test_mul_bignum_all() -> Result<()> { let test_data = test_data(); for i in 0..test_data.len() { for j in 0..i { - test_mul_bignum(&|_| prepare_two_bignums_from_test_data(i, j))?; + test_mul_bignum(&|_| { + prepare_two_bignums_from_values(test_data[i].clone(), test_data[j].clone()) + })?; } }