Modify ecrecover tests

This commit is contained in:
wborgeaud 2022-07-18 16:41:17 +02:00
parent 15ee891778
commit f9ec4e8e7d
2 changed files with 5 additions and 12 deletions

View File

@ -35,6 +35,7 @@ pub(crate) fn get_opcode(mnemonic: &str) -> u8 {
"SHR" => 0x1c,
"SAR" => 0x1d,
"KECCAK256" => 0x20,
"SHA3" => 0x20,
"ADDRESS" => 0x30,
"BALANCE" => 0x31,
"ORIGIN" => 0x32,

View File

@ -1,20 +1,13 @@
use std::str::FromStr;
use anyhow::Result;
use ethereum_types::U256;
use keccak_hash::keccak;
use crate::cpu::kernel::aggregator::combined_kernel;
use crate::cpu::kernel::assembler::Kernel;
use crate::cpu::kernel::interpreter::run;
use crate::cpu::kernel::tests::u256ify;
fn pubkey_to_addr(x: U256, y: U256) -> Vec<u8> {
let mut buf = [0; 64];
x.to_big_endian(&mut buf[0..32]);
y.to_big_endian(&mut buf[32..64]);
let hash = keccak(buf);
hash.0[12..].to_vec()
}
fn test_valid_ecrecover(
hash: &str,
v: &str,
@ -24,10 +17,9 @@ fn test_valid_ecrecover(
kernel: &Kernel,
) -> Result<()> {
let ecrecover = kernel.global_labels["ecrecover"];
let initial_stack = u256ify([s, r, v, hash])?;
let initial_stack = u256ify(["0xdeadbeef", s, r, v, hash])?;
let stack = run(&kernel.code, ecrecover, initial_stack).stack;
let got = pubkey_to_addr(stack[1], stack[0]);
assert_eq!(got, hex::decode(&expected[2..]).unwrap());
assert_eq!(stack[0], U256::from_str(expected).unwrap());
Ok(())
}