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
757 changes: 399 additions & 358 deletions Cargo.lock

Large diffs are not rendered by default.

88 changes: 44 additions & 44 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,52 @@ name = "reth-bsc"
path = "src/main.rs"

[dependencies]
reth = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-cli = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-cli-commands = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-basic-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-db = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-engine-local = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-discv4 = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e", features = ["test-utils"] }
reth-engine-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-ethereum-forks = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e", features = ["serde"] }
reth-ethereum-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-ethereum-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-eth-wire = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-eth-wire-types = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-evm = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-revm = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-network = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e", features = ["test-utils"] }
reth-network-p2p = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-network-api = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e", features = ["test-utils"] }
reth-network-peers = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-payload-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-primitives-traits = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-provider = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e", features = ["test-utils"] }
reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-rpc-engine-api = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-tracing = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-trie-common = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
reth-trie-db = { git = "https://github.com/paradigmxyz/reth", rev = "7b76a1e" }
revm = "27.0.2"
reth = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-cli = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-cli-commands = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-basic-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-db = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-engine-local = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-cli-util = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-discv4 = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b", features = ["test-utils"] }
reth-engine-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-ethereum-forks = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b", features = ["serde"] }
reth-ethereum-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-ethereum-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-eth-wire = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-eth-wire-types = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-evm = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-node-core = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-revm = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-network = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b", features = ["test-utils"] }
reth-network-p2p = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-network-api = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b", features = ["test-utils"] }
reth-network-peers = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-payload-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-primitives-traits = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-provider = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b", features = ["test-utils"] }
reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-rpc-engine-api = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-tracing = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-trie-common = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
reth-trie-db = { git = "https://github.com/paradigmxyz/reth", rev = "6487f0b" }
revm = "27.0.3"

# alloy dependencies
alloy-evm = "0.15"
alloy-evm = "0.16.1"

alloy-genesis = "1.0.17"
alloy-consensus = "1.0.17"
alloy-eips = "1.0.17"
alloy-network = "1.0.17"
alloy-rpc-types = { version = "1.0.17", features = ["engine"] }
alloy-rpc-types-eth = "1.0.17"
alloy-rpc-types-engine = "1.0.17"
alloy-signer = "1.0.17"
alloy-genesis = "1.0.22"
alloy-consensus = "1.0.22"
alloy-eips = "1.0.22"
alloy-network = "1.0.22"
alloy-rpc-types = { version = "1.0.22", features = ["engine"] }
alloy-rpc-types-eth = "1.0.22"
alloy-rpc-types-engine = "1.0.22"
alloy-signer = "1.0.22"

alloy-chains = "0.2.0"
alloy-rlp = { version = "0.3.10", default-features = false, features = ["core-net"] }
Expand Down Expand Up @@ -160,4 +160,4 @@ codegen-units = 16
[profile.maxperf]
inherits = "release"
lto = "fat"
codegen-units = 1
codegen-units = 1
26 changes: 14 additions & 12 deletions src/evm/precompiles/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ fn bls_signature_validation_run(input: &[u8], gas_limit: u64) -> PrecompileResul
return Err(PrecompileError::OutOfGas);
}

let revert = || Ok(PrecompileOutput::new_reverted(cost, Default::default()));

let msg_and_sig_length = BLS_MSG_HASH_LENGTH + BLS_SIGNATURE_LENGTH;
let input_length = input.len() as u64;
if (input_length <= msg_and_sig_length) ||
!((input_length - msg_and_sig_length).is_multiple_of(BLS_SINGLE_PUBKEY_LENGTH))
{
return Err(BscPrecompileError::Reverted(cost).into());
return revert()
}

let msg_hash: &Vec<u8> = &input[..BLS_MSG_HASH_LENGTH as usize].to_vec();
Expand All @@ -42,7 +44,7 @@ fn bls_signature_validation_run(input: &[u8], gas_limit: u64) -> PrecompileResul

// check signature format
if bls::signature_to_point(&signature.to_vec()).is_err() {
return Err(BscPrecompileError::Reverted(cost).into());
return revert()
}

