Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Use ralexstokes ssz-rs crate after it has been no-std enabled. (parit…
Browse files Browse the repository at this point in the history
…ytech#767)

Co-authored-by: claravanstaden <Cats 4 life!>
  • Loading branch information
claravanstaden authored Jan 24, 2023
1 parent 7c80678 commit 2ed1155
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
10 changes: 2 additions & 8 deletions parachain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions parachain/pallets/ethereum-beacon-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ serde = { version = "1.0.137", optional = true }
codec = { version = "3.1.5", package = "parity-scale-codec", default-features = false, features = [ "derive" ] }
scale-info = { version = "2.2.0", default-features = false, features = [ "derive" ] }
milagro_bls = { git = "https://github.com/Snowfork/milagro_bls", default-features = false }
ssz-rs = { git = "https://github.com/Snowfork/ssz_rs", default-features = false, rev="f55915f7f96943109345b164e89342eef1aeb6e3" }
ssz-rs-derive = { git = "https://github.com/Snowfork/ssz_rs", default-features = false, rev="f55915f7f96943109345b164e89342eef1aeb6e3" }
ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs", default-features = false, rev="d18af912abacbf84219be37ab3b42a9abcf10d2a" }
ssz-rs-derive = { git = "https://github.com/ralexstokes/ssz-rs", default-features = false, rev="d18af912abacbf84219be37ab3b42a9abcf10d2a" }
byte-slice-cast = { version = "1.2.1", default-features = false }
rlp = { version = "0.5", default-features = false }
hex-literal = { version = "0.3.1", optional = true }
Expand Down
17 changes: 13 additions & 4 deletions parachain/pallets/ethereum-beacon-client/src/merkleization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub enum MerkleizationError {
HashTreeRootError,
HashTreeRootInvalidBytes,
InvalidLength,
InputTooShort,
ExtraInput,
ExpectedFurtherInput { provided: u64, expected: u64 },
AdditionalInput { provided: u64, expected: u64 },
InvalidInput,
DeserializeError,
ListError,
Expand Down Expand Up @@ -483,10 +483,19 @@ pub fn get_sync_committee_bits<SyncCommitteeBitsSize: Get<u32>>(
bits_hex: BoundedVec<u8, SyncCommitteeBitsSize>,
) -> Result<Vec<u8>, MerkleizationError> {
let bitv = Bitvector::<{ config::SYNC_COMMITTEE_SIZE }>::deserialize(&bits_hex).map_err(
//|_| MerkleizationError::InvalidInput
|e| -> MerkleizationError {
match e {
DeserializeError::InputTooShort => MerkleizationError::InputTooShort,
DeserializeError::ExtraInput => MerkleizationError::ExtraInput,
DeserializeError::ExpectedFurtherInput { provided, expected } =>
MerkleizationError::ExpectedFurtherInput {
provided: provided as u64,
expected: expected as u64,
},
DeserializeError::AdditionalInput { provided, expected } =>
MerkleizationError::AdditionalInput {
provided: provided as u64,
expected: expected as u64,
},
_ => MerkleizationError::InvalidInput,
}
},
Expand Down
10 changes: 8 additions & 2 deletions parachain/pallets/ethereum-beacon-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ mod beacon_tests {
mock_minimal::MaxSyncCommitteeSize,
>(bits.try_into().expect("invalid sync committee bits"));

assert_err!(sync_committee_bits, MerkleizationError::InputTooShort);
assert_err!(
sync_committee_bits,
MerkleizationError::ExpectedFurtherInput { provided: 47, expected: 64 }
);
}

#[test]
Expand All @@ -341,7 +344,10 @@ mod beacon_tests {
mock_minimal::MaxSyncCommitteeSize,
>(bits.try_into().expect("invalid sync committee bits"));

assert_err!(sync_committee_bits, MerkleizationError::ExtraInput);
assert_err!(
sync_committee_bits,
MerkleizationError::AdditionalInput { provided: 130, expected: 64 }
);
}

#[test]
Expand Down

0 comments on commit 2ed1155

Please sign in to comment.