Spec for opcode BALANCE#248
Conversation
CPerezz
left a comment
There was a problem hiding this comment.
The implementation looks good.
Some questions regarding the markdown specs.
Co-authored-by: Carlos Pérez <37264926+CPerezz@users.noreply.github.com>
|
To be honest I'm not sure about:
This got me thinking. I'd say yes, we definitely need to do this check right? But how? How can we assert that an account exists? This would require a lookup and I think we don't have any mechanism in our tables (see https://github.com/privacy-scaling-explorations/zkevm-specs/blob/master/specs/tables.md) that allows us to gather this info. We would need to have a table with all the accounts for which we need to check it's existance. Or at the very least, to add a tag for this thing in the rw table for example. |
Here's a summary of a discussion we had about this via chat: There are 2 options for the MPT table API.
Some circuits require proving that an account doesn't exist. With option B that is done with a single lookup. With option A that would be done with the check I'm more favorable towards option B. For this PR I would say to go with one of the options (probably option A is simpler), and then we can revisit all lookups to non-existing accounts if necessary once we settle on which option we take. |
|
Pending on #249 update |
|
Hey @silathdiir I think that #249 is close enough to be merged that this will not be necessary. And we can wait, rebase this on the top of the new main and then resolve the TODO in this PR. Note that this means that we'll need to go for option 2. |
Got it. Will try to update after #249 is closed. Thanks. |
|
#291 should unlock this PR |
|
@silathdiir #291 has just been merged, so this PR is now unlocked to be completed :) |
Thanks a lot. I updated this PR according to #291 (will update similar code of extcodehash in another PR). @CPerezz @ed255 please help review again when you have time. Thanks. |
| address, | ||
| True, | ||
| is_warm, | ||
| rw_counter_of_reversion=rw_counter_end_of_reversion - reversible_write_counter, |
There was a problem hiding this comment.
Is reversible_write_counter always zero?
There was a problem hiding this comment.
I tried to review reversible-write-reversion doc. It seems that reversible_write_counter should be initialized to 0.
And I referenced the code of test_extcodecopy.py and test_extcodehash.py.
There was a problem hiding this comment.
I readed the document for first time, and, ups, it's tricky!
BTW I changed with random values this lines in SLOAD and test are passing
so are we missing something here? (cc/ @ed255 @ChihChengLiang )
unsure about this revertion parameters, but for the rest, LGTM
There was a problem hiding this comment.
I think in this test the rw_counter_end_of_reversion and reversible_write_counter are not super relevant because we're only checking the constraints of the BALANCE step with the STOP/REVERT step as next. But we're not checking the constraints of the STOP/REVERT step.
The constraints related to rw_counter_end_of_reversion and reversible_write_counter are checked during the REVERT step, so even if we have wrong values here the test would pass.
As @silathdiir reversible_write_counter should start at 0 when a call begins. I think rw_counter_end_of_reversion should be 9 + the count of reversible operations that happened (which I think should be 1 for the account access list write).
There was a problem hiding this comment.
Fixed rw_counter_end_of_reversion to 10 with comment:
# 9 + 1 reversible operation (the account access list write)
rw_counter_end_of_reversion = 0 if is_persistent else 10
| address, | ||
| True, | ||
| is_warm, | ||
| rw_counter_of_reversion=rw_counter_end_of_reversion - reversible_write_counter, |
There was a problem hiding this comment.
I readed the document for first time, and, ups, it's tricky!
BTW I changed with random values this lines in SLOAD and test are passing
so are we missing something here? (cc/ @ed255 @ChihChengLiang )
unsure about this revertion parameters, but for the rest, LGTM
| address, | ||
| True, | ||
| is_warm, | ||
| rw_counter_of_reversion=rw_counter_end_of_reversion - reversible_write_counter, |
There was a problem hiding this comment.
I think in this test the rw_counter_end_of_reversion and reversible_write_counter are not super relevant because we're only checking the constraints of the BALANCE step with the STOP/REVERT step as next. But we're not checking the constraints of the STOP/REVERT step.
The constraints related to rw_counter_end_of_reversion and reversible_write_counter are checked during the REVERT step, so even if we have wrong values here the test would pass.
As @silathdiir reversible_write_counter should start at 0 when a call begins. I think rw_counter_end_of_reversion should be 9 + the count of reversible operations that happened (which I think should be 1 for the account access list write).
…e` lookup if `exists == 1`, and `non-existing` lookup otherwise.
ed255
left a comment
There was a problem hiding this comment.
I noticed that in a few places the rwc counter increase is outdated (check my suggested changes).
Other than that, everything looks good!
Co-authored-by: Eduard S. <eduardsanou@posteo.net>
Co-authored-by: Eduard S. <eduardsanou@posteo.net>
Co-authored-by: Eduard S. <eduardsanou@posteo.net>
I updated code according to the suggestions. Thanks a lot. |
Circuit: privacy-ethereum/zkevm-circuits#683
Not confirm if necessary to constrain "If the given account doesn't exist, then it will push 0 onto the stack instead." in the circuit.And is there a method (could be used in circuit) to lookup if account is existing? Thanks.