Skip to content

Commit

Permalink
update to schnorrkel 0.11.3
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilva committed Nov 28, 2023
1 parent 24c05ba commit 1caaab7
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 40 deletions.
45 changes: 35 additions & 10 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions polkadot/node/core/approval-voting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ parity-scale-codec = { version = "3.6.1", default-features = false, features = [
gum = { package = "tracing-gum", path = "../../gum" }
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
schnellru = "0.2.1"
merlin = "2.0"
schnorrkel = "0.9.1"
merlin = "3.0"
schnorrkel = "0.11.3"
kvdb = "0.13.0"
derive_more = "0.99.17"
thiserror = "1.0.48"
Expand All @@ -31,14 +31,14 @@ sp-consensus = { path = "../../../../substrate/primitives/consensus/common", def
sp-consensus-slots = { path = "../../../../substrate/primitives/consensus/slots", default-features = false }
sp-application-crypto = { path = "../../../../substrate/primitives/application-crypto", default-features = false, features = ["full_crypto"] }
sp-runtime = { path = "../../../../substrate/primitives/runtime", default-features = false }
rand_core = "0.5.1"
rand_core = "0.6.2"
rand_chacha = { version = "0.3.1" }
rand = "0.8.5"

[dev-dependencies]
async-trait = "0.1.57"
parking_lot = "0.12.0"
rand_core = "0.5.1" # should match schnorrkel
rand_core = "0.6.2" # should match schnorrkel
sp-keyring = { path = "../../../../substrate/primitives/keyring" }
sp-keystore = { path = "../../../../substrate/primitives/keystore" }
sp-core = { path = "../../../../substrate/primitives/core" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ fn dummy_assignment_cert(kind: AssignmentCertKind) -> AssignmentCert {
let mut prng = rand_core::OsRng;
let keypair = schnorrkel::Keypair::generate_with(&mut prng);
let (inout, proof, _) = keypair.vrf_sign(ctx.bytes(msg));
let out = inout.to_output();
let preout = inout.to_preout();

AssignmentCert { kind, vrf: VrfSignature { output: VrfOutput(out), proof: VrfProof(proof) } }
AssignmentCert { kind, vrf: VrfSignature { output: VrfOutput(preout), proof: VrfProof(proof) } }
}

fn make_block_entry_v1(
Expand Down
6 changes: 3 additions & 3 deletions polkadot/node/core/approval-voting/src/criteria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ fn compute_relay_vrf_modulo_assignments_v1(
let cert = AssignmentCert {
kind: AssignmentCertKind::RelayVRFModulo { sample: rvm_sample },
vrf: VrfSignature {
output: VrfOutput(vrf_in_out.to_output()),
output: VrfOutput(vrf_in_out.to_preout()),
proof: VrfProof(vrf_proof),
},
};
Expand Down Expand Up @@ -539,7 +539,7 @@ fn compute_relay_vrf_modulo_assignments_v2(
core_bitfield: assignment_bitfield.clone(),
},
vrf: VrfSignature {
output: VrfOutput(vrf_in_out.to_output()),
output: VrfOutput(vrf_in_out.to_preout()),
proof: VrfProof(vrf_proof),
},
};
Expand Down Expand Up @@ -574,7 +574,7 @@ fn compute_relay_vrf_delay_assignments(
let cert = AssignmentCertV2 {
kind: AssignmentCertKindV2::RelayVRFDelay { core_index: core },
vrf: VrfSignature {
output: VrfOutput(vrf_in_out.to_output()),
output: VrfOutput(vrf_in_out.to_preout()),
proof: VrfProof(vrf_proof),
},
};
Expand Down
11 changes: 7 additions & 4 deletions polkadot/node/core/approval-voting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ fn garbage_assignment_cert(kind: AssignmentCertKind) -> AssignmentCert {
let mut prng = rand_core::OsRng;
let keypair = schnorrkel::Keypair::generate_with(&mut prng);
let (inout, proof, _) = keypair.vrf_sign(ctx.bytes(msg));
let out = inout.to_output();
let preout = inout.to_preout();

AssignmentCert { kind, vrf: VrfSignature { output: VrfOutput(out), proof: VrfProof(proof) } }
AssignmentCert { kind, vrf: VrfSignature { output: VrfOutput(preout), proof: VrfProof(proof) } }
}

fn garbage_assignment_cert_v2(kind: AssignmentCertKindV2) -> AssignmentCertV2 {
Expand All @@ -426,9 +426,12 @@ fn garbage_assignment_cert_v2(kind: AssignmentCertKindV2) -> AssignmentCertV2 {
let mut prng = rand_core::OsRng;
let keypair = schnorrkel::Keypair::generate_with(&mut prng);
let (inout, proof, _) = keypair.vrf_sign(ctx.bytes(msg));
let out = inout.to_output();
let preout = inout.to_preout();

AssignmentCertV2 { kind, vrf: VrfSignature { output: VrfOutput(out), proof: VrfProof(proof) } }
AssignmentCertV2 {
kind,
vrf: VrfSignature { output: VrfOutput(preout), proof: VrfProof(proof) },
}
}

fn sign_approval(
Expand Down
4 changes: 2 additions & 2 deletions polkadot/node/network/approval-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
polkadot-primitives-test-helpers = { path = "../../../primitives/test-helpers" }

assert_matches = "1.4.0"
schnorrkel = { version = "0.9.1", default-features = false }
rand_core = "0.5.1" # should match schnorrkel
schnorrkel = { version = "0.11.3", default-features = false }
rand_core = "0.6.2" # should match schnorrkel
rand_chacha = "0.3.1"
env_logger = "0.9.0"
log = "0.4.17"
8 changes: 4 additions & 4 deletions polkadot/node/network/approval-distribution/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,14 @@ fn fake_assignment_cert(block_hash: Hash, validator: ValidatorIndex) -> Indirect
let mut prng = rand_core::OsRng;
let keypair = schnorrkel::Keypair::generate_with(&mut prng);
let (inout, proof, _) = keypair.vrf_sign(ctx.bytes(msg));
let out = inout.to_output();
let preout = inout.to_preout();

IndirectAssignmentCert {
block_hash,
validator,
cert: AssignmentCert {
kind: AssignmentCertKind::RelayVRFModulo { sample: 1 },
vrf: VrfSignature { output: VrfOutput(out), proof: VrfProof(proof) },
vrf: VrfSignature { output: VrfOutput(preout), proof: VrfProof(proof) },
},
}
}
Expand All @@ -320,14 +320,14 @@ fn fake_assignment_cert_v2(
let mut prng = rand_core::OsRng;
let keypair = schnorrkel::Keypair::generate_with(&mut prng);
let (inout, proof, _) = keypair.vrf_sign(ctx.bytes(msg));
let out = inout.to_output();
let preout = inout.to_preout();

IndirectAssignmentCertV2 {
block_hash,
validator,
cert: AssignmentCertV2 {
kind: AssignmentCertKindV2::RelayVRFModuloCompact { core_bitfield },
vrf: VrfSignature { output: VrfOutput(out), proof: VrfProof(proof) },
vrf: VrfSignature { output: VrfOutput(preout), proof: VrfProof(proof) },
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sp-keystore = { path = "../../../substrate/primitives/keystore" }
sp-maybe-compressed-blob = { path = "../../../substrate/primitives/maybe-compressed-blob" }
sp-runtime = { path = "../../../substrate/primitives/runtime" }
polkadot-parachain-primitives = { path = "../../parachain", default-features = false }
schnorrkel = "0.9.1"
schnorrkel = "0.11.3"
thiserror = "1.0.48"
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
serde = { version = "1.0.188", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions substrate/primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ array-bytes = { version = "6.1", optional = true }
ed25519-zebra = { version = "3.1.0", default-features = false, optional = true }
blake2 = { version = "0.10.4", default-features = false, optional = true }
libsecp256k1 = { version = "0.7", default-features = false, features = ["static-context"], optional = true }
schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"], default-features = false }
merlin = { version = "2.0", default-features = false }
schnorrkel = { version = "0.11.3", features = ["preaudit_deprecated"], default-features = false }
merlin = { version = "3.0", default-features = false }
secp256k1 = { version = "0.24.0", default-features = false, features = ["recovery", "alloc"], optional = true }
sp-core-hashing = { path = "hashing", default-features = false, optional = true }
sp-runtime-interface = { path = "../runtime-interface", default-features = false}
Expand Down
17 changes: 9 additions & 8 deletions substrate/primitives/core/src/sr25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ pub mod vrf {
use crate::crypto::{VrfCrypto, VrfPublic};
use schnorrkel::{
errors::MultiSignatureStage,
vrf::{VRF_OUTPUT_LENGTH, VRF_PROOF_LENGTH},
vrf::{VRF_PREOUT_LENGTH, VRF_PROOF_LENGTH},
SignatureError,
};

Expand Down Expand Up @@ -636,7 +636,7 @@ pub mod vrf {

/// VRF output type suitable for schnorrkel operations.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct VrfOutput(pub schnorrkel::vrf::VRFOutput);
pub struct VrfOutput(pub schnorrkel::vrf::VRFPreOut);

impl Encode for VrfOutput {
fn encode(&self) -> Vec<u8> {
Expand All @@ -646,19 +646,19 @@ pub mod vrf {

impl Decode for VrfOutput {
fn decode<R: codec::Input>(i: &mut R) -> Result<Self, codec::Error> {
let decoded = <[u8; VRF_OUTPUT_LENGTH]>::decode(i)?;
Ok(Self(schnorrkel::vrf::VRFOutput::from_bytes(&decoded).map_err(convert_error)?))
let decoded = <[u8; VRF_PREOUT_LENGTH]>::decode(i)?;
Ok(Self(schnorrkel::vrf::VRFPreOut::from_bytes(&decoded).map_err(convert_error)?))
}
}

impl MaxEncodedLen for VrfOutput {
fn max_encoded_len() -> usize {
<[u8; VRF_OUTPUT_LENGTH]>::max_encoded_len()
<[u8; VRF_PREOUT_LENGTH]>::max_encoded_len()
}
}

impl TypeInfo for VrfOutput {
type Identity = [u8; VRF_OUTPUT_LENGTH];
type Identity = [u8; VRF_PREOUT_LENGTH];

fn type_info() -> scale_info::Type {
Self::Identity::type_info()
Expand Down Expand Up @@ -717,11 +717,11 @@ pub mod vrf {

let proof = self.0.dleq_proove(extra, &inout, true).0;

VrfSignature { output: VrfOutput(inout.to_output()), proof: VrfProof(proof) }
VrfSignature { output: VrfOutput(inout.to_preout()), proof: VrfProof(proof) }
}

fn vrf_output(&self, input: &Self::VrfInput) -> Self::VrfOutput {
let output = self.0.vrf_create_hash(input.0.clone()).to_output();
let output = self.0.vrf_create_hash(input.0.clone()).to_preout();
VrfOutput(output)
}
}
Expand Down Expand Up @@ -762,6 +762,7 @@ pub mod vrf {
ScalarFormatError => "Signature error: `ScalarFormatError`".into(),
NotMarkedSchnorrkel => "Signature error: `NotMarkedSchnorrkel`".into(),
BytesLengthError { .. } => "Signature error: `BytesLengthError`".into(),
InvalidKey => "Signature error: `InvalidKey`".into(),
MuSigAbsent { musig_stage: Commitment } =>
"Signature error: `MuSigAbsent` at stage `Commitment`".into(),
MuSigAbsent { musig_stage: Reveal } =>
Expand Down

0 comments on commit 1caaab7

Please sign in to comment.