Migrate from ethereum-types to alloy-primitives (#6078)

* Remove use of ethers_core::RlpStream

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into remove_use_of_ethers_core

* Remove old code

* Simplify keccak call

* Remove unused package

* Merge branch 'unstable' of https://github.com/ethDreamer/lighthouse into remove_use_of_ethers_core

* Merge branch 'unstable' into remove_use_of_ethers_core

* Run clippy

* Merge branch 'remove_use_of_ethers_core' of https://github.com/dospore/lighthouse into remove_use_of_ethers_core

* Check all cargo fmt

* migrate to alloy primitives init

* fix deps

* integrate alloy-primitives

* resolve dep issues

* more changes based on dep changes

* add TODOs

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into remove_use_of_ethers_core

* Revert lock

* Add BeaconBlocksByRange v3

* continue migration

* Revert "Add BeaconBlocksByRange v3"

This reverts commit e3ce7fc5ea.

* impl hash256 extended trait

* revert some uneeded diffs

* merge conflict resolved

* fix subnet id rshift calc

* rename to FixedBytesExtended

* debugging

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into migrate-to-alloy-primitives

* fix failed test

* fixing more tests

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into remove_use_of_ethers_core

* introduce a shim to convert between the two u256 types

* move alloy to wrokspace

* align alloy versions

* update

* update web3signer test certs

* refactor

* resolve failing tests

* linting

* fix graffiti string test

* fmt

* fix ef test

* resolve merge conflicts

* remove udep and revert cert

* cargo patch

* cyclic dep

* fix build error

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into migrate-to-alloy-primitives

* resolve conflicts, update deps

* merge unstable

* fmt

* fix deps

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into migrate-to-alloy-primitives

* resolve merge conflicts

* resolve conflicts, make necessary changes

* Remove patch

* fmt

* remove file

* merge conflicts

* sneaking in a smol change

* bump versions

* Merge remote-tracking branch 'origin/unstable' into migrate-to-alloy-primitives

* Updates for peerDAS

* Update ethereum_hashing to prevent dupe

* updated alloy-consensus, removed TODOs

* cargo update

* endianess fix

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into migrate-to-alloy-primitives

* fmt

* fix merge

* fix test

* fixed_bytes crate

* minor fixes

* convert u256 to i64

* panic free mixin to_low_u64_le

* from_str_radix

* computbe_subnet api and ensuring we use big-endian

* Merge branch 'unstable' of https://github.com/sigp/lighthouse into migrate-to-alloy-primitives

* fix test

* Simplify subnet_id test

* Simplify some more tests

* Add tests to fixed_bytes crate

* Merge branch 'unstable' into migrate-to-alloy-primitives
This commit is contained in:
Eitan Seri-Levi
2024-09-02 01:03:24 -07:00
committed by GitHub
parent 002ca2cdeb
commit 99e53b88c3
152 changed files with 1050 additions and 718 deletions

View File

@@ -5,6 +5,7 @@ authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = { workspace = true }
[dependencies]
alloy-primitives = { workspace = true }
ethereum_ssz = { workspace = true }
tree_hash = { workspace = true }
rand = { workspace = true }
@@ -12,10 +13,11 @@ serde = { workspace = true }
ethereum_serde_utils = { workspace = true }
hex = { workspace = true }
ethereum_hashing = { workspace = true }
ethereum-types = { workspace = true }
arbitrary = { workspace = true }
zeroize = { workspace = true }
blst = { version = "0.3.3", optional = true }
safe_arith = { workspace = true }
fixed_bytes = { workspace = true }
[features]
arbitrary = []

View File

@@ -68,7 +68,7 @@ pub fn verify_signature_sets<'a>(
}
// Grab a slice of the message, to satisfy the blst API.
msgs_refs.push(set.message.as_bytes());
msgs_refs.push(set.message.as_slice());
if let Some(point) = set.signature.point() {
// Subgroup check the signature
@@ -196,7 +196,7 @@ impl TSignature<blst_core::PublicKey> for blst_core::Signature {
fn verify(&self, pubkey: &blst_core::PublicKey, msg: Hash256) -> bool {
// Public keys have already been checked for subgroup and infinity
// Check Signature inside function for subgroup
self.verify(true, msg.as_bytes(), DST, &[], pubkey, false) == BLST_ERROR::BLST_SUCCESS
self.verify(true, msg.as_slice(), DST, &[], pubkey, false) == BLST_ERROR::BLST_SUCCESS
}
}
@@ -256,7 +256,7 @@ impl TAggregateSignature<blst_core::PublicKey, BlstAggregatePublicKey, blst_core
let signature = self.0.clone().to_signature();
// Public keys are already valid due to PoP
// Check Signature inside function for subgroup
signature.fast_aggregate_verify(true, msg.as_bytes(), DST, &pubkeys)
signature.fast_aggregate_verify(true, msg.as_slice(), DST, &pubkeys)
== BLST_ERROR::BLST_SUCCESS
}
@@ -266,7 +266,7 @@ impl TAggregateSignature<blst_core::PublicKey, BlstAggregatePublicKey, blst_core
pubkeys: &[&GenericPublicKey<blst_core::PublicKey>],
) -> bool {
let pubkeys = pubkeys.iter().map(|pk| pk.point()).collect::<Vec<_>>();
let msgs = msgs.iter().map(|hash| hash.as_bytes()).collect::<Vec<_>>();
let msgs = msgs.iter().map(|hash| hash.as_slice()).collect::<Vec<_>>();
let signature = self.0.clone().to_signature();
// Public keys have already been checked for subgroup and infinity
// Check Signature inside function for subgroup
@@ -287,7 +287,7 @@ impl TSecretKey<blst_core::Signature, blst_core::PublicKey> for blst_core::Secre
}
fn sign(&self, msg: Hash256) -> blst_core::Signature {
self.sign(msg.as_bytes(), DST, &[])
self.sign(msg.as_slice(), DST, &[])
}
fn serialize(&self) -> ZeroizeHash {

View File

@@ -44,7 +44,8 @@ pub use zeroize_hash::ZeroizeHash;
#[cfg(feature = "supranational")]
use blst::BLST_ERROR as BlstError;
pub type Hash256 = ethereum_types::H256;
pub type Hash256 = fixed_bytes::Hash256;
pub use fixed_bytes::FixedBytesExtended;
#[derive(Clone, Debug, PartialEq)]
pub enum Error {

View File

@@ -1,4 +1,4 @@
use bls::{Hash256, INFINITY_SIGNATURE, SECRET_KEY_BYTES_LEN};
use bls::{FixedBytesExtended, Hash256, INFINITY_SIGNATURE, SECRET_KEY_BYTES_LEN};
use ssz::{Decode, Encode};
use std::borrow::Cow;
use std::fmt::Debug;