Skip to content

Commit fe4d419

Browse files
committed
wip: progress with a more constant-time api for or
2 parents 9b08388 + e4ecf3c commit fe4d419

File tree

9 files changed

+262
-171
lines changed

9 files changed

+262
-171
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ num-bigint = "0.4.6"
2626
num-traits = "0.2.19"
2727
rand = "0.8.5"
2828
sha3 = "0.10.8"
29+
subtle = "2.6.1"
2930
thiserror = "1"
3031
keccak = "0.1.5"
3132
zerocopy = "0.8"
@@ -40,7 +41,6 @@ json = "0.12.4"
4041
serde = { version = "1.0.219", features = ["derive"] }
4142
serde_json = "1.0.140"
4243
sha2 = "0.10"
43-
subtle = "2.6.1"
4444

4545
[profile.dev]
4646
# Makes tests run much faster at the cost of slightly longer builds and worse debug info.

examples/simple_composition.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use sigma_rs::{
1010
errors::Error,
1111
LinearRelation, Nizk,
1212
};
13+
use subtle::CtOption;
1314

1415
type G = RistrettoPoint;
1516
type ProofResult<T> = Result<T, Error>;
@@ -53,7 +54,14 @@ fn prove(P1: G, x2: Scalar, H: G) -> ProofResult<Vec<u8>> {
5354
let Q = H * x2;
5455

5556
let instance = create_relation(P1, P2, Q, H);
56-
let witness = ComposedWitness::Or(1, vec![ComposedWitness::Simple(vec![x2])]);
57+
// Create OR witness with branch 1 being the real one (index 1)
58+
let witness = ComposedWitness::Or(vec![
59+
CtOption::new(
60+
ComposedWitness::Simple(vec![Scalar::from(0u64)]),
61+
0u8.into(),
62+
), // dummy for branch 0
63+
CtOption::new(ComposedWitness::Simple(vec![x2]), 1u8.into()), // real witness for branch 1
64+
]);
5765
let nizk = Nizk::<_, Shake128DuplexSponge<G>>::new(b"or_proof_example", instance);
5866

5967
nizk.prove_batchable(&witness, &mut OsRng)

src/codec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Encoding and decoding utilities for Fiat-Shamir and group operations.
22
3-
pub use crate::duplex_sponge::keccak::KeccakDuplexSponge;
4-
use crate::duplex_sponge::{shake::ShakeDuplexSponge, DuplexSpongeInterface};
3+
use crate::duplex_sponge::DuplexSpongeInterface;
4+
pub use crate::duplex_sponge::{keccak::KeccakDuplexSponge, shake::ShakeDuplexSponge};
55
use ff::PrimeField;
66
use group::prime::PrimeGroup;
77
use num_bigint::BigUint;
@@ -101,7 +101,7 @@ where
101101
self.hasher.absorb(data);
102102
}
103103

104-
fn verifier_challenge(&mut self) -> G::Scalar {
104+
fn verifier_challenge(&mut self) -> Self::Challenge {
105105
#[allow(clippy::manual_div_ceil)]
106106
let scalar_byte_length = (G::Scalar::NUM_BITS as usize + 7) / 8;
107107

0 commit comments

Comments
 (0)