mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-13 14:39:25 +00:00
Further documentation, start shoring up API boundaries of existing crates
This commit is contained in:
@@ -64,11 +64,8 @@ fn clsag() {
|
||||
image,
|
||||
ClsagInput::new(
|
||||
Commitment::new(secrets.1, AMOUNT),
|
||||
Decoys {
|
||||
i: u8::try_from(real).unwrap(),
|
||||
offsets: (1 ..= RING_LEN).collect(),
|
||||
ring: ring.clone(),
|
||||
},
|
||||
Decoys::new((1 ..= RING_LEN).collect(), u8::try_from(real).unwrap(), ring.clone())
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap(),
|
||||
)],
|
||||
@@ -115,7 +112,7 @@ fn clsag_multisig() {
|
||||
Arc::new(RwLock::new(Some(ClsagDetails::new(
|
||||
ClsagInput::new(
|
||||
Commitment::new(randomness, AMOUNT),
|
||||
Decoys { i: RING_INDEX, offsets: (1 ..= RING_LEN).collect(), ring: ring.clone() },
|
||||
Decoys::new((1 ..= RING_LEN).collect(), RING_INDEX, ring.clone()).unwrap(),
|
||||
)
|
||||
.unwrap(),
|
||||
mask_sum,
|
||||
|
||||
@@ -260,12 +260,15 @@ async fn select_decoys<R: RngCore + CryptoRng, RPC: RpcConnection>(
|
||||
// members
|
||||
}
|
||||
|
||||
res.push(Decoys {
|
||||
// Binary searches for the real spend since we don't know where it sorted to
|
||||
i: u8::try_from(ring.partition_point(|x| x.0 < o.0)).unwrap(),
|
||||
offsets: offset(&ring.iter().map(|output| output.0).collect::<Vec<_>>()),
|
||||
ring: ring.iter().map(|output| output.1).collect(),
|
||||
});
|
||||
res.push(
|
||||
Decoys::new(
|
||||
offset(&ring.iter().map(|output| output.0).collect::<Vec<_>>()),
|
||||
// Binary searches for the real spend since we don't know where it sorted to
|
||||
u8::try_from(ring.partition_point(|x| x.0 < o.0)).unwrap(),
|
||||
ring.iter().map(|output| output.1).collect(),
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
|
||||
@@ -22,6 +22,8 @@ use dalek_ff_group as dfg;
|
||||
#[cfg(feature = "multisig")]
|
||||
use frost::FrostError;
|
||||
|
||||
use monero_io::varint_len;
|
||||
|
||||
use crate::{
|
||||
Protocol, Commitment, hash,
|
||||
serialize::{
|
||||
@@ -181,7 +183,7 @@ fn prepare_inputs(
|
||||
|
||||
tx.prefix.inputs.push(Input::ToKey {
|
||||
amount: None,
|
||||
key_offsets: decoys.offsets.clone(),
|
||||
key_offsets: decoys.offsets().to_vec(),
|
||||
key_image: signable[i].1,
|
||||
});
|
||||
}
|
||||
@@ -518,8 +520,13 @@ impl SignableTransaction {
|
||||
}
|
||||
|
||||
// Caclculate weight of decoys
|
||||
let decoy_weights =
|
||||
inputs.iter().map(|(_, decoy)| Decoys::fee_weight(&decoy.offsets)).collect::<Vec<_>>();
|
||||
let decoy_weights = inputs
|
||||
.iter()
|
||||
.map(|(_, decoys)| {
|
||||
let offsets = decoys.offsets();
|
||||
varint_len(offsets.len()) + offsets.iter().map(|offset| varint_len(*offset)).sum::<usize>()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Deterministically calculate tx weight and fee
|
||||
let (weight, fee) =
|
||||
|
||||
@@ -108,11 +108,11 @@ impl SignableTransaction {
|
||||
transcript.append_message(b"input_shared_key", input.key_offset().to_bytes());
|
||||
|
||||
// Ensure all signers are signing the same rings
|
||||
transcript.append_message(b"real_spend", [decoys.i]);
|
||||
for (i, ring_member) in decoys.ring.iter().enumerate() {
|
||||
transcript.append_message(b"real_spend", [decoys.signer_index()]);
|
||||
for (i, ring_member) in decoys.ring().iter().enumerate() {
|
||||
transcript
|
||||
.append_message(b"ring_member", [u8::try_from(i).expect("ring size exceeded 255")]);
|
||||
transcript.append_message(b"ring_member_offset", decoys.offsets[i].to_le_bytes());
|
||||
transcript.append_message(b"ring_member_offset", decoys.offsets()[i].to_le_bytes());
|
||||
transcript.append_message(b"ring_member_key", ring_member[0].compress().to_bytes());
|
||||
transcript.append_message(b"ring_member_commitment", ring_member[1].compress().to_bytes());
|
||||
}
|
||||
@@ -356,7 +356,7 @@ impl SignMachine<Transaction> for TransactionSignMachine {
|
||||
|
||||
tx.prefix.inputs.push(Input::ToKey {
|
||||
amount: None,
|
||||
key_offsets: value.2.offsets.clone(),
|
||||
key_offsets: value.2.offsets().to_vec(),
|
||||
key_image: value.0,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user