Skip to content

Commit 49dc76d

Browse files
Use byte strings (#67)
This PR switches from `"string".as_bytes()` to `b"string"` for consistency and conciseness.
1 parent c455a66 commit 49dc76d

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

benches/triptych.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ fn generate_data<R: CryptoRngCore>(
6565
// Generate transcripts
6666
let transcripts = (0..b)
6767
.map(|i| {
68-
let mut transcript = Transcript::new("Test transcript".as_bytes());
69-
transcript.append_u64("index".as_bytes(), i as u64);
68+
let mut transcript = Transcript::new(b"Test transcript");
69+
transcript.append_u64(b"index", i as u64);
7070

7171
transcript
7272
})

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
//! let statement = Statement::new(&params, &input_set, &J).unwrap();
9898
//!
9999
//! // Generate a transcript
100-
//! let mut transcript = Transcript::new("Test transcript".as_bytes());
100+
//! let mut transcript = Transcript::new(b"Test transcript");
101101
//!
102102
//! // Generate a proof from the witness
103103
//! let proof = Proof::prove(&witness, &statement, &mut transcript.clone()).unwrap();

src/parameters.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Parameters {
5959
// Use `BLAKE3` to generate `U`
6060
let mut U_bytes = [0u8; 64];
6161
let mut hasher = Hasher::new();
62-
hasher.update("Triptych U".as_bytes());
62+
hasher.update(b"Triptych U");
6363
hasher.finalize_xof().fill(&mut U_bytes);
6464
let U = RistrettoPoint::from_uniform_bytes(&U_bytes);
6565

@@ -92,13 +92,13 @@ impl Parameters {
9292
// Use `BLAKE3` to generate `CommitmentH`
9393
let mut CommitmentH_bytes = [0u8; 64];
9494
let mut hasher = Hasher::new();
95-
hasher.update("Triptych CommitmentH".as_bytes());
95+
hasher.update(b"Triptych CommitmentH");
9696
hasher.finalize_xof().fill(&mut CommitmentH_bytes);
9797
let CommitmentH = RistrettoPoint::from_uniform_bytes(&CommitmentH_bytes);
9898

9999
// Use `BLAKE3` for the commitment matrix generators
100100
let mut hasher = Hasher::new();
101-
hasher.update("Triptych CommitmentG".as_bytes());
101+
hasher.update(b"Triptych CommitmentG");
102102
hasher.update(&n.to_le_bytes());
103103
hasher.update(&m.to_le_bytes());
104104
let mut hasher_xof = hasher.finalize_xof();
@@ -112,7 +112,7 @@ impl Parameters {
112112

113113
// Use `BLAKE3` for the transcript hash
114114
let mut hasher = Hasher::new();
115-
hasher.update("Triptych Parameters".as_bytes());
115+
hasher.update(b"Triptych Parameters");
116116
hasher.update(&Self::VERSION.to_le_bytes());
117117
hasher.update(&n.to_le_bytes());
118118
hasher.update(&m.to_le_bytes());

src/proof.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl Proof {
484484
let mut U_scalar = Scalar::ZERO;
485485

486486
// Set up a transcript generator for use in weighting
487-
let mut transcript_weights = Transcript::new("Triptych verifier weights".as_bytes());
487+
let mut transcript_weights = Transcript::new(b"Triptych verifier weights");
488488

489489
let mut null_rng = NullRng;
490490

@@ -499,7 +499,7 @@ impl Proof {
499499

500500
// Run the Fiat-Shamir response phase to get the transcript generator and weight
501501
let mut transcript_rng = transcript.response(&proof.f, &proof.z_A, &proof.z_C, &proof.z);
502-
transcript_weights.append_u64("proof".as_bytes(), transcript_rng.as_rngcore().next_u64());
502+
transcript_weights.append_u64(b"proof", transcript_rng.as_rngcore().next_u64());
503503
}
504504

505505
// Finalize the weighting transcript into a pseudorandom number generator
@@ -846,8 +846,8 @@ mod test {
846846
// Generate transcripts
847847
let transcripts = (0..b)
848848
.map(|i| {
849-
let mut transcript = Transcript::new("Test transcript".as_bytes());
850-
transcript.append_u64("index".as_bytes(), i as u64);
849+
let mut transcript = Transcript::new(b"Test transcript");
850+
transcript.append_u64(b"index", i as u64);
851851

852852
transcript
853853
})
@@ -975,7 +975,7 @@ mod test {
975975
Proof::prove_with_rng_vartime(&witnesses[0], &statements[0], &mut rng, &mut transcripts[0]).unwrap();
976976

977977
// Generate a modified transcript
978-
let mut evil_transcript = Transcript::new("Evil transcript".as_bytes());
978+
let mut evil_transcript = Transcript::new(b"Evil transcript");
979979

980980
// Attempt to verify the proof against the new statement, which should fail
981981
assert!(proof.verify(&statements[0], &mut evil_transcript).is_err());

src/statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl InputSet {
2929
pub fn new(M: &[RistrettoPoint]) -> Self {
3030
// Use `BLAKE3` for the transcript hash
3131
let mut hasher = Hasher::new();
32-
hasher.update("Triptych InputSet".as_bytes());
32+
hasher.update(b"Triptych InputSet");
3333
hasher.update(&Self::VERSION.to_le_bytes());
3434
for item in M {
3535
hasher.update(item.compress().as_bytes());

src/transcript.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'a, R: CryptoRngCore> ProofTranscript<'a, R> {
8080

8181
// Get the initial challenge using wide reduction
8282
let mut xi_bytes = [0u8; 64];
83-
self.transcript.challenge_bytes("xi".as_bytes(), &mut xi_bytes);
83+
self.transcript.challenge_bytes(b"xi", &mut xi_bytes);
8484
let xi = Scalar::from_bytes_mod_order_wide(&xi_bytes);
8585

8686
// Get powers of the challenge and confirm they are nonzero

0 commit comments

Comments
 (0)