Skip to content

Commit 3a3ad68

Browse files
XuyangSongclaude
andcommitted
Merge origin/develop into anthony/arm-crate-split
Resolved conflicts in arm/src/action.rs and arm/src/transaction.rs: - action.rs: dropped develop's duplicate verify/delta/get_delta_msg methods (already provided by ActionExt trait); changed verify signature to &self - transaction.rs: kept crate-split architecture (DeltaProof::from_bytes, non-Result get_delta_msg); changed verify signature to &self to match - delta_proof.rs: auto-merged (mod tests reorganization) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2 parents 3efcd79 + c8125d3 commit 3a3ad68

3 files changed

Lines changed: 44 additions & 15 deletions

File tree

arm/src/action.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub trait ActionExt {
2323
Self: Sized;
2424

2525
/// Verifies all proofs and consistencies in the action.
26-
fn verify(self) -> Result<(), ArmError>;
26+
fn verify(&self) -> Result<(), ArmError>;
2727

2828
/// This function computes the delta of the action by summing up the deltas
2929
/// of each compliance unit.
@@ -48,7 +48,7 @@ impl ActionExt for Action {
4848
})
4949
}
5050

51-
fn verify(self) -> Result<(), ArmError> {
51+
fn verify(&self) -> Result<(), ArmError> {
5252
for unit in &self.compliance_units {
5353
unit.verify()?;
5454
}

arm/src/delta_proof.rs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,49 @@ impl<'de> Deserialize<'de> for DeltaWitness {
221221
}
222222
}
223223

224-
#[test]
225-
fn test_delta_proof() {
224+
#[cfg(test)]
225+
mod tests {
226+
use super::*;
226227
use k256::elliptic_curve::rand_core::OsRng;
227228

228-
let mut rng = OsRng;
229-
let signing_key = SigningKey::random(&mut rng);
230-
let verifying_key = VerifyingKey::from(&signing_key);
229+
#[test]
230+
fn test_delta_proof() {
231+
let mut rng = OsRng;
232+
let signing_key = SigningKey::random(&mut rng);
233+
let verifying_key = VerifyingKey::from(&signing_key);
231234

232-
let message = b"Hello, world!";
233-
let witness = DeltaWitness { signing_key };
234-
let proof = DeltaProof::prove(message, &witness).unwrap();
235-
let instance = DeltaInstance { verifying_key };
235+
let message = b"Hello, world!";
236+
let witness = DeltaWitness { signing_key };
237+
let proof = DeltaProof::prove(message, &witness).unwrap();
238+
let instance = DeltaInstance { verifying_key };
239+
240+
DeltaProof::verify(message, &proof, instance).unwrap();
241+
}
242+
243+
/// DeltaProof: serialize then deserialize via bincode must round-trip.
244+
#[test]
245+
fn delta_proof_bincode_roundtrip() {
246+
let mut rng = OsRng;
247+
let signing_key = SigningKey::random(&mut rng);
248+
let witness = DeltaWitness { signing_key };
249+
let proof = DeltaProof::prove(b"roundtrip", &witness).unwrap();
250+
251+
let encoded = bincode::serialize(&proof).unwrap();
252+
let decoded: DeltaProof = bincode::deserialize(&encoded).unwrap();
253+
assert_eq!(proof, decoded);
254+
}
236255

237-
DeltaProof::verify(message, &proof, instance).unwrap();
256+
/// DeltaWitness: serialize then deserialize via bincode must round-trip.
257+
#[test]
258+
fn delta_witness_bincode_roundtrip() {
259+
let mut rng = OsRng;
260+
let signing_key = SigningKey::random(&mut rng);
261+
let witness = DeltaWitness { signing_key };
262+
263+
let encoded = bincode::serialize(&witness).unwrap();
264+
let decoded: DeltaWitness = bincode::deserialize(&encoded).unwrap();
265+
assert_eq!(witness, decoded);
266+
}
238267
}
239268

240269
/// DeltaProof: serialize then deserialize via bincode must round-trip.

arm/src/transaction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub trait TransactionExt {
3131
fn generate_delta_proof(self) -> Result<Transaction, ArmError>;
3232

3333
/// Verifies all the proofs and corresponding checks in the transaction.
34-
fn verify(self) -> Result<(), ArmError>;
34+
fn verify(&self) -> Result<(), ArmError>;
3535

3636
/// Returns the DeltaInstance constructed from the sum of all actions' deltas.
3737
fn delta(&self) -> Result<DeltaInstance, ArmError>;
@@ -88,7 +88,7 @@ impl TransactionExt for Transaction {
8888
}
8989
}
9090

91-
fn verify(self) -> Result<(), ArmError> {
91+
fn verify(&self) -> Result<(), ArmError> {
9292
match &self.delta_proof {
9393
Delta::Proof(proof) => {
9494
let proof = DeltaProof::from_bytes(&proof.0)?;
@@ -109,7 +109,7 @@ impl TransactionExt for Transaction {
109109
self.verify_aggregation()?;
110110
} else {
111111
// Try verifying individually.
112-
for action in self.actions {
112+
for action in self.actions.iter() {
113113
action.verify()?;
114114
}
115115
}

0 commit comments

Comments
 (0)