mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
test(execution): chain test state check, execution bug fixes/upgrades (#472)
* temp: header stage backoff stand-in * feat(execution): Check chain post state, fix StateProviderLatest and evm return * Disable receipt merkle tree check * update and merge * Fix storage double values in dup table * fmt * Update bin/reth/src/test_eth_chain/runner.rs Co-authored-by: Georgios Konstantopoulos <me@gakonst.com> * Enable receipt root check after byzantium * Receipt inner rlp without header for proof root * some cleanup nits * nit Co-authored-by: Oliver Nordbjerg <hi@notbjerg.me> Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
@ -2,7 +2,6 @@ use crate::{keccak256, Header, Log, Receipt, TransactionSigned, H256};
|
||||
use hash_db::Hasher;
|
||||
use hex_literal::hex;
|
||||
use plain_hasher::PlainHasher;
|
||||
use reth_rlp::Encodable;
|
||||
use triehash::ordered_trie_root;
|
||||
|
||||
/// Keccak-256 hash of the RLP of an empty list, KEC("\xc0").
|
||||
@ -46,12 +45,12 @@ pub fn calculate_transaction_root<'a>(
|
||||
pub fn calculate_receipt_root<'a>(receipts: impl Iterator<Item = &'a Receipt>) -> H256 {
|
||||
ordered_trie_root::<KeccakHasher, _>(receipts.into_iter().map(|receipt| {
|
||||
let mut receipt_rlp = Vec::new();
|
||||
receipt.encode(&mut receipt_rlp);
|
||||
receipt.encode_inner(&mut receipt_rlp, false);
|
||||
receipt_rlp
|
||||
}))
|
||||
}
|
||||
|
||||
/// Calculates the log root for a header.
|
||||
/// Calculates the log root for headers.
|
||||
pub fn calculate_log_root<'a>(logs: impl Iterator<Item = &'a Log> + Clone) -> H256 {
|
||||
//https://github.com/ethereum/go-ethereum/blob/356bbe343a30789e77bb38f25983c8f2f2bfbb47/cmd/evm/internal/t8ntool/execution.go#L255
|
||||
let mut logs_rlp = Vec::new();
|
||||
@ -69,7 +68,13 @@ pub fn calculate_ommers_root<'a>(ommers: impl Iterator<Item = &'a Header> + Clon
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{hex_literal::hex, proofs::calculate_transaction_root, Block};
|
||||
|
||||
use crate::{
|
||||
hex_literal::hex,
|
||||
proofs::{calculate_receipt_root, calculate_transaction_root},
|
||||
Block, Bloom, Log, Receipt, TxType, H160, H256,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use reth_rlp::Decodable;
|
||||
|
||||
#[test]
|
||||
@ -81,4 +86,23 @@ mod tests {
|
||||
let tx_root = calculate_transaction_root(block.body.iter());
|
||||
assert_eq!(block.transactions_root, tx_root, "Should be same");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_receipt_root() {
|
||||
let logs = vec![Log { address: H160::zero(), topics: vec![], data: Bytes::default() }];
|
||||
let bloom = Bloom(hex!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"));
|
||||
let receipt = Receipt {
|
||||
tx_type: TxType::EIP2930,
|
||||
success: true,
|
||||
cumulative_gas_used: 102068,
|
||||
bloom,
|
||||
logs,
|
||||
};
|
||||
let receipt = vec![receipt];
|
||||
let root = calculate_receipt_root(receipt.iter());
|
||||
assert_eq!(
|
||||
root,
|
||||
H256(hex!("fe70ae4a136d98944951b2123859698d59ad251a381abc9960fa81cae3d0d4a0"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ impl Receipt {
|
||||
}
|
||||
|
||||
/// Encodes the receipt data.
|
||||
fn encode_receipt(&self, out: &mut dyn BufMut) {
|
||||
fn encode_fields(&self, out: &mut dyn BufMut) {
|
||||
self.receipt_rlp_header().encode(out);
|
||||
self.success.encode(out);
|
||||
self.cumulative_gas_used.encode(out);
|
||||
@ -44,6 +44,34 @@ impl Receipt {
|
||||
self.logs.encode(out);
|
||||
}
|
||||
|
||||
/// Encode receipt with or without the header data.
|
||||
pub fn encode_inner(&self, out: &mut dyn BufMut, with_header: bool) {
|
||||
if matches!(self.tx_type, TxType::Legacy) {
|
||||
self.encode_fields(out);
|
||||
return
|
||||
}
|
||||
|
||||
let mut payload = BytesMut::new();
|
||||
self.encode_fields(&mut payload);
|
||||
|
||||
if with_header {
|
||||
let payload_length = payload.len() + 1;
|
||||
let header = reth_rlp::Header { list: false, payload_length };
|
||||
header.encode(out);
|
||||
}
|
||||
|
||||
match self.tx_type {
|
||||
TxType::EIP2930 => {
|
||||
out.put_u8(0x01);
|
||||
}
|
||||
TxType::EIP1559 => {
|
||||
out.put_u8(0x02);
|
||||
}
|
||||
_ => unreachable!("legacy handled; qed."),
|
||||
}
|
||||
out.put_slice(payload.as_ref());
|
||||
}
|
||||
|
||||
/// Returns the length of the receipt data.
|
||||
fn receipt_length(&self) -> usize {
|
||||
let rlp_head = self.receipt_rlp_header();
|
||||
@ -90,29 +118,7 @@ impl Encodable for Receipt {
|
||||
payload_len
|
||||
}
|
||||
fn encode(&self, out: &mut dyn BufMut) {
|
||||
if matches!(self.tx_type, TxType::Legacy) {
|
||||
self.encode_receipt(out);
|
||||
return
|
||||
}
|
||||
|
||||
let mut payload = BytesMut::new();
|
||||
self.encode_receipt(&mut payload);
|
||||
let payload_length = payload.len() + 1;
|
||||
|
||||
let header = reth_rlp::Header { list: false, payload_length };
|
||||
header.encode(out);
|
||||
|
||||
match self.tx_type {
|
||||
TxType::EIP2930 => {
|
||||
out.put_u8(0x01);
|
||||
}
|
||||
TxType::EIP1559 => {
|
||||
out.put_u8(0x02);
|
||||
}
|
||||
_ => unreachable!("legacy handled; qed."),
|
||||
}
|
||||
|
||||
out.put_slice(payload.as_ref());
|
||||
self.encode_inner(out, true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,15 +159,15 @@ impl Decodable for Receipt {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{Address, H256};
|
||||
use ethers_core::{types::Bytes, utils::hex};
|
||||
use crate::{hex_literal::hex, Address, H256};
|
||||
use ethers_core::types::Bytes;
|
||||
use reth_rlp::{Decodable, Encodable};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
// Test vector from: https://eips.ethereum.org/EIPS/eip-2481
|
||||
fn encode_legacy_receipt() {
|
||||
let expected = hex::decode("f901668001b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85ff85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff").unwrap();
|
||||
let expected = hex!("f901668001b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85ff85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff");
|
||||
|
||||
let mut data = vec![];
|
||||
let receipt = Receipt {
|
||||
@ -195,7 +201,7 @@ mod tests {
|
||||
#[test]
|
||||
// Test vector from: https://eips.ethereum.org/EIPS/eip-2481
|
||||
fn decode_legacy_receipt() {
|
||||
let data = hex::decode("f901668001b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85ff85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff").unwrap();
|
||||
let data = hex!("f901668001b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85ff85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff");
|
||||
|
||||
// EIP658Receipt
|
||||
let expected = Receipt {
|
||||
|
||||
Reference in New Issue
Block a user