From 57fdcb1001f9c45cb1bdb98185279c0e5fede1e6 Mon Sep 17 00:00:00 2001 From: Rodrigoue9 Date: Fri, 21 Aug 2026 15:04:46 -0300 Subject: [PATCH 1/4] feat(eval): add deterministic execution gas meter to prevent infinite loops in circuit scripts --- lib/circuit_gas_meter.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 lib/circuit_gas_meter.ts diff --git a/lib/circuit_gas_meter.ts b/lib/circuit_gas_meter.ts new file mode 100644 index 00000000..6fb3d122 --- /dev/null +++ b/lib/circuit_gas_meter.ts @@ -0,0 +1,4 @@ +export function trackScriptExecutionGas(opCount: number, gasLimit = 100000): boolean { + if (opCount > gasLimit) throw new Error('Gas limit exceeded'); + return true; +} From 9f6618444f6d0a26a593f183390a231dd66bd377 Mon Sep 17 00:00:00 2001 From: Rodrigoue9 Date: Sat, 22 Aug 2026 08:21:24 -0300 Subject: [PATCH 2/4] feat(eval): deliver standardized clean deliverable --- lib/gas_meter.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 lib/gas_meter.ts diff --git a/lib/gas_meter.ts b/lib/gas_meter.ts new file mode 100644 index 00000000..4f6b25c7 --- /dev/null +++ b/lib/gas_meter.ts @@ -0,0 +1,4 @@ +export function calculateCircuitEvalGas(opCount: number, memoryBytes: number): number { + const baseGas = 100; + return baseGas + opCount * 2 + Math.floor(memoryBytes / 1024); +} From bfa7138a2270ce609e8ae3a6b29c4adcac551e58 Mon Sep 17 00:00:00 2001 From: Rodrigoue9 Date: Sat, 22 Aug 2026 08:25:58 -0300 Subject: [PATCH 3/4] feat(eval): circuit simulation execution timeout and memory leak guard --- lib/timeout_guard.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 lib/timeout_guard.ts diff --git a/lib/timeout_guard.ts b/lib/timeout_guard.ts new file mode 100644 index 00000000..a5d16cd9 --- /dev/null +++ b/lib/timeout_guard.ts @@ -0,0 +1,7 @@ +export function enforceEvalTimeout(promise: Promise, timeoutMs: number = 5000): Promise { + let timer: NodeJS.Timeout; + const timeoutPromise = new Promise((_, reject) => { + timer = setTimeout(() => reject(new Error('Circuit eval timeout exceeded')), timeoutMs); + }); + return Promise.race([promise, timeoutPromise]).finally(() => clearTimeout(timer)); +} From fe1ba3d35a42259c4d8c5a90ff48074ead6cd31f Mon Sep 17 00:00:00 2001 From: Rodrigoue9 Date: Sat, 22 Aug 2026 08:34:58 -0300 Subject: [PATCH 4/4] feat(eval): recursive schematic expansion stack depth limit guard --- lib/stack_guard.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 lib/stack_guard.ts diff --git a/lib/stack_guard.ts b/lib/stack_guard.ts new file mode 100644 index 00000000..5cbab06a --- /dev/null +++ b/lib/stack_guard.ts @@ -0,0 +1,5 @@ +export function checkCallStackDepth(currentDepth: number, maxDepth: number = 250): void { + if (currentDepth > maxDepth) { + throw new Error(`Maximum schematic expansion depth of ${maxDepth} exceeded`); + } +}