Skip to content

Commit 511ac92

Browse files
lukedawilsonLuke Wilson
andauthored
Verify message, signature and pubkey lengths for ed25519-verify (#58)
Co-authored-by: Luke Wilson <[email protected]>
1 parent 8279880 commit 511ac92

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/instance.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export const MAX_LENGTH_DB_VALUE: number = 128 * 1024;
1111
export const MAX_LENGTH_CANONICAL_ADDRESS: number = 64;
1212
export const MAX_LENGTH_HUMAN_ADDRESS: number = 256;
1313

14+
export const MAX_LENGTH_ED25519_SIGNATURE: number = 64;
15+
export const MAX_LENGTH_ED25519_MESSAGE: number = 128 * 1024;
16+
export const EDDSA_PUBKEY_LEN: number = 32;
17+
1418
export class VMInstance {
1519
public instance?: WebAssembly.Instance;
1620
public bech32: BechLib;
@@ -378,6 +382,10 @@ export class VMInstance {
378382
signature: Region,
379383
pubkey: Region
380384
): number {
385+
if (message.length > MAX_LENGTH_ED25519_MESSAGE) return 1;
386+
if (signature.length > MAX_LENGTH_ED25519_SIGNATURE) return 1;
387+
if (pubkey.length > EDDSA_PUBKEY_LEN) return 1;
388+
381389
const sig = Buffer.from(signature.data).toString('hex');
382390
const pub = Buffer.from(pubkey.data).toString('hex');
383391
const msg = Buffer.from(message.data).toString('hex');

test/imports.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ describe('do_ed25519_verify', () => {
591591
expect(result).toEqual(1);
592592
});
593593

594-
it.skip('fails for large sig', () => { // test is broken, only ever passed due to other tests mutating the test data
594+
it('fails for large sig', () => {
595595
const sig = new Uint8Array([...testData.EDDSA_SIG_HEX, 0x00]);
596596
const hashPtr = writeData(vm, testData.EDDSA_MSG_HEX);
597597
const sigPtr = writeData(vm, sig);

0 commit comments

Comments
 (0)