mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-13 14:39:25 +00:00
Inline the eVRF into the DKG library
Due to how we're handling share encryption, we'd either need two circuits or to dedicate this circuit to the DKG. The latter makes sense at this time.
This commit is contained in:
@@ -36,13 +36,26 @@ multiexp = { path = "../multiexp", version = "0.4", default-features = false }
|
|||||||
schnorr = { package = "schnorr-signatures", path = "../schnorr", version = "^0.5.1", default-features = false }
|
schnorr = { package = "schnorr-signatures", path = "../schnorr", version = "^0.5.1", default-features = false }
|
||||||
dleq = { path = "../dleq", version = "^0.4.1", default-features = false }
|
dleq = { path = "../dleq", version = "^0.4.1", default-features = false }
|
||||||
|
|
||||||
|
# eVRF DKG dependencies
|
||||||
|
subtle = { version = "2", default-features = false, features = ["std"], optional = true }
|
||||||
|
generic-array = { version = "1", default-features = false, features = ["alloc"], optional = true }
|
||||||
|
rand_chacha = { version = "0.3", default-features = false, features = ["std"], optional = true }
|
||||||
|
blake2 = { version = "0.10", default-features = false, features = ["std"], optional = true }
|
||||||
generalized-bulletproofs = { path = "../evrf/generalized-bulletproofs", default-features = false, optional = true }
|
generalized-bulletproofs = { path = "../evrf/generalized-bulletproofs", default-features = false, optional = true }
|
||||||
ec-divisors = { path = "../evrf/divisors", default-features = false, optional = true }
|
ec-divisors = { path = "../evrf/divisors", default-features = false, optional = true }
|
||||||
evrf = { path = "../evrf", default-features = false, optional = true }
|
generalized-bulletproofs-circuit-abstraction = { path = "./circuit-abstraction", optional = true }
|
||||||
|
generalized-bulletproofs-ec-gadgets = { path = "./ec-gadgets", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
|
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
|
||||||
ciphersuite = { path = "../ciphersuite", default-features = false, features = ["ristretto"] }
|
ciphersuite = { path = "../ciphersuite", default-features = false, features = ["ristretto"] }
|
||||||
|
generalized-bulletproofs = { path = "./generalized-bulletproofs", features = ["tests"] }
|
||||||
|
ec-divisors = { path = "./divisors", features = ["pasta"] }
|
||||||
|
pasta_curves = "0.5"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
generalized-bulletproofs-circuit-abstraction = { path = "./circuit-abstraction" }
|
||||||
|
generalized-bulletproofs-ec-gadgets = { path = "./ec-gadgets" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
std = [
|
std = [
|
||||||
@@ -66,6 +79,6 @@ std = [
|
|||||||
"dleq/serialize"
|
"dleq/serialize"
|
||||||
]
|
]
|
||||||
borsh = ["dep:borsh"]
|
borsh = ["dep:borsh"]
|
||||||
evrf = ["std", "dep:ec-divisors", "dep:generalized-bulletproofs", "dep:evrf"]
|
evrf = ["std", "dep:subtle", "dep:generic-array", "dep:rand_chacha", "dep:blake2", "dep:ec-divisors", "dep:generalized-bulletproofs", "dep:evrf"]
|
||||||
tests = ["rand_core/getrandom"]
|
tests = ["rand_core/getrandom"]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "evrf"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = "Implementation of an eVRF premised on Generalized Bulletproofs"
|
|
||||||
license = "MIT"
|
|
||||||
repository = "https://github.com/serai-dex/serai/tree/develop/crypto/evrf"
|
|
||||||
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
|
|
||||||
keywords = ["ciphersuite", "ff", "group"]
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
|
||||||
all-features = true
|
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
subtle = { version = "2", default-features = false, features = ["std"] }
|
|
||||||
zeroize = { version = "^1.5", default-features = false, features = ["zeroize_derive"] }
|
|
||||||
|
|
||||||
rand_core = { version = "0.6", default-features = false, features = ["std"] }
|
|
||||||
rand_chacha = { version = "0.3", default-features = false, features = ["std"] }
|
|
||||||
|
|
||||||
generic-array = { version = "1", default-features = false, features = ["alloc"] }
|
|
||||||
|
|
||||||
blake2 = { version = "0.10", default-features = false, features = ["std"] }
|
|
||||||
ciphersuite = { path = "../ciphersuite", version = "0.4", default-features = false, features = ["std"] }
|
|
||||||
|
|
||||||
ec-divisors = { path = "./divisors" }
|
|
||||||
generalized-bulletproofs = { path = "./generalized-bulletproofs" }
|
|
||||||
generalized-bulletproofs-circuit-abstraction = { path = "./circuit-abstraction" }
|
|
||||||
generalized-bulletproofs-ec-gadgets = { path = "./ec-gadgets" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
generalized-bulletproofs = { path = "./generalized-bulletproofs", features = ["tests"] }
|
|
||||||
ec-divisors = { path = "./divisors", features = ["pasta"] }
|
|
||||||
pasta_curves = "0.5"
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 Luke Parker
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
# eVRF
|
|
||||||
|
|
||||||
An implementation of an [eVRF](https://eprint.iacr.org/2024/397.pdf) premised on
|
|
||||||
[Generalized Bulletproofs](https://repo.getmonero.org/monero-project/ccs-proposals/uploads/a9baa50c38c6312efc0fea5c6a188bb9/gbp.pdf).
|
|
||||||
@@ -18,7 +18,10 @@ use crate::{backend::u8_from_bool, Scalar, FieldElement};
|
|||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn B() -> FieldElement {
|
fn B() -> FieldElement {
|
||||||
FieldElement::from_repr(hex_literal::hex!("5f07603a853f20370b682036210d463e64903a23ea669d07ca26cfc13f594209")).unwrap()
|
FieldElement::from_repr(hex_literal::hex!(
|
||||||
|
"5f07603a853f20370b682036210d463e64903a23ea669d07ca26cfc13f594209"
|
||||||
|
))
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recover_y(x: FieldElement) -> CtOption<FieldElement> {
|
fn recover_y(x: FieldElement) -> CtOption<FieldElement> {
|
||||||
@@ -196,13 +199,13 @@ impl Group for Point {
|
|||||||
}
|
}
|
||||||
fn generator() -> Self {
|
fn generator() -> Self {
|
||||||
Point {
|
Point {
|
||||||
x: FieldElement::from_repr(
|
x: FieldElement::from_repr(hex_literal::hex!(
|
||||||
hex_literal::hex!("0100000000000000000000000000000000000000000000000000000000000000")
|
"0100000000000000000000000000000000000000000000000000000000000000"
|
||||||
)
|
))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
y: FieldElement::from_repr(
|
y: FieldElement::from_repr(hex_literal::hex!(
|
||||||
hex_literal::hex!("2e4118080a484a3dfbafe2199a0e36b7193581d676c0dadfa376b0265616020c")
|
"2e4118080a484a3dfbafe2199a0e36b7193581d676c0dadfa376b0265616020c"
|
||||||
)
|
))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
z: FieldElement::ONE,
|
z: FieldElement::ONE,
|
||||||
}
|
}
|
||||||
@@ -336,11 +339,11 @@ impl GroupEncoding for Point {
|
|||||||
let point = y.map(|y| Point { x, y, z: FieldElement::ONE });
|
let point = y.map(|y| Point { x, y, z: FieldElement::ONE });
|
||||||
|
|
||||||
let not_negative_zero = !(is_identity & sign);
|
let not_negative_zero = !(is_identity & sign);
|
||||||
// Only return the point if it isn't -0 and the sign byte wasn't malleated
|
// Only return the point if it isn't -0
|
||||||
CtOption::conditional_select(
|
CtOption::conditional_select(
|
||||||
&CtOption::new(Point::identity(), 0.into()),
|
&CtOption::new(Point::identity(), 0.into()),
|
||||||
&point,
|
&point,
|
||||||
not_negative_zero & ((bytes[0] & 1).ct_eq(&bytes[0])),
|
not_negative_zero,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user