Update serai-abi, and dependencies, to patch-polkadot-sdk

This commit is contained in:
Luke Parker
2025-09-01 20:02:48 -04:00
parent 3c6e889732
commit 53a64bc7e2
25 changed files with 1499 additions and 658 deletions

View File

@@ -41,6 +41,7 @@ impl ExternalCoin {
feature = "non_canonical_scale_derivations",
derive(scale::Encode, scale::Decode, scale::MaxEncodedLen)
)]
#[cfg_attr(feature = "non_canonical_scale_derivations", allow(clippy::cast_possible_truncation))]
#[cfg_attr(feature = "serde", derive(sp_core::serde::Serialize, sp_core::serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "sp_core::serde"))]
pub enum Coin {

View File

@@ -67,6 +67,7 @@ impl BorshDeserialize for Batch {
let read = self.reader.read(buf)?;
self.read = self.read.saturating_add(read);
if self.read > Batch::MAX_SIZE {
#[allow(clippy::io_other_error)]
Err(io::Error::new(io::ErrorKind::Other, "Batch size exceeded maximum"))?;
}
Ok(read)

View File

@@ -10,6 +10,7 @@ use crate::{address::ExternalAddress, balance::ExternalBalance};
feature = "non_canonical_scale_derivations",
derive(scale::Encode, scale::Decode, scale::MaxEncodedLen)
)]
#[cfg_attr(feature = "non_canonical_scale_derivations", allow(clippy::cast_possible_truncation))]
pub enum OutInstruction {
/// Transfer to the specified address.
Transfer(ExternalAddress),

View File

@@ -69,6 +69,8 @@ impl From<u64> for BlockNumber {
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Zeroize, BorshSerialize, BorshDeserialize)]
#[rustfmt::skip]
#[derive(scale::Encode, scale::Decode)] // This is safe as scale and borsh share an encoding here
#[cfg_attr(feature = "serde", derive(sp_core::serde::Serialize, sp_core::serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "sp_core::serde"))]
pub struct BlockHash(pub [u8; 32]);
impl From<[u8; 32]> for BlockHash {
fn from(hash: [u8; 32]) -> BlockHash {

View File

@@ -145,19 +145,6 @@ fn unbalanced_merkle_tree() {
let with_new = UnbalancedMerkleTree::new(tag, list_of_hashes.clone());
// Check `is_empty` works
assert_eq!(with_new.is_empty(), i == 0);
// The reference method, easy to audit, should have identical behavior to the optimized method
assert_eq!(
with_new,
UnbalancedMerkleTree::from_scale_encoded_list_of_hashes(tag, list_of_hashes.encode())
);
// The encoding of a slice should work the same as the encoding of a list
assert_eq!(
with_new,
UnbalancedMerkleTree::from_scale_encoded_list_of_hashes(
tag,
list_of_hashes.as_slice().encode()
)
);
// Check the incremental method produces an identical result
assert_eq!(incremental.clone().calculate(tag), with_new, "{i}");

View File

@@ -71,6 +71,7 @@ impl ExternalNetworkId {
feature = "non_canonical_scale_derivations",
derive(scale::Encode, scale::Decode, scale::MaxEncodedLen)
)]
#[cfg_attr(feature = "non_canonical_scale_derivations", allow(clippy::cast_possible_truncation))]
pub enum NetworkId {
/// The Serai network.
Serai,

View File

@@ -45,6 +45,7 @@ pub fn borsh_deserialize_bounded_vec<R: Read, T: BorshDeserialize, const B: u32>
reader.read_exact(&mut length[.. bytes_for_length])?;
let length = u32::from_le_bytes(length);
if length > B {
#[allow(clippy::io_other_error)]
Err(Error::new(ErrorKind::Other, "bound exceeded"))?;
}

View File

@@ -65,8 +65,24 @@ impl TryFrom<ValidatorSet> for ExternalValidatorSet {
impl ExternalValidatorSet {
/// The MuSig context for this validator set.
pub fn musig_context(&self) -> Vec<u8> {
borsh::to_vec(&(b"ValidatorSets-musig_key".as_ref(), self)).unwrap()
pub fn musig_context(&self) -> [u8; 32] {
let mut res = [0; 32];
const DST: &[u8] = b"ValidatorSets-musig_key";
res[0] = u8::try_from(DST.len()).unwrap();
#[allow(clippy::range_plus_one)]
res[1 .. (1 + DST.len())].copy_from_slice(DST);
// Check we have room to encode into `res`, using the approximate `size_of` for the max size of
// the serialization
const BYTES_FOR_SET: usize = 32 - (1 + DST.len());
const _ASSERT_MORE_BYTES_THAN_SIZE: [();
BYTES_FOR_SET - core::mem::size_of::<ExternalValidatorSet>()] = [(); _];
let encoded = borsh::to_vec(&self).unwrap();
res[(1 + DST.len()) .. (1 + DST.len() + encoded.len())].copy_from_slice(&encoded);
res
}
/// The MuSig public key for a validator set.
@@ -80,7 +96,7 @@ impl ExternalValidatorSet {
.expect("invalid participant"),
);
}
Public(dkg::musig::musig_key::<Ristretto>(&self.musig_context(), &keys).unwrap().to_bytes())
Public(dkg::musig_key::<Ristretto>(self.musig_context(), &keys).unwrap().to_bytes())
}
/// The message for the `set_keys` signature.

View File

@@ -24,6 +24,7 @@ fn downtime_per_slash_point(validators: NonZero<u16>) -> Duration {
feature = "non_canonical_scale_derivations",
derive(scale::Encode, scale::Decode, scale::MaxEncodedLen)
)]
#[cfg_attr(feature = "non_canonical_scale_derivations", allow(clippy::cast_possible_truncation))]
pub enum Slash {
/// The slash points accumulated by this validator.
///