-
Notifications
You must be signed in to change notification settings - Fork 2
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
Refactor Instruction type, catch more errors during transpilation #305
Conversation
ccd05c5
to
6116e23
Compare
d93f649
to
c404c64
Compare
pub global_clk: u64, | ||
|
||
/// The clock increments by 4 (possibly more in syscalls) for each instruction that has been | ||
/// The gas counter increments by 4 (possibly more in syscalls) for each instruction that has been |
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.
In case of clock I would understand that as instructions can take multiple clock ticks, but why we are keeping the same behavior for gas counter?
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.
It's the opposite in our situation. The clock (global_clk
) ticks once per executed instruction. The gas counter, on the other hand, measures how much "work" has been done already and counts 4 per instruction + an extra cost of some syscalls (these are not "instructions").
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.
But why the cost of each instruction is 4 gas points? What is the reason to keep gas cost == ((number of executed instructions) >> 2) + sum(cost of called syscalls)
?
Why it is 4 instead of (what seems to be more intuitive) 1, or instead of any randomly chosen other number?
That leads to the situation where syscall can cost less than any other instruction.
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.
It's an arbitrary number. The exact number doesn't matter; what matters is the cost of each instruction/syscall relative to each of the others. The value 4 seemed reasonable to me; it allows a little bit of flexibility if a "cheaper" instruction type were ever introduced in the future.
9812c8d
to
7c76746
Compare
7c76746
to
5f8631e
Compare
Following up after #304, closes #18.
Refactored
Instruction
type to anenum
with each instruction variant having exactly the operands it needs. Invalid instructions (wrong operand types, registers out of range etc.) are now caught during transpilation instead of runtime and generally, more invariants are guaranteed to be upheld.