June 2024 nightly update

Replaces #571.
This commit is contained in:
Luke Parker 2024-06-01 21:46:47 -04:00
parent f4147c39b2
commit 2a05cf3225
No known key found for this signature in database
19 changed files with 63 additions and 40 deletions

View file

@ -1 +1 @@
nightly-2024-05-01 nightly-2024-06-01

1
Cargo.lock generated
View file

@ -10975,6 +10975,7 @@ dependencies = [
name = "zalloc" name = "zalloc"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"rustversion",
"zeroize", "zeroize",
] ]

View file

@ -105,13 +105,13 @@ pub struct Metadata {
/// but the payment ID will be returned here anyway: /// but the payment ID will be returned here anyway:
/// ///
/// 1) If the payment ID is tied to an output received by a subaddress account /// 1) If the payment ID is tied to an output received by a subaddress account
/// that spent Monero in the transaction (the received output is considered /// that spent Monero in the transaction (the received output is considered
/// "change" and is not considered a "payment" in this case). If there are multiple /// "change" and is not considered a "payment" in this case). If there are multiple
/// spending subaddress accounts in a transaction, the highest index spent key image /// spending subaddress accounts in a transaction, the highest index spent key image
/// is used to determine the spending subaddress account. /// is used to determine the spending subaddress account.
/// ///
/// 2) If the payment ID is the unencrypted variant and the block's hf version is /// 2) If the payment ID is the unencrypted variant and the block's hf version is
/// v12 or higher (https://github.com/serai-dex/serai/issues/512) /// v12 or higher (https://github.com/serai-dex/serai/issues/512)
pub payment_id: Option<PaymentId>, pub payment_id: Option<PaymentId>,
/// Arbitrary data encoded in TX extra. /// Arbitrary data encoded in TX extra.
pub arbitrary_data: Vec<Vec<u8>>, pub arbitrary_data: Vec<Vec<u8>>,

View file

@ -364,8 +364,8 @@ impl Change {
/// 1) The change in the tx is shunted to the fee (fingerprintable fee). /// 1) The change in the tx is shunted to the fee (fingerprintable fee).
/// ///
/// 2) If there are 2 outputs in the tx, there would be no payment ID as is the case when the /// 2) If there are 2 outputs in the tx, there would be no payment ID as is the case when the
/// reference wallet creates 2 output txs, since monero-serai doesn't know which output /// reference wallet creates 2 output txs, since monero-serai doesn't know which output
/// to tie the dummy payment ID to. /// to tie the dummy payment ID to.
pub fn fingerprintable(address: Option<MoneroAddress>) -> Change { pub fn fingerprintable(address: Option<MoneroAddress>) -> Change {
Change { address, view: None } Change { address, view: None }
} }

View file

@ -7,7 +7,7 @@ repository = "https://github.com/serai-dex/serai/tree/develop/common/zalloc"
authors = ["Luke Parker <lukeparker5132@gmail.com>"] authors = ["Luke Parker <lukeparker5132@gmail.com>"]
keywords = [] keywords = []
edition = "2021" edition = "2021"
rust-version = "1.60" rust-version = "1.77.0"
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true
@ -19,8 +19,10 @@ workspace = true
[dependencies] [dependencies]
zeroize = { version = "^1.5", default-features = false } zeroize = { version = "^1.5", default-features = false }
[build-dependencies]
rustversion = { version = "1", default-features = false }
[features] [features]
std = ["zeroize/std"] std = ["zeroize/std"]
default = ["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
View 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)");
}

View file

@ -1,6 +1,6 @@
#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_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. //! 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 //! 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. /// An allocator wrapper which zeroizes its memory on dealloc.
pub struct ZeroizingAlloc<T>(pub T); pub struct ZeroizingAlloc<T>(pub T);
#[cfg(feature = "allocator")] #[cfg(all(zalloc_rustc_nightly, feature = "allocator"))]
use core::{ use core::{
ptr::NonNull, ptr::NonNull,
alloc::{AllocError, Allocator}, alloc::{AllocError, Allocator},
}; };
#[cfg(feature = "allocator")] #[cfg(all(zalloc_rustc_nightly, feature = "allocator"))]
unsafe impl<T: Allocator> Allocator for ZeroizingAlloc<T> { unsafe impl<T: Allocator> Allocator for ZeroizingAlloc<T> {
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> { fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
self.0.allocate(layout) self.0.allocate(layout)

View file

@ -122,7 +122,7 @@ impl QueuedBatchesDb {
pub fn take(txn: &mut impl DbTxn, set: ValidatorSet) -> Vec<Transaction> { pub fn take(txn: &mut impl DbTxn, set: ValidatorSet) -> Vec<Transaction> {
let batches_vec = Self::get(txn, set).unwrap_or_default(); 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 batches: &[u8] = &batches_vec;
let mut res = vec![]; let mut res = vec![];

View file

@ -177,14 +177,14 @@ impl<N: Network> BlockData<N> {
let new_block = last_block_or_round(&mut txn, LATEST_BLOCK_KEY, self.number.0)?; let new_block = last_block_or_round(&mut txn, LATEST_BLOCK_KEY, self.number.0)?;
if new_block { if new_block {
// Delete the latest round key // 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())?; let new_round = last_block_or_round(&mut txn, LATEST_ROUND_KEY, round_number.0.into())?;
if new_block || new_round { if new_block || new_round {
// Delete the messages for the old round // Delete the messages for the old round
txn.del(&key(PROPOSE_KEY)); txn.del(key(PROPOSE_KEY));
txn.del(&key(PEVOTE_KEY)); txn.del(key(PEVOTE_KEY));
txn.del(&key(PRECOMMIT_KEY)); txn.del(key(PRECOMMIT_KEY));
} }
// Check we haven't sent this message within this round // Check we haven't sent this message within this round

View file

@ -34,7 +34,7 @@ macro_rules! math_op {
impl $Op<$Other> for $Value { impl $Op<$Other> for $Value {
type Output = $Value; type Output = $Value;
fn $op_fn(self, other: $Other) -> Self::Output { 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 { impl $Assign<$Other> for $Value {
@ -45,7 +45,7 @@ macro_rules! math_op {
impl<'a> $Op<&'a $Other> for $Value { impl<'a> $Op<&'a $Other> for $Value {
type Output = $Value; type Output = $Value;
fn $op_fn(self, other: &'a $Other) -> Self::Output { 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 { impl<'a> $Assign<&'a $Other> for $Value {
@ -60,7 +60,7 @@ macro_rules! from_wrapper {
($wrapper: ident, $inner: ident, $uint: ident) => { ($wrapper: ident, $inner: ident, $uint: ident) => {
impl From<$uint> for $wrapper { impl From<$uint> for $wrapper {
fn from(a: $uint) -> $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 { impl Neg for $FieldName {
type Output = $FieldName; type Output = $FieldName;
fn neg(self) -> $FieldName { fn neg(self) -> $FieldName {
Self(self.0.neg()) $FieldName(self.0.neg())
} }
} }
@ -141,13 +141,13 @@ macro_rules! field {
impl $FieldName { impl $FieldName {
/// Perform an exponentiation. /// Perform an exponentiation.
pub fn pow(&self, other: $FieldName) -> $FieldName { pub fn pow(&self, other: $FieldName) -> $FieldName {
let mut table = [Self(Residue::ONE); 16]; let mut table = [$FieldName(Residue::ONE); 16];
table[1] = *self; table[1] = *self;
for i in 2 .. 16 { for i in 2 .. 16 {
table[i] = table[i - 1] * self; table[i] = table[i - 1] * self;
} }
let mut res = Self(Residue::ONE); let mut res = $FieldName(Residue::ONE);
let mut bits = 0; let mut bits = 0;
for (i, mut bit) in other.to_le_bits().iter_mut().rev().enumerate() { for (i, mut bit) in other.to_le_bits().iter_mut().rev().enumerate() {
bits <<= 1; bits <<= 1;
@ -170,8 +170,8 @@ macro_rules! field {
} }
impl Field for $FieldName { impl Field for $FieldName {
const ZERO: Self = Self(Residue::ZERO); const ZERO: Self = $FieldName(Residue::ZERO);
const ONE: Self = Self(Residue::ONE); const ONE: Self = $FieldName(Residue::ONE);
fn random(mut rng: impl RngCore) -> Self { fn random(mut rng: impl RngCore) -> Self {
let mut bytes = [0; 112]; let mut bytes = [0; 112];
@ -188,12 +188,12 @@ macro_rules! field {
fn invert(&self) -> CtOption<Self> { fn invert(&self) -> CtOption<Self> {
const NEG_2: $FieldName = 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()) CtOption::new(self.pow(NEG_2), !self.is_zero())
} }
fn sqrt(&self) -> CtOption<Self> { 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)), &$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 TWO_INV: Self = $FieldName($ResidueType::new(&U448::from_u8(2)).invert().0);
const MULTIPLICATIVE_GENERATOR: Self = 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 // True for both the Ed448 Scalar field and FieldElement field
const S: u32 = 1; const S: u32 = 1;
// Both fields have their root of unity as -1 // Both fields have their root of unity as -1
const ROOT_OF_UNITY: Self = const ROOT_OF_UNITY: Self =
Self($ResidueType::sub(&$ResidueType::ZERO, &$ResidueType::new(&U448::ONE))); $FieldName($ResidueType::sub(&$ResidueType::ZERO, &$ResidueType::new(&U448::ONE)));
const ROOT_OF_UNITY_INV: Self = Self(Self::ROOT_OF_UNITY.0.invert().0); 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))); const DELTA: Self = $FieldName(Residue::new(&U448::from_le_hex($DELTA)));

View file

@ -10,7 +10,7 @@ integrating with existing systems.
This library offers ciphersuites compatible with the This library offers ciphersuites compatible with the
[IETF draft](https://github.com/cfrg/draft-irtf-cfrg-frost). Currently, version [IETF draft](https://github.com/cfrg/draft-irtf-cfrg-frost). Currently, version
11 is supported. 15 is supported.
This library was 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), [audited by Cypher Stack in March 2023](https://github.com/serai-dex/serai/raw/e1bb2c191b7123fd260d008e31656d090d559d21/audits/Cypher%20Stack%20crypto%20March%202023/Audit.pdf),

View file

@ -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"message", C::hash_msg(msg));
rho_transcript.append_message( rho_transcript.append_message(
b"preprocesses", b"preprocesses",
&C::hash_commitments( C::hash_commitments(self.params.algorithm.transcript().challenge(b"preprocesses").as_ref()),
self.params.algorithm.transcript().challenge(b"preprocesses").as_ref(),
),
); );
// Generate the per-signer binding factors // Generate the per-signer binding factors

View file

@ -52,7 +52,7 @@ fn test_rfc8032() {
SchnorrSignature::<Ed25519>::read::<&[u8]>(&mut hex::decode(vector.2).unwrap().as_ref()) SchnorrSignature::<Ed25519>::read::<&[u8]>(&mut hex::decode(vector.2).unwrap().as_ref())
.unwrap(); .unwrap();
let hram = Sha512::new_with_prefix( 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))); assert!(sig.verify(key, Scalar::from_hash(hram)));
} }

View file

@ -3,9 +3,9 @@
Flexible Transcript is a crate offering: Flexible Transcript is a crate offering:
- `Transcript`, a trait offering functions transcripts should implement. - `Transcript`, a trait offering functions transcripts should implement.
- `DigestTranscript`, a competent transcript format instantiated against a - `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 - `MerlinTranscript`, a wrapper of `merlin` into the trait (available via the
`merlin` feature). `merlin` feature).
- `RecommendedTranscript`, a transcript recommended for usage in applications. - `RecommendedTranscript`, a transcript recommended for usage in applications.
Currently, this is `DigestTranscript<Blake2b512>` (available via the Currently, this is `DigestTranscript<Blake2b512>` (available via the
`recommended` feature). `recommended` feature).

View file

@ -231,7 +231,7 @@ impl ForwardedOutputDb {
let res = InInstructionWithBalance::decode(&mut outputs_ref).unwrap(); let res = InInstructionWithBalance::decode(&mut outputs_ref).unwrap();
assert!(outputs_ref.len() < outputs.len()); assert!(outputs_ref.len() < outputs.len());
if outputs_ref.is_empty() { if outputs_ref.is_empty() {
txn.del(&Self::key(balance)); txn.del(Self::key(balance));
} else { } else {
Self::set(txn, balance, &outputs); Self::set(txn, balance, &outputs);
} }

View file

@ -49,6 +49,9 @@ std = [
"coins-primitives/std", "coins-primitives/std",
] ]
# TODO
try-runtime = []
runtime-benchmarks = [ runtime-benchmarks = [
"frame-system/runtime-benchmarks", "frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks", "frame-support/runtime-benchmarks",

View file

@ -60,3 +60,6 @@ std = [
"validator-sets-pallet/std", "validator-sets-pallet/std",
] ]
default = ["std"] default = ["std"]
# TODO
try-runtime = []

View file

@ -57,4 +57,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks", "frame-support/runtime-benchmarks",
] ]
# TODO
try-runtime = []
default = ["std"] default = ["std"]

View file

@ -70,6 +70,9 @@ std = [
"dex-pallet/std", "dex-pallet/std",
] ]
# TODO
try-runtime = []
runtime-benchmarks = [ runtime-benchmarks = [
"frame-system/runtime-benchmarks", "frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks", "frame-support/runtime-benchmarks",