Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bor-consensus/src/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mod tests {
// Known test vector: sign a hash with a known private key
// Using the secp256k1 identity: signing keccak256("test") with a known key
use alloy_primitives::keccak256;
use k256::ecdsa::{SigningKey, signature::hazmat::PrehashSigner};
use k256::ecdsa::SigningKey;

let msg_hash = keccak256(b"test message for seal verification");

Expand Down
12 changes: 4 additions & 8 deletions crates/bor-consensus/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ mod tests {
use alloy_primitives::{keccak256, Address};
use std::collections::BTreeMap;

fn make_signers(count: usize) -> Vec<Address> {
(0..count)
.map(|i| Address::new([(i + 1) as u8; 20]))
.collect()
}


fn make_extra_data_with_seal(seal: &[u8; 65]) -> Vec<u8> {
let mut data = vec![0u8; 32]; // vanity
Expand Down Expand Up @@ -254,7 +250,7 @@ mod tests {
#[test]
fn test_reject_wrong_difficulty() {
// Use a real key to create a valid signature
use k256::ecdsa::{SigningKey, signature::hazmat::PrehashSigner};
use k256::ecdsa::SigningKey;

let secret_bytes: [u8; 32] = keccak256(b"test_difficulty_key").0;
let signing_key = SigningKey::from_bytes((&secret_bytes).into()).unwrap();
Expand Down Expand Up @@ -291,7 +287,7 @@ mod tests {
#[test]
fn test_validate_known_header() {
// Create a valid header with known key
use k256::ecdsa::{SigningKey, signature::hazmat::PrehashSigner};
use k256::ecdsa::SigningKey;

let secret_bytes: [u8; 32] = keccak256(b"known_validator_key").0;
let signing_key = SigningKey::from_bytes((&secret_bytes).into()).unwrap();
Expand Down Expand Up @@ -367,7 +363,7 @@ mod tests {

#[test]
fn test_reject_unauthorized_signer() {
use k256::ecdsa::{SigningKey, signature::hazmat::PrehashSigner};
use k256::ecdsa::SigningKey;

let secret_bytes: [u8; 32] = keccak256(b"unauthorized_key").0;
let signing_key = SigningKey::from_bytes((&secret_bytes).into()).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/bor-consensus/tests/stress_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn test_concurrent_header_verification_no_panics() {

for thread_id in 0..NUM_THREADS {
let signers = Arc::clone(&signers);
let snapshot = Arc::clone(&snapshot);
let _snapshot = Arc::clone(&snapshot);

let handle = thread::spawn(move || {
let recents = BTreeMap::new();
Expand All @@ -77,7 +77,7 @@ fn test_concurrent_header_verification_no_panics() {
difficulty: U256::from(5),
extra_data: vec![0u8; 97],
gas_limit: 30_000_000,
seal_hash: keccak256(&block_number.to_be_bytes()),
seal_hash: keccak256(block_number.to_be_bytes()),
has_ommers: false,
};

Expand Down
5 changes: 1 addition & 4 deletions crates/bor-evm/src/system_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ mod tests {
let data = call.call_data();
// Starts with selector
assert_eq!(&data[..4], &COMMIT_SPAN_SELECTOR);
// First param: uint256 = 42
let span_id_offset = 4;
// ABI encoded: offset to bytes (64), then uint256 span_id at offset 0
// Actually with abi_encode_params for (uint256, bytes): span_id, offset, length, data
// ABI encoded: span_id, offset, length, data
assert!(data.len() > 4 + 32); // At least selector + one word
}

Expand Down
10 changes: 5 additions & 5 deletions crates/bor-node/tests/integration_amoy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn test_amoy_genesis_initialization() {
#[test]
fn test_amoy_first_100_blocks_simulated() {
let config = BorNodeConfig::amoy();
let node = BorNode::new(config).unwrap();
let _node = BorNode::new(config).unwrap();

let validators = vec![
Address::new([0x01; 20]),
Expand Down Expand Up @@ -51,7 +51,7 @@ fn test_amoy_first_100_blocks_simulated() {
difficulty,
extra_data: vec![0u8; 97],
gas_limit: 30_000_000,
seal_hash: keccak256(&block_number.to_be_bytes()),
seal_hash: keccak256(block_number.to_be_bytes()),
has_ommers: false,
};
let parent = ParentValidationParams {
Expand All @@ -62,7 +62,7 @@ fn test_amoy_first_100_blocks_simulated() {
// Pre-execution validation (no span start in first 100 blocks with span_size=6400)
validate_block_pre_execution(
block_number,
&vec![0u8; 97],
&[0u8; 97],
false,
false,
6400,
Expand All @@ -76,8 +76,8 @@ fn test_amoy_first_100_blocks_simulated() {
assert!(!plan.execute_commit_span);

// Post-execution: verify matching roots
let state_root = keccak256(&block_number.to_be_bytes());
let receipt_root = keccak256(&(block_number + 1000).to_be_bytes());
let state_root = keccak256(block_number.to_be_bytes());
let receipt_root = keccak256((block_number + 1000).to_be_bytes());
validate_block_post_execution(
&state_root,
&state_root,
Expand Down
4 changes: 2 additions & 2 deletions crates/bor-node/tests/integration_delhi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn test_delhi_sprint_size_transition() {

#[test]
fn test_delhi_boundary_blocks() {
let node = BorNode::new(BorNodeConfig::mainnet()).unwrap();
let _node = BorNode::new(BorNodeConfig::mainnet()).unwrap();

// Simulate blocks around Delhi boundary
for block in (DELHI_BLOCK - 16)..=(DELHI_BLOCK + 16) {
Expand All @@ -31,7 +31,7 @@ fn test_delhi_boundary_blocks() {
// Pre-execution validation should pass for normal blocks
validate_block_pre_execution(
block,
&vec![0u8; 97],
&[0u8; 97],
false,
false,
6400, // span_size doesn't change at Delhi
Expand Down
8 changes: 4 additions & 4 deletions crates/bor-node/tests/integration_madhugiri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use alloy_primitives::{B256, keccak256};
use bor_chainspec::BorHardfork;
use bor_consensus::block_validation::{validate_block_pre_execution, validate_block_post_execution};
use bor_consensus::block_validation::validate_block_post_execution;
use bor_storage::{is_post_madhugiri, store_block_receipts, compute_receipt_root};
use bor_node::{BorNode, BorNodeConfig};

Expand Down Expand Up @@ -34,7 +34,7 @@ fn test_post_madhugiri_unified_receipt_storage() {

#[test]
fn test_madhugiri_boundary_blocks() {
let node = BorNode::new(BorNodeConfig::mainnet()).unwrap();
let _node = BorNode::new(BorNodeConfig::mainnet()).unwrap();

// Pre-Madhugiri block: Bor receipt excluded from receipt root
let regular_hashes = vec![B256::from([0x01; 32]), B256::from([0x02; 32])];
Expand All @@ -59,8 +59,8 @@ fn test_madhugiri_fork_active() {
#[test]
fn test_madhugiri_boundary_post_execution() {
// Simulate post-execution at the exact boundary
let state_root = keccak256(&MADHUGIRI_BLOCK.to_be_bytes());
let receipt_root = keccak256(&(MADHUGIRI_BLOCK + 1).to_be_bytes());
let state_root = keccak256(MADHUGIRI_BLOCK.to_be_bytes());
let receipt_root = keccak256((MADHUGIRI_BLOCK + 1).to_be_bytes());

// Both state root and receipt root must match
validate_block_post_execution(
Expand Down
4 changes: 2 additions & 2 deletions crates/bor-node/tests/integration_rio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn test_rio_span_size_transition() {

#[test]
fn test_rio_boundary_blocks() {
let node = BorNode::new(BorNodeConfig::mainnet()).unwrap();
let _node = BorNode::new(BorNodeConfig::mainnet()).unwrap();

// Simulate blocks around Rio boundary
for block in (RIO_BLOCK - 8)..=(RIO_BLOCK + 8) {
Expand All @@ -36,7 +36,7 @@ fn test_rio_boundary_blocks() {
if !is_span_start {
validate_block_pre_execution(
block,
&vec![0u8; 97],
&[0u8; 97],
false,
false,
current_span_size,
Expand Down
6 changes: 3 additions & 3 deletions crates/bor-node/tests/integration_state_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn test_1000_consecutive_blocks_post_lisovo() {
if !is_span_start {
validate_block_pre_execution(
block,
&vec![0u8; 97],
&[0u8; 97],
false,
false,
current_span_size,
Expand Down Expand Up @@ -106,8 +106,8 @@ fn test_1000_consecutive_blocks_post_lisovo() {
assert!(is_post, "block {block} should be post-Madhugiri");

// 6. Post-execution: simulate matching roots
let state_root = keccak256(&block.to_be_bytes());
let receipt_root = keccak256(&(block + 1).to_be_bytes());
let state_root = keccak256(block.to_be_bytes());
let receipt_root = keccak256((block + 1).to_be_bytes());
validate_block_post_execution(
&state_root,
&state_root,
Expand Down
2 changes: 1 addition & 1 deletion crates/bor-storage/src/receipt_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod tests {
fn test_legacy_key_computation() {
let block_number: u64 = 12345;
let key = bor_receipt_key_legacy(block_number);
let expected = alloy_primitives::keccak256(&block_number.to_be_bytes());
let expected = alloy_primitives::keccak256(block_number.to_be_bytes());
assert_eq!(key, expected);

// Different block numbers yield different keys
Expand Down
18 changes: 9 additions & 9 deletions crates/bor-storage/tests/receipt_key_crosscheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bor_storage::receipt_key::{bor_receipt_key, bor_receipt_key_legacy};
/// Go's borReceiptKey computes keccak256 of the big-endian u64 block number.
/// This mirrors that computation exactly.
fn go_bor_receipt_key_legacy(block_number: u64) -> B256 {
keccak256(&block_number.to_be_bytes())
keccak256(block_number.to_be_bytes())
}

/// Go's new receipt key computes keccak256 of the block hash bytes.
Expand Down Expand Up @@ -61,10 +61,10 @@ fn test_hash_key_matches_go() {
keccak256(b"polygon_bor_block_80084801"),
keccak256(b"polygon_bor_block_99999999"),
// Simulate typical block hashes
keccak256(&[1u8; 32]),
keccak256(&[2u8; 32]),
keccak256(&100u64.to_be_bytes()),
keccak256(&80_084_800u64.to_be_bytes()),
keccak256([1u8; 32]),
keccak256([2u8; 32]),
keccak256(100u64.to_be_bytes()),
keccak256(80_084_800u64.to_be_bytes()),
];

for hash in &test_hashes {
Expand All @@ -82,25 +82,25 @@ fn test_hash_key_matches_go() {
fn test_encoding_is_fixed_8_byte_big_endian() {
// Block 0 should hash [0,0,0,0,0,0,0,0] (8 zero bytes)
let key_0 = bor_receipt_key_legacy(0);
let expected = keccak256(&[0u8; 8]);
let expected = keccak256([0u8; 8]);
assert_eq!(key_0, expected, "Block 0 key should hash 8 zero bytes");

// Block 1 should hash [0,0,0,0,0,0,0,1]
let key_1 = bor_receipt_key_legacy(1);
let expected = keccak256(&[0, 0, 0, 0, 0, 0, 0, 1u8]);
let expected = keccak256([0, 0, 0, 0, 0, 0, 0, 1u8]);
assert_eq!(key_1, expected, "Block 1 key should hash [0,0,0,0,0,0,0,1]");

// Block 256 should hash [0,0,0,0,0,0,1,0]
let key_256 = bor_receipt_key_legacy(256);
let expected = keccak256(&[0, 0, 0, 0, 0, 0, 1, 0u8]);
let expected = keccak256([0, 0, 0, 0, 0, 0, 1, 0u8]);
assert_eq!(key_256, expected, "Block 256 key encoding");
}

/// Legacy and hash keys should produce different results for related inputs.
#[test]
fn test_legacy_vs_hash_key_different() {
let block_number = 80_084_800u64;
let block_hash = keccak256(&block_number.to_be_bytes());
let block_hash = keccak256(block_number.to_be_bytes());

let legacy_key = bor_receipt_key_legacy(block_number);
let hash_key = bor_receipt_key(&block_hash);
Expand Down
Loading