Add changes for bug fix in zkp crate

This commit is contained in:
onyinyang 2023-09-21 10:25:28 -04:00
parent 5e1a2d8c6d
commit ed72b05347
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
1 changed files with 12 additions and 43 deletions

View File

@ -26,9 +26,7 @@ and a new Lox credential to be issued:
- trust_level: revealed to be 2 less than the trust_level above - trust_level: revealed to be 2 less than the trust_level above
- level_since: today - level_since: today
- invites_remaining: revealed to be LEVEL_INVITATIONS for the new trust - invites_remaining: revealed to be LEVEL_INVITATIONS for the new trust
level [Actually, there's a bug in the zkp crate that's triggered when level
a public value is 0 (the identity element of the Ristretto group), so
we treat this field as blinded, but the _server_ encrypts the value.]
- blockages: blinded, but proved in ZK that it's one more than the - blockages: blinded, but proved in ZK that it's one more than the
blockages above blockages above
@ -100,15 +98,14 @@ pub struct Response {
// The new attributes; the trust_level and invites_remaining are // The new attributes; the trust_level and invites_remaining are
// implicit // implicit
level_since: Scalar, level_since: Scalar,
invremain: Scalar,
// The fields for the new Lox credential // The fields for the new Lox credential
P: RistrettoPoint, P: RistrettoPoint,
EncQ: (RistrettoPoint, RistrettoPoint), EncQ: (RistrettoPoint, RistrettoPoint),
EncInvRemain: (RistrettoPoint, RistrettoPoint),
id_server: Scalar, id_server: Scalar,
TId: RistrettoPoint, TId: RistrettoPoint,
TBucket: RistrettoPoint, TBucket: RistrettoPoint,
TInvRemain: RistrettoPoint,
TBlockages: RistrettoPoint, TBlockages: RistrettoPoint,
// The ZKP // The ZKP
@ -155,11 +152,10 @@ define_proof! {
blindissue, blindissue,
"Blockage Migration Blind Issuing", "Blockage Migration Blind Issuing",
(x0, x0tilde, xid, xbucket, xlevel, xsince, xinvremain, xblockages, (x0, x0tilde, xid, xbucket, xlevel, xsince, xinvremain, xblockages,
s, b, tid, tbucket, tinvremain, tblockages), s, b, tid, tbucket, tblockages),
(P, EncQ0, EncQ1, X0, Xid, Xbucket, Xlevel, Xsince, Xinvremain, (P, EncQ0, EncQ1, X0, Xid, Xbucket, Xlevel, Xsince, Xinvremain,
Xblockages, Plevel, Psince, TId, TBucket, TInvRemain, TBlockages, Xblockages, Plevel, Psince, Pinvremain, TId, TBucket, TBlockages,
D, EncId0, EncId1, EncBucket0, EncBucket1, EncInvRemain0, D, EncId0, EncId1, EncBucket0, EncBucket1, EncBlockages0, EncBlockages1),
EncInvRemain1, EncBlockages0, EncBlockages1),
(A, B): (A, B):
Xid = (xid*A), Xid = (xid*A),
Xlevel = (xlevel*A), Xlevel = (xlevel*A),
@ -173,14 +169,12 @@ define_proof! {
TId = (tid*A), TId = (tid*A),
TBucket = (b*Xbucket), TBucket = (b*Xbucket),
TBucket = (tbucket*A), TBucket = (tbucket*A),
TInvRemain = (b*Xinvremain),
TInvRemain = (tinvremain*A),
TBlockages = (b*Xblockages), TBlockages = (b*Xblockages),
TBlockages = (tblockages*A), TBlockages = (tblockages*A),
EncQ0 = (s*B + tid*EncId0 + tbucket*EncBucket0 EncQ0 = (s*B + tid*EncId0 + tbucket*EncBucket0
+ tinvremain*EncInvRemain0 + tblockages*EncBlockages0), + tblockages*EncBlockages0),
EncQ1 = (s*D + tid*EncId1 + tbucket*EncBucket1 EncQ1 = (s*D + tid*EncId1 + tbucket*EncBucket1
+ tinvremain*EncInvRemain1 + tblockages*EncBlockages1 + tblockages*EncBlockages1
+ x0*P + xlevel*Plevel + xsince*Psince) + x0*P + xlevel*Plevel + xsince*Psince)
} }
@ -484,14 +478,6 @@ impl BridgeAuth {
// invitations for moving from level i to level i+1) // invitations for moving from level i to level i+1)
let invremain: Scalar = LEVEL_INVITATIONS[(level - 3) as usize].into(); let invremain: Scalar = LEVEL_INVITATIONS[(level - 3) as usize].into();
// Because of the bug in the zkp crate, encrypt the invites
// remaining instead of sending it in the clear
let sinvremain = Scalar::random(&mut rng);
let EncInvRemain = (
&sinvremain * Btable,
&invremain * Btable + sinvremain * req.D,
);
// Compute the MAC on the visible attributes // Compute the MAC on the visible attributes
let b = Scalar::random(&mut rng); let b = Scalar::random(&mut rng);
let P = &b * Btable; let P = &b * Btable;
@ -512,9 +498,6 @@ impl BridgeAuth {
let tbucket = self.lox_priv.x[2] * b; let tbucket = self.lox_priv.x[2] * b;
let TBucket = &tbucket * Atable; let TBucket = &tbucket * Atable;
let EncQBucket = (tbucket * req.EncBucket.0, tbucket * req.EncBucket.1); let EncQBucket = (tbucket * req.EncBucket.0, tbucket * req.EncBucket.1);
let tinvremain = self.lox_priv.x[5] * b;
let TInvRemain = &tinvremain * Atable;
let EncQInvRemain = (tinvremain * EncInvRemain.0, tinvremain * EncInvRemain.1);
let tblockages = self.lox_priv.x[6] * b; let tblockages = self.lox_priv.x[6] * b;
let TBlockages = &tblockages * Atable; let TBlockages = &tblockages * Atable;
let EncQBlockages = ( let EncQBlockages = (
@ -523,8 +506,8 @@ impl BridgeAuth {
); );
let EncQ = ( let EncQ = (
EncQHc.0 + EncQId.0 + EncQBucket.0 + EncQInvRemain.0 + EncQBlockages.0, EncQHc.0 + EncQId.0 + EncQBucket.0 + EncQBlockages.0,
EncQHc.1 + EncQId.1 + EncQBucket.1 + EncQInvRemain.1 + EncQBlockages.1, EncQHc.1 + EncQId.1 + EncQBucket.1 + EncQBlockages.1,
); );
let mut transcript = Transcript::new(b"blockage migration issuing"); let mut transcript = Transcript::new(b"blockage migration issuing");
@ -545,17 +528,15 @@ impl BridgeAuth {
Xblockages: &self.lox_pub.X[6], Xblockages: &self.lox_pub.X[6],
Plevel: &(trust_level * P), Plevel: &(trust_level * P),
Psince: &(level_since * P), Psince: &(level_since * P),
Pinvremain: &(invremain * P),
TId: &TId, TId: &TId,
TBucket: &TBucket, TBucket: &TBucket,
TInvRemain: &TInvRemain,
TBlockages: &TBlockages, TBlockages: &TBlockages,
D: &req.D, D: &req.D,
EncId0: &EncId.0, EncId0: &EncId.0,
EncId1: &EncId.1, EncId1: &EncId.1,
EncBucket0: &req.EncBucket.0, EncBucket0: &req.EncBucket.0,
EncBucket1: &req.EncBucket.1, EncBucket1: &req.EncBucket.1,
EncInvRemain0: &EncInvRemain.0,
EncInvRemain1: &EncInvRemain.1,
EncBlockages0: &req.EncBlockages.0, EncBlockages0: &req.EncBlockages.0,
EncBlockages1: &req.EncBlockages.1, EncBlockages1: &req.EncBlockages.1,
x0: &self.lox_priv.x[0], x0: &self.lox_priv.x[0],
@ -570,7 +551,6 @@ impl BridgeAuth {
b: &b, b: &b,
tid: &tid, tid: &tid,
tbucket: &tbucket, tbucket: &tbucket,
tinvremain: &tinvremain,
tblockages: &tblockages, tblockages: &tblockages,
}, },
) )
@ -578,13 +558,12 @@ impl BridgeAuth {
Ok(Response { Ok(Response {
level_since, level_since,
invremain,
P, P,
EncQ, EncQ,
EncInvRemain,
id_server, id_server,
TId, TId,
TBucket, TBucket,
TInvRemain,
TBlockages, TBlockages,
piBlindIssue, piBlindIssue,
}) })
@ -601,7 +580,6 @@ pub fn handle_response(
let A: &RistrettoPoint = &CMZ_A; let A: &RistrettoPoint = &CMZ_A;
let B: &RistrettoPoint = &CMZ_B; let B: &RistrettoPoint = &CMZ_B;
let Btable: &RistrettoBasepointTable = &CMZ_B_TABLE; let Btable: &RistrettoBasepointTable = &CMZ_B_TABLE;
if resp.P.is_identity() { if resp.P.is_identity() {
return Err(ProofError::VerificationFailure); return Err(ProofError::VerificationFailure);
} }
@ -627,13 +605,6 @@ pub fn handle_response(
// moving from level i to level i+1) // moving from level i to level i+1)
let invremain: Scalar = LEVEL_INVITATIONS[(new_level - 1) as usize].into(); let invremain: Scalar = LEVEL_INVITATIONS[(new_level - 1) as usize].into();
// Decrypt EncInvRemain
let recv_invremain = resp.EncInvRemain.1 - (state.d * resp.EncInvRemain.0);
if recv_invremain != &invremain * Btable {
return Err(ProofError::VerificationFailure);
}
// Verify the proof // Verify the proof
let mut transcript = Transcript::new(b"blockage migration issuing"); let mut transcript = Transcript::new(b"blockage migration issuing");
blindissue::verify_compact( blindissue::verify_compact(
@ -654,17 +625,15 @@ pub fn handle_response(
Xblockages: &lox_pub.X[6].compress(), Xblockages: &lox_pub.X[6].compress(),
Plevel: &(state.trust_level * resp.P).compress(), Plevel: &(state.trust_level * resp.P).compress(),
Psince: &(resp.level_since * resp.P).compress(), Psince: &(resp.level_since * resp.P).compress(),
Pinvremain: &(resp.invremain * resp.P).compress(),
TId: &resp.TId.compress(), TId: &resp.TId.compress(),
TBucket: &resp.TBucket.compress(), TBucket: &resp.TBucket.compress(),
TInvRemain: &resp.TInvRemain.compress(),
TBlockages: &resp.TBlockages.compress(), TBlockages: &resp.TBlockages.compress(),
D: &state.D.compress(), D: &state.D.compress(),
EncId0: &EncId.0.compress(), EncId0: &EncId.0.compress(),
EncId1: &EncId.1.compress(), EncId1: &EncId.1.compress(),
EncBucket0: &state.EncBucket.0.compress(), EncBucket0: &state.EncBucket.0.compress(),
EncBucket1: &state.EncBucket.1.compress(), EncBucket1: &state.EncBucket.1.compress(),
EncInvRemain0: &resp.EncInvRemain.0.compress(),
EncInvRemain1: &resp.EncInvRemain.1.compress(),
EncBlockages0: &state.EncBlockages.0.compress(), EncBlockages0: &state.EncBlockages.0.compress(),
EncBlockages1: &state.EncBlockages.1.compress(), EncBlockages1: &state.EncBlockages.1.compress(),
}, },