Skip to content

Commit 4194f21

Browse files
correct issue on ed25519 full session
solving parity mistake with ed25519: - faulty use of & instead of && - magic number used for curve order inside Psig
1 parent f5cd168 commit 4194f21

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/libMPC/SCL_Musig2.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ Psign(secnonce, sk, session_ctx){
356356
//todo : test range of k1 and k2
357357
if (this.curve.Has_even_y(R)==false)
358358
{
359-
k1=secp256k1.CURVE.n-k1;
360-
k2=secp256k1.CURVE.n-k2;
359+
k1=this.order-k1;
360+
k2=this.order-k2;
361361
}
362362
let d_ = int_from_bytes(sk)
363363
//todo : test range d

src/libMPC/SCL_ecc.mjs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,13 @@ export class SCL_ecc
9292
return true;
9393
}
9494
if (this.curve === 'ed25519'){
95-
if( (RawHex_Point[0]&&(0x80)==0x80))
95+
if( ( (RawHex_Point[0]&(0x80))==0x80))
9696
{
9797
return false;
9898
}
99-
else
99+
else {
100100
return true;
101+
}
101102
}
102103
}
103104

@@ -142,8 +143,9 @@ export class SCL_ecc
142143
return bytePoint.slice(1,33);//x-only version for noncegen
143144
}
144145
if(this.curve=='ed25519') {
145-
bytePoint[0]=bytePoint[0]&0x7f;//nullify to force parity bit to 0
146-
return bytePoint;
146+
let cp=Buffer.from([...bytePoint]);//avoid destruction of input
147+
cp[0]=cp[0]&0x7f;//force parity bit to 0
148+
return cp;
147149
}
148150

149151
}
@@ -172,9 +174,10 @@ export class SCL_ecc
172174
return P;
173175
}
174176
if (this.curve === 'ed25519') {
175-
bytePointX[0]=bytePointX[0]&0x7f;//nullify to force parity bit to 0
177+
let cp=Buffer.from([...bytePointX]);//avoid destruction of input
178+
cp[0]=cp[0]&0x7f;//force parity bit to 0
176179

177-
return ed25519.ExtendedPoint.fromHex(reverse(bytePointX));
180+
return ed25519.ExtendedPoint.fromHex(reverse(cp));
178181
}
179182
throw new Error('Unsupported curve');
180183
}

src/libMPC/test_Musig2.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,9 @@ function random_fullsession(Curve){
371371

372372
let psigs=[p1,p2];
373373

374+
console.log(" -Aggregating signature");
374375
let res=signer.Partial_sig_agg(psigs, session_ctx);
375-
console.log("Aggregated signature=", res, res.length);
376+
console.log("res", res, res.length);
376377

377378
console.log(" -Final Schnorr verify:");
378379

0 commit comments

Comments
 (0)