Skip to content
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

Arkworks Elliptic Curve utils overhaul #1870

Merged
merged 6 commits into from
Oct 16, 2023
Merged
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
174 changes: 9 additions & 165 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion substrate/primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ sp-runtime-interface = { path = "../runtime-interface", default-features = false
# bls crypto
w3f-bls = { version = "0.1.3", default-features = false, optional = true}
# bandersnatch crypto
bandersnatch_vrfs = { git = "https://github.com/w3f/ring-vrf", rev = "f4fe253", default-features = false, optional = true }
bandersnatch_vrfs = { git = "https://github.com/w3f/ring-vrf", rev = "4b09416", default-features = false, optional = true }

[dev-dependencies]
criterion = "0.4.0"
Expand Down
33 changes: 9 additions & 24 deletions substrate/primitives/core/src/bandersnatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,7 @@ const PREOUT_SERIALIZED_LEN: usize = 33;
//
// This size is dependent on the ring domain size and the actual value
// is equal to the SCALE encoded size of the `KZG` backend.
//
// Some values:
// ring_size → ~serialized_size
// 512 → 74 KB
// 1024 → 147 KB
// 2048 → 295 KB
// NOTE: This is quite big but looks like there is an upcoming fix
// in the backend.
const RING_CONTEXT_SERIALIZED_LEN: usize = 147748;
const RING_CONTEXT_SERIALIZED_LEN: usize = 147716;

/// Bandersnatch public key.
#[cfg_attr(feature = "full_crypto", derive(Hash))]
Expand Down Expand Up @@ -538,10 +530,7 @@ pub mod vrf {
#[cfg(feature = "full_crypto")]
impl Pair {
fn vrf_sign_gen<const N: usize>(&self, data: &VrfSignData) -> VrfSignature {
let ios = core::array::from_fn(|i| {
let input = data.inputs[i].0.clone();
self.secret.vrf_inout(input)
});
let ios = core::array::from_fn(|i| self.secret.vrf_inout(data.inputs[i].0));

let thin_signature: ThinVrfSignature<N> =
self.secret.sign_thin_vrf(data.transcript.clone(), &ios);
Expand All @@ -567,7 +556,7 @@ pub mod vrf {
input: &VrfInput,
) -> [u8; N] {
let transcript = Transcript::new_labeled(context);
let inout = self.secret.vrf_inout(input.0.clone());
let inout = self.secret.vrf_inout(input.0);
inout.vrf_output_bytes(transcript)
}
}
Expand All @@ -583,7 +572,7 @@ pub mod vrf {
};

let preouts: [bandersnatch_vrfs::VrfPreOut; N] =
core::array::from_fn(|i| signature.outputs[i].0.clone());
core::array::from_fn(|i| signature.outputs[i].0);

// Deserialize only the proof, the rest has already been deserialized
// This is another hack used because backend signature type is generic over
Expand All @@ -596,7 +585,7 @@ pub mod vrf {
};
let signature = ThinVrfSignature { proof, preouts };

let inputs = data.inputs.iter().map(|i| i.0.clone());
let inputs = data.inputs.iter().map(|i| i.0);

public.verify_thin_vrf(data.transcript.clone(), inputs, &signature).is_ok()
}
Expand All @@ -610,8 +599,7 @@ pub mod vrf {
input: &VrfInput,
) -> [u8; N] {
let transcript = Transcript::new_labeled(context);
let inout =
bandersnatch_vrfs::VrfInOut { input: input.0.clone(), preoutput: self.0.clone() };
let inout = bandersnatch_vrfs::VrfInOut { input: input.0, preoutput: self.0 };
inout.vrf_output_bytes(transcript)
}
}
Expand Down Expand Up @@ -733,10 +721,7 @@ pub mod ring_vrf {
data: &VrfSignData,
prover: &RingProver,
) -> RingVrfSignature {
let ios = core::array::from_fn(|i| {
let input = data.inputs[i].0.clone();
self.secret.vrf_inout(input)
});
let ios = core::array::from_fn(|i| self.secret.vrf_inout(data.inputs[i].0));

let ring_signature: bandersnatch_vrfs::RingVrfSignature<N> =
bandersnatch_vrfs::RingProver { ring_prover: prover, secret: &self.secret }
Expand Down Expand Up @@ -792,12 +777,12 @@ pub mod ring_vrf {
};

let preouts: [bandersnatch_vrfs::VrfPreOut; N] =
core::array::from_fn(|i| self.outputs[i].0.clone());
core::array::from_fn(|i| self.outputs[i].0);

let signature =
bandersnatch_vrfs::RingVrfSignature { proof: vrf_signature.proof, preouts };

let inputs = data.inputs.iter().map(|i| i.0.clone());
let inputs = data.inputs.iter().map(|i| i.0);

bandersnatch_vrfs::RingVerifier(verifier)
.verify_ring_vrf(data.transcript.clone(), inputs, &signature)
Expand Down
Loading
Loading