Bandersnatch: ring-context generic over domain size (#2581)

Serialized length is now statically computed depending on the domain
size.

Opens the primitive to more generic usages not related to Sassafras
expectations

Address one point of
https://github.com/paritytech/polkadot-sdk/issues/2364
This commit is contained in:
Davide Galassi
2023-12-01 22:50:34 +01:00
committed by GitHub
parent 5789d6a7b4
commit ecfdb2b74f
3 changed files with 70 additions and 55 deletions
@@ -23,10 +23,16 @@ use sp_consensus_slots::Slot;
use sp_std::vec::Vec;
pub use sp_core::bandersnatch::{
ring_vrf::{RingContext, RingProver, RingVerifier, RingVerifierData, RingVrfSignature},
ring_vrf::{RingProver, RingVerifier, RingVerifierData, RingVrfSignature},
vrf::{VrfInput, VrfOutput, VrfSignData, VrfSignature},
};
/// Ring VRF domain size for Sassafras consensus.
pub const RING_VRF_DOMAIN_SIZE: u32 = 2048;
/// Bandersnatch VRF [`RingContext`] specialization for Sassafras using [`RING_VRF_DOMAIN_SIZE`].
pub type RingContext = sp_core::bandersnatch::ring_vrf::RingContext<RING_VRF_DOMAIN_SIZE>;
fn vrf_input_from_data(
domain: &[u8],
data: impl IntoIterator<Item = impl AsRef<[u8]>>,