Skip to content

Commit

Permalink
test: catch invalid deserialization in spec tests and return false
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewkeil committed May 1, 2024
1 parent 152c960 commit e79ebad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions packages/beacon-node/test/spec/bls/bls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export const testFnByType: Record<string, "skip" | ((data: any) => any)> = {
*/
function aggregate_verify(input: {pubkeys: string[]; messages: string[]; signature: string}): boolean {
const {pubkeys, messages, signature} = input;
return aggregateVerify(messages.map(fromHexString), pubkeys.map(fromHexString), fromHexString(signature));
try {
return aggregateVerify(messages.map(fromHexString), pubkeys.map(fromHexString), fromHexString(signature));
} catch {
return false;
}
}

/**
Expand Down Expand Up @@ -142,7 +146,11 @@ function sign(input: {privkey: string; message: string}): string | null {
*/
function verify(input: {pubkey: string; message: string; signature: string}): boolean {
const {pubkey, message, signature} = input;
return _verify(fromHexString(message), fromHexString(pubkey), fromHexString(signature));
try {
return _verify(fromHexString(message), fromHexString(pubkey), fromHexString(signature));
} catch {
return false;
}
}

/**
Expand Down
12 changes: 10 additions & 2 deletions packages/beacon-node/test/spec/general/bls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ function aggregate(input: string[]): string {
*/
function aggregate_verify(input: {pubkeys: string[]; messages: string[]; signature: string}): boolean {
const {pubkeys, messages, signature} = input;
return aggregateVerify(messages.map(fromHexString), pubkeys.map(fromHexString), fromHexString(signature));
try {
return aggregateVerify(messages.map(fromHexString), pubkeys.map(fromHexString), fromHexString(signature));
} catch {
return false;
}
}

/**
Expand Down Expand Up @@ -185,5 +189,9 @@ function sign(input: {privkey: string; message: string}): string | null {
*/
function verify(input: {pubkey: string; message: string; signature: string}): boolean {
const {pubkey, message, signature} = input;
return _verify(fromHexString(message), fromHexString(pubkey), fromHexString(signature));
try {
return _verify(fromHexString(message), fromHexString(pubkey), fromHexString(signature));
} catch {
return false;
}
}

0 comments on commit e79ebad

Please sign in to comment.