From c90acce7bd73a2638c46132ae5bcd79c7a6bc0b9 Mon Sep 17 00:00:00 2001 From: Davide Galassi Date: Tue, 26 Mar 2024 15:19:40 +0100 Subject: [PATCH] Challenge in accumulation mode --- ark-transcript/src/lib.rs | 6 +++++- ark-transcript/src/tests.rs | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ark-transcript/src/lib.rs b/ark-transcript/src/lib.rs index 7422d6a6..c23686c2 100644 --- a/ark-transcript/src/lib.rs +++ b/ark-transcript/src/lib.rs @@ -120,7 +120,11 @@ impl Mode { println!("Shake128 {}transcript XoF reader",self.debug_name); match self { Mode::Hash(hasher) => Reader(hasher.clone().finalize_xof()), - Mode::Accumulate(_) => panic!("Attempt to read from accumulating Transcript"), + Mode::Accumulate(acc) => { + let mut t = Transcript::from_accumulation(acc); + t.seperate(); + t.mode.raw_reader() + } } } } diff --git a/ark-transcript/src/tests.rs b/ark-transcript/src/tests.rs index b71fe2ca..3caadb0e 100644 --- a/ark-transcript/src/tests.rs +++ b/ark-transcript/src/tests.rs @@ -104,3 +104,26 @@ fn accumulation() { let c2: [u8; 32] = t3.challenge(b"challenge").read_byte_array(); assert_eq!(c1,c2); } + +#[test] +fn challenge_in_accumulation() { + let mut t1 = Transcript::new_blank_accumulator(); + let mut t2 = Transcript::new_blank_accumulator(); + + let commitment1 = b"commitment data 1"; + let commitment2 = b"commitment data 2"; + + t1.write_bytes(commitment1); + t2.write_bytes(commitment1); + + t1.write_bytes(commitment2); + t2.write_bytes(commitment2); + + let acc = t2.accumulator_finalize(); + let mut t3 = Transcript::from_accumulation(acc); + + let c1: [u8; 32] = t1.challenge(b"challenge").read_byte_array(); + let c2: [u8; 32] = t3.challenge(b"challenge").read_byte_array(); + + assert_eq!(c1, c2); +}