From b94cd3991cb3324430c669726df8f34fc17e1b71 Mon Sep 17 00:00:00 2001 From: Antoine FONDEUR Date: Wed, 15 May 2024 23:21:13 +0200 Subject: [PATCH] added verification for assert --- src/utils.ts | 10 ++++++++++ src/vm.ts | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/utils.ts b/src/utils.ts index 9c8b028..6ed4c29 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -14,3 +14,13 @@ function getLastActiveRowIndex(column: string): number { .getRow(); return index; } + +function opcodeAssertions(instruction: decodedInstruction, operandsValue: operands): void{ + switch (instruction.Opcode){ + case Opcodes.AssertEq: + if (Number(operandsValue.dst) !== Number(operandsValue.res)){ + throw new AssertEqError(); + } + break; + } +} \ No newline at end of file diff --git a/src/vm.ts b/src/vm.ts index fb9c512..4383e04 100644 --- a/src/vm.ts +++ b/src/vm.ts @@ -47,6 +47,13 @@ const builtins = { poseidon: null, }; +type operands = { + op0: number | string; + op1: number | string; + dst: number | string; + res: number | string; +}; + const program: any[][] = programSheet.getRange("A2:A").getValues(); function initialize_builtins(): void { @@ -218,6 +225,15 @@ function step(n: number = 0): void { let resValue: string | number = runSheet .getRange(`${resColumn}${n + 2}`) .getDisplayValue(); + + let operandsValue: operands = { + op0: op0Value, + op1: op1Value, + res: resValue, + dst: dstValue, + }; + + opcodeAssertions(instruction, operandsValue); let newPc: string | number; switch (instruction.PcUpdate) {