Skip to content

Commit

Permalink
refactor(vm): use trySync instead of try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocao committed Sep 9, 2024
1 parent 336c5f7 commit e1ad4a8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions libs/vm/src/vm-imports.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Secp256k1 from "@noble/secp256k1";
import { Maybe } from "true-myth";
import { keccak256, secp256k1Verify } from "./services/crypto";
import { trySync } from "./services/try";
import { type HttpFetchAction, HttpFetchResponse } from "./types/vm-actions";
import { PromiseStatus } from "./types/vm-promise";
import { WorkerToHost } from "./worker-host-communication.js";
Expand Down Expand Up @@ -145,17 +146,21 @@ export default class VmImports {
),
);

try {
this.callResult = secp256k1Verify(message, signature, publicKey);
return this.callResult.length;
} catch (error) {
const result = trySync(() =>
secp256k1Verify(message, signature, publicKey),
);

if (result.isErr) {
console.error(
`[${this.processId}] - @secp256k1Verify: ${message}`,
error,
result.error,
);
this.callResult = new Uint8Array();
return 0;
}

this.callResult = result.value;
return this.callResult.length;
}

callResultWrite(ptr: number, length: number) {
Expand Down

0 comments on commit e1ad4a8

Please sign in to comment.