Skip to content

Commit 2cdae61

Browse files
fix(sdk-lib-mpc): throw in Dsg.endSession() when signature exists
Without the throw, endSession() silently reset dsgState to Uninitialized after signing, allowing init() to succeed again and enabling inadvertent session reuse on the same key share. Ticket: WAL-383
1 parent b28bbf2 commit 2cdae61

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

modules/sdk-lib-mpc/src/tss/ecdsa-dkls/dsg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class Dsg {
164164
*/
165165
endSession(): void {
166166
if (this._signature) {
167-
new Error('Session already ended because combined signature was produced.');
167+
throw new Error('Session already ended because combined signature was produced.');
168168
}
169169
if (this.dsgSession) {
170170
this.dsgSession.free();

modules/sdk-lib-mpc/test/unit/tss/ecdsa/dklsDsg.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,29 @@ describe('DKLS Dsg 2x3', function () {
217217
await party.init().should.be.rejectedWith(/Invalid messageHash length/);
218218
});
219219

220+
it('should throw in endSession() when signature has already been produced', async function () {
221+
const vector = vectors[0];
222+
const party1 = new DklsDsg.Dsg(
223+
fs.readFileSync(shareFiles[vector.party1]),
224+
vector.party1,
225+
vector.derivationPath,
226+
crypto.createHash('sha256').update(Buffer.from(vector.msgToSign, 'hex')).digest()
227+
);
228+
const party2 = new DklsDsg.Dsg(
229+
fs.readFileSync(shareFiles[vector.party2]),
230+
vector.party2,
231+
vector.derivationPath,
232+
crypto.createHash('sha256').update(Buffer.from(vector.msgToSign, 'hex')).digest()
233+
);
234+
const round4Messages = await executeTillRound(4, party1, party2);
235+
party1.handleIncomingMessages({
236+
p2pMessages: [],
237+
broadcastMessages: round4Messages[1].broadcastMessages,
238+
});
239+
should.exist(party1.signature);
240+
(() => party1.endSession()).should.throw('Session already ended because combined signature was produced.');
241+
});
242+
220243
it(`should fail when signing two different messages`, async function () {
221244
const party1 = new DklsDsg.Dsg(
222245
fs.readFileSync(`${__dirname}/fixtures/userShare`),

0 commit comments

Comments
 (0)