-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: decoding error with constants #58
bug: decoding error with constants #58
Conversation
* bug: fixed Op0 display * fixed bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest that we instead try to use the size
of an instruction. If a given instruction is size = 2, then the following encoded instruction is a constant. Otherwise, we try to decode as an instruction, and if an error is raised, again, consider it's a constant
for (var i = 0; i < bytecode.length; i++) { | ||
programSheet | ||
.getRange(`A${i + 2}:B${i + 2}`) | ||
.setValues([ | ||
[ | ||
bytecode[i], | ||
isConstant | ||
? `=TO_SIGNED_INTEGER(A${i + 2})` | ||
: `=DECODE_INSTRUCTION(A${i + 2})`, | ||
], | ||
]); | ||
if (!isConstant) { | ||
isConstant = size(decodeInstruction(BigInt(bytecode[i]))) == 2; | ||
} else { | ||
isConstant = false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when possible, I prefer not to use "stateful" for loops, ie loops where an iteration depends on the previous ones.
for (var i = 0; i < bytecode.length; i++) { | |
programSheet | |
.getRange(`A${i + 2}:B${i + 2}`) | |
.setValues([ | |
[ | |
bytecode[i], | |
isConstant | |
? `=TO_SIGNED_INTEGER(A${i + 2})` | |
: `=DECODE_INSTRUCTION(A${i + 2})`, | |
], | |
]); | |
if (!isConstant) { | |
isConstant = size(decodeInstruction(BigInt(bytecode[i]))) == 2; | |
} else { | |
isConstant = false; | |
} | |
} | |
programSheet | |
.getRange(`A2:B${bytecode.length + 1}`) | |
.setValues( | |
bytecode.map((instruction, i) => [ | |
instruction, | |
i > 0 && size(decodeInstruction(BigInt(bytecode[i - 1]))) == 2 ? `=TO_SIGNED_INTEGER(A${i + 2})` : `=DECODE_INSTRUCTION(A${i + 2})`, | |
]), | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course we compute two times decodeInstruction
here so it's probably less efficient.
The merge-base changed after approval.
* added memory relocation * added full relocation * bug: decoding error with constants (#58) * bug: dealing with constants * bug: fixed Op0 display (#57) * bug: fixed Op0 display * fixed bug * bug: handle constants * removed gs 'IF' * removed size column * relocation with intermediate steps on gs * cleaned up code * clear proverSheet when loading new program * add formulas for relocation * run trunk check * update readme to indicate how to handle .js files * ran trunk * updated readme * changed name of initializeBuiltin * added memory relocation * added full relocation * relocation with intermediate steps on gs * cleaned up code * clear proverSheet when loading new program * add formulas for relocation * run trunk check * update readme to indicate how to handle .js files * ran trunk * updated readme * changed name of initializeBuiltin * Fix initial stack * Initialize builtins on the fly * Fix trunk --------- Co-authored-by: Clément Walter <[email protected]>
bug: decoding error with constants
Time spent on this PR: 45 mins
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
Currently an instruction is interpreted as a felt constant as long as it is a NOp and has a regular PCUpdate.
Resolves #54
What is the new behavior?
There is no way to make a difference between a felt constant and an instruction.
So the new behavior is to try to decode all instructions and no matter if it fails or not, it will convert the instruction to a decimal number in the right column.