Skip to content

update deps to point to relevant alloy branches #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
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
3 changes: 2 additions & 1 deletion .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- name: Check code coverage with cargo-tarpaulin
run: cargo-tarpaulin --workspace --all-features --out xml
- name: Upload to codecov.io
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["ethereum"]
categories = ["cryptography::cryptocurrencies"]

[dependencies]
tree_hash = { git = "https://github.com/KolbyML/tree_hash.git", rev = "8aaf8bb4184148768d48e2cfbbdd0b95d1da8730" }
tree_hash = { git = "https://github.com/eserilev/tree_hash", branch = "alloy-deps"}
ethereum_serde_utils = "0.5"
ethereum_ssz = "0.5"
serde = "1.0.0"
Expand All @@ -24,4 +24,4 @@ itertools = "0.10.0"

[dev-dependencies]
serde_json = "1.0.0"
tree_hash_derive = { git = "https://github.com/KolbyML/tree_hash.git", rev = "8aaf8bb4184148768d48e2cfbbdd0b95d1da8730" }
tree_hash_derive = { git = "https://github.com/eserilev/tree_hash", branch = "alloy-deps"}
35 changes: 35 additions & 0 deletions src/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,24 @@ impl<N: Unsigned + Clone> Bitfield<Variable<N>> {
pub fn is_subset(&self, other: &Self) -> bool {
self.difference(other).is_zero()
}

/// Returns a new BitList of length M, with the same bits set as `self`.
pub fn resize<M: Unsigned + Clone>(&self) -> Result<Bitfield<Variable<M>>, Error> {
if N::to_usize() > M::to_usize() {
return Err(Error::InvalidByteCount {
given: M::to_usize(),
expected: N::to_usize() + 1,
});
}

let mut resized = Bitfield::<Variable<M>>::with_capacity(M::to_usize())?;

for (i, bit) in self.iter().enumerate() {
resized.set(i, bit)?;
}

Ok(resized)
}
}

impl<N: Unsigned + Clone> Bitfield<Fixed<N>> {
Expand Down Expand Up @@ -1403,4 +1421,21 @@ mod bitlist {
fn size_of() {
assert_eq!(std::mem::size_of::<BitList1024>(), SMALLVEC_LEN + 24);
}

#[test]
fn resize() {
let mut bit_list = BitList1::with_capacity(1).unwrap();
bit_list.set(0, true).unwrap();
assert_eq!(bit_list.len(), 1);
assert_eq!(bit_list.num_set_bits(), 1);
assert_eq!(bit_list.highest_set_bit().unwrap(), 0);

let resized_bit_list = bit_list.resize::<typenum::U1024>().unwrap();
assert_eq!(resized_bit_list.len(), 1024);
assert_eq!(resized_bit_list.num_set_bits(), 1);
assert_eq!(resized_bit_list.highest_set_bit().unwrap(), 0);

// Can't extend a BitList to a smaller BitList
resized_bit_list.resize::<typenum::U16>().unwrap_err();
}
}
2 changes: 1 addition & 1 deletion src/fixed_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub use typenum;
/// assert_eq!(&long[..], &[1, 2, 3, 4, 0]);
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Derivative)]
#[derivative(PartialEq, Hash(bound = "T: std::hash::Hash"))]
#[derivative(PartialEq, Eq, Hash(bound = "T: std::hash::Hash"))]
#[serde(transparent)]
pub struct FixedVector<T, N> {
vec: Vec<T>,
Expand Down
Loading