let pub_key_count = (input_length - msg_and_sig_length) / BLS_SINGLE_PUBKEY_LENGTH;
Expand All @@ -54,13 +56,13 @@ fn bls_signature_validation_run(input: &[u8], gas_limit: u64) -> PrecompileResul
let pub_key = &pub_keys_data[i as usize * BLS_SINGLE_PUBKEY_LENGTH as usize..
(i + 1) as usize * BLS_SINGLE_PUBKEY_LENGTH as usize];
if !bls::key_validate(&pub_key.to_vec()) {
return Err(BscPrecompileError::Reverted(cost).into());
return revert()
}
pub_keys.push(pub_key.to_vec());
msg_hashes.push(msg_hash.clone().to_vec());
}
if pub_keys.is_empty() {
return Err(BscPrecompileError::Reverted(cost).into());
return revert()
}

// verify signature
Expand Down Expand Up @@ -141,8 +143,8 @@ mod tests {
input.extend_from_slice(&pub_key);

match bls_signature_validation_run(&Bytes::from(input.clone()), 100_000_000) {
Ok(_) => panic!("BLS signature validation failed, expect error"),
Err(e) => assert_eq!(e, BscPrecompileError::Reverted(4500).into()),
Ok(res) => assert_eq!(res, PrecompileOutput::new_reverted(4500, Default::default())),
Err(e) => panic!("BLS signature validation failed, expect error"),
}

// wrong pubkey
Expand All @@ -155,8 +157,8 @@ mod tests {
input.extend_from_slice(&pub_key);

match bls_signature_validation_run(&Bytes::from(input.clone()), 100_000_000) {
Ok(_) => panic!("BLS signature validation failed, expect error"),
Err(e) => assert_eq!(e, BscPrecompileError::Reverted(4500).into()),
Ok(res) => assert_eq!(res, PrecompileOutput::new_reverted(4500, Default::default())),
Err(e) => panic!("BLS signature validation failed, expect error"),
}
}

Expand Down Expand Up @@ -214,8 +216,8 @@ mod tests {
input.extend_from_slice(&pub_key3);

match bls_signature_validation_run(&Bytes::from(input.clone()), 100_000_000) {
Ok(_) => panic!("BLS signature validation failed, expect error"),
Err(e) => assert_eq!(e, BscPrecompileError::Reverted(11500).into()),
Ok(res) => assert_eq!(res, PrecompileOutput::new_reverted(11500, Default::default())),
Err(e) => panic!("BLS signature validation failed, expect error"),
}

// invalid pubkey
Expand All @@ -232,8 +234,8 @@ mod tests {
input.extend_from_slice(&pub_key3);

match bls_signature_validation_run(&Bytes::from(input.clone()), 100_000_000) {
Ok(_) => panic!("BLS signature validation failed, expect error"),
Err(e) => assert_eq!(e, BscPrecompileError::Reverted(11500).into()),
Ok(res) => assert_eq!(res, PrecompileOutput::new_reverted(11500, Default::default())),
Err(e) => panic!("BLS signature validation failed, expect error"),
}

// duplicate pubkey
Expand Down
30 changes: 16 additions & 14 deletions src/evm/precompiles/cometbft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ fn convert_light_block_from_proto(light_block_proto: &TmLightBlock) -> ConvertLi
let signed_header =
match SignedHeader::try_from(light_block_proto.signed_header.as_ref().unwrap().clone()) {
Ok(sh) => sh.clone(),
Err(_) => return Err(BscPrecompileError::CometBftInvalidInput.into()),
Err(_) => return Err(BscPrecompileError::InvalidInput.into()),
};

let validator_set =
match Set::try_from(light_block_proto.validator_set.as_ref().unwrap().clone()) {
Ok(vs) => vs.clone(),
Err(_) => return Err(BscPrecompileError::CometBftInvalidInput.into()),
Err(_) => return Err(BscPrecompileError::InvalidInput.into()),
};

let next_validator_set = validator_set.clone();
Expand All @@ -108,7 +108,7 @@ type DecodeLightBlockResult = Result<(ConsensusState, TmLightBlock), PrecompileE
fn decode_light_block_validation_input(input: &[u8]) -> DecodeLightBlockResult {
let input_length = input.len() as u64;
if input_length < CONSENSUS_STATE_LENGTH_BYTES_LENGTH {
return Err(BscPrecompileError::CometBftInvalidInput.into());
return Err(BscPrecompileError::InvalidInput.into());
}

let cs_length = u64::from_be_bytes(
Expand All @@ -120,11 +120,11 @@ fn decode_light_block_validation_input(input: &[u8]) -> DecodeLightBlockResult {
let input_length_checked = CONSENSUS_STATE_LENGTH_BYTES_LENGTH.checked_add(cs_length);
if input_length_checked.is_none() {
// overflow
return Err(BscPrecompileError::CometBftInvalidInput.into());
return Err(BscPrecompileError::InvalidInput.into());
}

if input_length < input_length_checked.unwrap() {
return Err(BscPrecompileError::CometBftInvalidInput.into());
return Err(BscPrecompileError::InvalidInput.into());
}

let decode_input = Bytes::from(
Expand All @@ -139,7 +139,7 @@ fn decode_light_block_validation_input(input: &[u8]) -> DecodeLightBlockResult {
.merge(&input[CONSENSUS_STATE_LENGTH_BYTES_LENGTH as usize + cs_length as usize..])
{
Ok(pb) => pb,
Err(_) => return Err(BscPrecompileError::CometBftInvalidInput.into()),
Err(_) => return Err(BscPrecompileError::InvalidInput.into()),
};

Ok((consensus_state, light_block_pb))
Expand All @@ -164,10 +164,10 @@ impl ConsensusState {

fn apply_light_block(&mut self, light_block: &LightBlock) -> Result<bool, PrecompileError> {
if light_block.height().value() <= self.height {
return Err(BscPrecompileError::CometBftInvalidInput.into());
return Err(BscPrecompileError::InvalidInput.into());
}
if light_block.signed_header.header().chain_id.as_str() != self.chain_id {
return Err(BscPrecompileError::CometBftInvalidInput.into());
return Err(BscPrecompileError::InvalidInput.into());
}

let vp = ProdPredicates;
Expand Down Expand Up @@ -300,7 +300,7 @@ fn decode_consensus_state(input: &Bytes) -> DecodeConsensusStateResult {
if input_length <= minimum_length ||
!(input_length - minimum_length).is_multiple_of(SINGLE_VALIDATOR_BYTES_LENGTH)
{
return Err(BscPrecompileError::CometBftInvalidInput.into());
return Err(BscPrecompileError::InvalidInput.into());
}

let mut pos = 0_u64;
Expand Down Expand Up @@ -344,7 +344,7 @@ fn decode_consensus_state(input: &Bytes) -> DecodeConsensusStateResult {
);
let pk = match PublicKey::from_raw_ed25519(&validator[..VALIDATOR_PUBKEY_LENGTH as usize]) {
Some(pk) => pk,
None => return Err(BscPrecompileError::CometBftInvalidInput.into()),
None => return Err(BscPrecompileError::InvalidInput.into()),
};
let vp = Power::from(voting_power as u32);
let validator_info = Validator::new_with_bls_and_relayer(
Expand Down Expand Up @@ -395,12 +395,13 @@ mod tests {
));

let result = cometbft_light_block_validation_run(&input, 100_000);
let PrecompileOutput { gas_used, bytes } = match result {
let PrecompileOutput { gas_used, bytes, reverted } = match result {
Ok(output) => output,
Err(_) => panic!("cometbft_light_block_validation_run failed"),
};
assert_eq!(gas_used, 3_000);
assert_eq!(bytes, except_output);
assert!(!reverted);
}
// apply light block failed
{
Expand All @@ -419,7 +420,7 @@ mod tests {
));

let result = cometbft_light_block_validation_run(&input, 100_000);
let expected = Err(BscPrecompileError::CometBftInvalidInput.into());
let expected = Err(BscPrecompileError::InvalidInput.into());
assert_eq!(result, expected);
}
// chain id mismatch
Expand All @@ -429,7 +430,7 @@ mod tests {
));

let result = cometbft_light_block_validation_run(&input, 100_000);
let expected = Err(BscPrecompileError::CometBftInvalidInput.into());
let expected = Err(BscPrecompileError::InvalidInput.into());
assert_eq!(result, expected);
}
}
Expand Down Expand Up @@ -680,11 +681,12 @@ mod tests {
));

let result = cometbft_light_block_validation_run_before_hertz(&input, 100_000);
let PrecompileOutput { gas_used, bytes } = match result {
let PrecompileOutput { gas_used, bytes, reverted } = match result {
Ok(output) => output,
Err(_) => panic!("cometbft_light_block_validation_run failed"),
};
assert_eq!(gas_used, 3_000);
assert_eq!(bytes, except_output_after_hertz);
assert!(!reverted);
}
}
Loading
Loading