Skip to content
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

Merged
merged 6 commits into from
Sep 6, 2024

Conversation

AntoineFONDEUR
Copy link
Collaborator

bug: decoding error with constants

Time spent on this PR: 45 mins

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

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.

Copy link
Owner

@ClementWalter ClementWalter left a 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

Comment on lines +46 to +62
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;
}
}
Copy link
Owner

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.

Suggested change
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})`,
]),
);

Copy link
Owner

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.

ClementWalter
ClementWalter previously approved these changes Sep 6, 2024
@AntoineFONDEUR AntoineFONDEUR dismissed ClementWalter’s stale review September 6, 2024 10:50

The merge-base changed after approval.

@ClementWalter ClementWalter merged commit 22b6b51 into ClementWalter:main Sep 6, 2024
1 check passed
ClementWalter added a commit that referenced this pull request Sep 12, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: debug decode_instruction for 0x40780017fff7fff
2 participants