From 8bb45203f9dfe90047f866cd5729e02edb19e35e Mon Sep 17 00:00:00 2001 From: Daniel Lubarov Date: Mon, 1 Aug 2022 17:40:16 -0700 Subject: [PATCH] More succinct deadbeef --- evm/src/cpu/kernel/tests/exp.rs | 8 +++----- evm/src/cpu/kernel/tests/rlp.rs | 14 ++++++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/evm/src/cpu/kernel/tests/exp.rs b/evm/src/cpu/kernel/tests/exp.rs index 388a1ac3..25bc5ad3 100644 --- a/evm/src/cpu/kernel/tests/exp.rs +++ b/evm/src/cpu/kernel/tests/exp.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - use anyhow::Result; use ethereum_types::U256; use rand::{thread_rng, Rng}; @@ -17,7 +15,7 @@ fn test_exp() -> Result<()> { let b = U256([0; 4].map(|_| rng.gen())); // Random input - let initial_stack = vec![U256::from_str("0xdeadbeef")?, b, a]; + let initial_stack = vec![0xDEADBEEFu32.into(), b, a]; let stack_with_kernel = run_with_kernel(&kernel, exp, initial_stack)? .stack() .to_vec(); @@ -29,7 +27,7 @@ fn test_exp() -> Result<()> { assert_eq!(stack_with_kernel, stack_with_opcode); // 0 base - let initial_stack = vec![U256::from_str("0xdeadbeef")?, b, U256::zero()]; + let initial_stack = vec![0xDEADBEEFu32.into(), b, U256::zero()]; let stack_with_kernel = run_with_kernel(&kernel, exp, initial_stack)? .stack() .to_vec(); @@ -41,7 +39,7 @@ fn test_exp() -> Result<()> { assert_eq!(stack_with_kernel, stack_with_opcode); // 0 exponent - let initial_stack = vec![U256::from_str("0xdeadbeef")?, U256::zero(), a]; + let initial_stack = vec![0xDEADBEEFu32.into(), U256::zero(), a]; let stack_with_kernel = run_with_kernel(&kernel, exp, initial_stack)? .stack() .to_vec(); diff --git a/evm/src/cpu/kernel/tests/rlp.rs b/evm/src/cpu/kernel/tests/rlp.rs index 55dfc7e8..cc311b4f 100644 --- a/evm/src/cpu/kernel/tests/rlp.rs +++ b/evm/src/cpu/kernel/tests/rlp.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - use anyhow::Result; use ethereum_types::U256; @@ -10,7 +8,7 @@ use crate::cpu::kernel::interpreter::Interpreter; fn test_decode_rlp_string_len_short() -> Result<()> { let decode_rlp_string_len = KERNEL.global_labels["decode_rlp_string_len"]; - let initial_stack = vec![U256::from_str("0xdeadbeef")?, 2.into()]; + let initial_stack = vec![0xDEADBEEFu32.into(), 2.into()]; let mut interpreter = Interpreter::new_with_kernel(decode_rlp_string_len, initial_stack); // A couple dummy bytes, followed by "0x70" which is its own encoding. @@ -27,7 +25,7 @@ fn test_decode_rlp_string_len_short() -> Result<()> { fn test_decode_rlp_string_len_medium() -> Result<()> { let decode_rlp_string_len = KERNEL.global_labels["decode_rlp_string_len"]; - let initial_stack = vec![U256::from_str("0xdeadbeef")?, 2.into()]; + let initial_stack = vec![0xDEADBEEFu32.into(), 2.into()]; let mut interpreter = Interpreter::new_with_kernel(decode_rlp_string_len, initial_stack); // A couple dummy bytes, followed by the RLP encoding of "1 2 3 4 5". @@ -44,7 +42,7 @@ fn test_decode_rlp_string_len_medium() -> Result<()> { fn test_decode_rlp_string_len_long() -> Result<()> { let decode_rlp_string_len = KERNEL.global_labels["decode_rlp_string_len"]; - let initial_stack = vec![U256::from_str("0xdeadbeef")?, 2.into()]; + let initial_stack = vec![0xDEADBEEFu32.into(), 2.into()]; let mut interpreter = Interpreter::new_with_kernel(decode_rlp_string_len, initial_stack); // The RLP encoding of the string "1 2 3 ... 56". @@ -65,7 +63,7 @@ fn test_decode_rlp_string_len_long() -> Result<()> { fn test_decode_rlp_list_len_short() -> Result<()> { let decode_rlp_list_len = KERNEL.global_labels["decode_rlp_list_len"]; - let initial_stack = vec![U256::from_str("0xdeadbeef")?, 0.into()]; + let initial_stack = vec![0xDEADBEEFu32.into(), 0.into()]; let mut interpreter = Interpreter::new_with_kernel(decode_rlp_list_len, initial_stack); // The RLP encoding of [1, 2, [3, 4]]. @@ -82,7 +80,7 @@ fn test_decode_rlp_list_len_short() -> Result<()> { fn test_decode_rlp_list_len_long() -> Result<()> { let decode_rlp_list_len = KERNEL.global_labels["decode_rlp_list_len"]; - let initial_stack = vec![U256::from_str("0xdeadbeef")?, 0.into()]; + let initial_stack = vec![0xDEADBEEFu32.into(), 0.into()]; let mut interpreter = Interpreter::new_with_kernel(decode_rlp_list_len, initial_stack); // The RLP encoding of [1, ..., 56]. @@ -103,7 +101,7 @@ fn test_decode_rlp_list_len_long() -> Result<()> { fn test_decode_rlp_scalar() -> Result<()> { let decode_rlp_scalar = KERNEL.global_labels["decode_rlp_scalar"]; - let initial_stack = vec![U256::from_str("0xdeadbeef")?, 0.into()]; + let initial_stack = vec![0xDEADBEEFu32.into(), 0.into()]; let mut interpreter = Interpreter::new_with_kernel(decode_rlp_scalar, initial_stack); // The RLP encoding of "12 34 56".