Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/circuit_gas_meter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function trackScriptExecutionGas(opCount: number, gasLimit = 100000): boolean {
if (opCount > gasLimit) throw new Error('Gas limit exceeded');
return true;
}
4 changes: 4 additions & 0 deletions lib/gas_meter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function calculateCircuitEvalGas(opCount: number, memoryBytes: number): number {
const baseGas = 100;
return baseGas + opCount * 2 + Math.floor(memoryBytes / 1024);
}
5 changes: 5 additions & 0 deletions lib/stack_guard.ts
Original file line number Diff line number Diff line change
@@ -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`);
}
}
7 changes: 7 additions & 0 deletions lib/timeout_guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function enforceEvalTimeout<T>(promise: Promise<T>, timeoutMs: number = 5000): Promise<T> {
let timer: NodeJS.Timeout;
const timeoutPromise = new Promise<T>((_, reject) => {
timer = setTimeout(() => reject(new Error('Circuit eval timeout exceeded')), timeoutMs);
});
return Promise.race([promise, timeoutPromise]).finally(() => clearTimeout(timer));
}
Loading