mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-16 17:07:35 +00:00
parent
f4147c39b2
commit
2a05cf3225
19 changed files with 63 additions and 40 deletions
2
.github/nightly-version
vendored
2
.github/nightly-version
vendored
|
@ -1 +1 @@
|
|||
nightly-2024-05-01
|
||||
nightly-2024-06-01
|
||||
|
|
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -10975,6 +10975,7 @@ dependencies = [
|
|||
name = "zalloc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ repository = "https://github.com/serai-dex/serai/tree/develop/common/zalloc"
|
|||
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
|
||||
keywords = []
|
||||
edition = "2021"
|
||||
rust-version = "1.60"
|
||||
rust-version = "1.77.0"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
@ -19,8 +19,10 @@ workspace = true
|
|||
[dependencies]
|
||||
zeroize = { version = "^1.5", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
rustversion = { version = "1", default-features = false }
|
||||
|
||||
[features]
|
||||
std = ["zeroize/std"]
|
||||
default = ["std"]
|
||||
# Commented for now as it requires nightly and we don't use nightly
|
||||
# allocator = []
|
||||
allocator = []
|
||||
|
|
10
common/zalloc/build.rs
Normal file
10
common/zalloc/build.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
#[rustversion::nightly]
|
||||
fn main() {
|
||||
println!("cargo::rustc-check-cfg=cfg(zalloc_rustc_nightly)");
|
||||
println!("cargo::rustc-cfg=zalloc_rustc_nightly");
|
||||
}
|
||||
|
||||
#[rustversion::not(nightly)]
|
||||
fn main() {
|
||||
println!("cargo::rustc-check-cfg=cfg(zalloc_rustc_nightly)");
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
#![cfg_attr(feature = "allocator", feature(allocator_api))]
|
||||
#![cfg_attr(all(zalloc_rustc_nightly, feature = "allocator"), feature(allocator_api))]
|
||||
|
||||
//! Implementation of a Zeroizing Allocator, enabling zeroizing memory on deallocation.
|
||||
//! This can either be used with Box (requires nightly and the "allocator" feature) to provide the
|
||||
|
@ -17,12 +17,12 @@ use zeroize::Zeroize;
|
|||
/// An allocator wrapper which zeroizes its memory on dealloc.
|
||||
pub struct ZeroizingAlloc<T>(pub T);
|
||||
|
||||
#[cfg(feature = "allocator")]
|
||||
#[cfg(all(zalloc_rustc_nightly, feature = "allocator"))]
|
||||
use core::{
|
||||
ptr::NonNull,
|
||||
alloc::{AllocError, Allocator},
|
||||
};
|
||||
#[cfg(feature = "allocator")]
|
||||
#[cfg(all(zalloc_rustc_nightly, feature = "allocator"))]
|
||||
unsafe impl<T: Allocator> Allocator for ZeroizingAlloc<T> {
|
||||
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
|
||||
self.0.allocate(layout)
|
||||
|
|
|
@ -122,7 +122,7 @@ impl QueuedBatchesDb {
|
|||
|
||||
pub fn take(txn: &mut impl DbTxn, set: ValidatorSet) -> Vec<Transaction> {
|
||||
let batches_vec = Self::get(txn, set).unwrap_or_default();
|
||||
txn.del(&Self::key(set));
|
||||
txn.del(Self::key(set));
|
||||
|
||||
let mut batches: &[u8] = &batches_vec;
|
||||
let mut res = vec![];
|
||||
|
|
|
@ -177,14 +177,14 @@ impl<N: Network> BlockData<N> {
|
|||
let new_block = last_block_or_round(&mut txn, LATEST_BLOCK_KEY, self.number.0)?;
|
||||
if new_block {
|
||||
// Delete the latest round key
|
||||
txn.del(&key(LATEST_ROUND_KEY));
|
||||
txn.del(key(LATEST_ROUND_KEY));
|
||||
}
|
||||
let new_round = last_block_or_round(&mut txn, LATEST_ROUND_KEY, round_number.0.into())?;
|
||||
if new_block || new_round {
|
||||
// Delete the messages for the old round
|
||||
txn.del(&key(PROPOSE_KEY));
|
||||
txn.del(&key(PEVOTE_KEY));
|
||||
txn.del(&key(PRECOMMIT_KEY));
|
||||
txn.del(key(PROPOSE_KEY));
|
||||
txn.del(key(PEVOTE_KEY));
|
||||
txn.del(key(PRECOMMIT_KEY));
|
||||
}
|
||||
|
||||
// Check we haven't sent this message within this round
|
||||
|
|
|
@ -34,7 +34,7 @@ macro_rules! math_op {
|
|||
impl $Op<$Other> for $Value {
|
||||
type Output = $Value;
|
||||
fn $op_fn(self, other: $Other) -> Self::Output {
|
||||
Self($function(self.0, other.0))
|
||||
$Value($function(self.0, other.0))
|
||||
}
|
||||
}
|
||||
impl $Assign<$Other> for $Value {
|
||||
|
@ -45,7 +45,7 @@ macro_rules! math_op {
|
|||
impl<'a> $Op<&'a $Other> for $Value {
|
||||
type Output = $Value;
|
||||
fn $op_fn(self, other: &'a $Other) -> Self::Output {
|
||||
Self($function(self.0, other.0))
|
||||
$Value($function(self.0, other.0))
|
||||
}
|
||||
}
|
||||
impl<'a> $Assign<&'a $Other> for $Value {
|
||||
|
@ -60,7 +60,7 @@ macro_rules! from_wrapper {
|
|||
($wrapper: ident, $inner: ident, $uint: ident) => {
|
||||
impl From<$uint> for $wrapper {
|
||||
fn from(a: $uint) -> $wrapper {
|
||||
Self(Residue::new(&$inner::from(a)))
|
||||
$wrapper(Residue::new(&$inner::from(a)))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -127,7 +127,7 @@ macro_rules! field {
|
|||
impl Neg for $FieldName {
|
||||
type Output = $FieldName;
|
||||
fn neg(self) -> $FieldName {
|
||||
Self(self.0.neg())
|
||||
$FieldName(self.0.neg())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,13 +141,13 @@ macro_rules! field {
|
|||
impl $FieldName {
|
||||
/// Perform an exponentiation.
|
||||
pub fn pow(&self, other: $FieldName) -> $FieldName {
|
||||
let mut table = [Self(Residue::ONE); 16];
|
||||
let mut table = [$FieldName(Residue::ONE); 16];
|
||||
table[1] = *self;
|
||||
for i in 2 .. 16 {
|
||||
table[i] = table[i - 1] * self;
|
||||
}
|
||||
|
||||
let mut res = Self(Residue::ONE);
|
||||
let mut res = $FieldName(Residue::ONE);
|
||||
let mut bits = 0;
|
||||
for (i, mut bit) in other.to_le_bits().iter_mut().rev().enumerate() {
|
||||
bits <<= 1;
|
||||
|
@ -170,8 +170,8 @@ macro_rules! field {
|
|||
}
|
||||
|
||||
impl Field for $FieldName {
|
||||
const ZERO: Self = Self(Residue::ZERO);
|
||||
const ONE: Self = Self(Residue::ONE);
|
||||
const ZERO: Self = $FieldName(Residue::ZERO);
|
||||
const ONE: Self = $FieldName(Residue::ONE);
|
||||
|
||||
fn random(mut rng: impl RngCore) -> Self {
|
||||
let mut bytes = [0; 112];
|
||||
|
@ -188,12 +188,12 @@ macro_rules! field {
|
|||
|
||||
fn invert(&self) -> CtOption<Self> {
|
||||
const NEG_2: $FieldName =
|
||||
Self($ResidueType::sub(&$ResidueType::ZERO, &$ResidueType::new(&U448::from_u8(2))));
|
||||
$FieldName($ResidueType::sub(&$ResidueType::ZERO, &$ResidueType::new(&U448::from_u8(2))));
|
||||
CtOption::new(self.pow(NEG_2), !self.is_zero())
|
||||
}
|
||||
|
||||
fn sqrt(&self) -> CtOption<Self> {
|
||||
const MOD_1_4: $FieldName = Self($ResidueType::new(
|
||||
const MOD_1_4: $FieldName = $FieldName($ResidueType::new(
|
||||
&$MODULUS.saturating_add(&U448::ONE).wrapping_div(&U448::from_u8(4)),
|
||||
));
|
||||
|
||||
|
@ -217,14 +217,14 @@ macro_rules! field {
|
|||
const TWO_INV: Self = $FieldName($ResidueType::new(&U448::from_u8(2)).invert().0);
|
||||
|
||||
const MULTIPLICATIVE_GENERATOR: Self =
|
||||
Self(Residue::new(&U448::from_u8($MULTIPLICATIVE_GENERATOR)));
|
||||
$FieldName(Residue::new(&U448::from_u8($MULTIPLICATIVE_GENERATOR)));
|
||||
// True for both the Ed448 Scalar field and FieldElement field
|
||||
const S: u32 = 1;
|
||||
|
||||
// Both fields have their root of unity as -1
|
||||
const ROOT_OF_UNITY: Self =
|
||||
Self($ResidueType::sub(&$ResidueType::ZERO, &$ResidueType::new(&U448::ONE)));
|
||||
const ROOT_OF_UNITY_INV: Self = Self(Self::ROOT_OF_UNITY.0.invert().0);
|
||||
$FieldName($ResidueType::sub(&$ResidueType::ZERO, &$ResidueType::new(&U448::ONE)));
|
||||
const ROOT_OF_UNITY_INV: Self = $FieldName(Self::ROOT_OF_UNITY.0.invert().0);
|
||||
|
||||
const DELTA: Self = $FieldName(Residue::new(&U448::from_le_hex($DELTA)));
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ integrating with existing systems.
|
|||
|
||||
This library offers ciphersuites compatible with the
|
||||
[IETF draft](https://github.com/cfrg/draft-irtf-cfrg-frost). Currently, version
|
||||
11 is supported.
|
||||
15 is supported.
|
||||
|
||||
This library was
|
||||
[audited by Cypher Stack in March 2023](https://github.com/serai-dex/serai/raw/e1bb2c191b7123fd260d008e31656d090d559d21/audits/Cypher%20Stack%20crypto%20March%202023/Audit.pdf),
|
||||
|
|
|
@ -362,9 +362,7 @@ impl<C: Curve, A: Algorithm<C>> SignMachine<A::Signature> for AlgorithmSignMachi
|
|||
rho_transcript.append_message(b"message", C::hash_msg(msg));
|
||||
rho_transcript.append_message(
|
||||
b"preprocesses",
|
||||
&C::hash_commitments(
|
||||
self.params.algorithm.transcript().challenge(b"preprocesses").as_ref(),
|
||||
),
|
||||
C::hash_commitments(self.params.algorithm.transcript().challenge(b"preprocesses").as_ref()),
|
||||
);
|
||||
|
||||
// Generate the per-signer binding factors
|
||||
|
|
|
@ -52,7 +52,7 @@ fn test_rfc8032() {
|
|||
SchnorrSignature::<Ed25519>::read::<&[u8]>(&mut hex::decode(vector.2).unwrap().as_ref())
|
||||
.unwrap();
|
||||
let hram = Sha512::new_with_prefix(
|
||||
&[sig.R.to_bytes().as_ref(), &key.to_bytes(), &hex::decode(vector.1).unwrap()].concat(),
|
||||
[sig.R.to_bytes().as_ref(), &key.to_bytes(), &hex::decode(vector.1).unwrap()].concat(),
|
||||
);
|
||||
assert!(sig.verify(key, Scalar::from_hash(hram)));
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
Flexible Transcript is a crate offering:
|
||||
- `Transcript`, a trait offering functions transcripts should implement.
|
||||
- `DigestTranscript`, a competent transcript format instantiated against a
|
||||
provided hash function.
|
||||
provided hash function.
|
||||
- `MerlinTranscript`, a wrapper of `merlin` into the trait (available via the
|
||||
`merlin` feature).
|
||||
`merlin` feature).
|
||||
- `RecommendedTranscript`, a transcript recommended for usage in applications.
|
||||
Currently, this is `DigestTranscript<Blake2b512>` (available via the
|
||||
`recommended` feature).
|
||||
|
|
|
@ -231,7 +231,7 @@ impl ForwardedOutputDb {
|
|||
let res = InInstructionWithBalance::decode(&mut outputs_ref).unwrap();
|
||||
assert!(outputs_ref.len() < outputs.len());
|
||||
if outputs_ref.is_empty() {
|
||||
txn.del(&Self::key(balance));
|
||||
txn.del(Self::key(balance));
|
||||
} else {
|
||||
Self::set(txn, balance, &outputs);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,9 @@ std = [
|
|||
"coins-primitives/std",
|
||||
]
|
||||
|
||||
# TODO
|
||||
try-runtime = []
|
||||
|
||||
runtime-benchmarks = [
|
||||
"frame-system/runtime-benchmarks",
|
||||
"frame-support/runtime-benchmarks",
|
||||
|
|
|
@ -60,3 +60,6 @@ std = [
|
|||
"validator-sets-pallet/std",
|
||||
]
|
||||
default = ["std"]
|
||||
|
||||
# TODO
|
||||
try-runtime = []
|
||||
|
|
|
@ -57,4 +57,7 @@ runtime-benchmarks = [
|
|||
"frame-support/runtime-benchmarks",
|
||||
]
|
||||
|
||||
# TODO
|
||||
try-runtime = []
|
||||
|
||||
default = ["std"]
|
||||
|
|
|
@ -70,6 +70,9 @@ std = [
|
|||
"dex-pallet/std",
|
||||
]
|
||||
|
||||
# TODO
|
||||
try-runtime = []
|
||||
|
||||
runtime-benchmarks = [
|
||||
"frame-system/runtime-benchmarks",
|
||||
"frame-support/runtime-benchmarks",
|
||||
|
|
Loading…
Reference in a new issue