Skip to content

Commit

Permalink
added verification for assert
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineFONDEUR committed May 15, 2024
1 parent dca3d6c commit b94cd39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
16 changes: 16 additions & 0 deletions src/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b94cd39

Please sign in to comment.