Circuit for opcode BALANCE#683
Conversation
|
Blocked by privacy-ethereum/zkevm-specs#248 which is at the same time blocked by privacy-ethereum/zkevm-specs#249 |
6c27908 to
b50ea9f
Compare
|
Will try to update this PR since #907 has been merged. |
1730635 to
2fd71d5
Compare
|
Hi @CPerezz , I updated this |
CPerezz
left a comment
There was a problem hiding this comment.
Just wondering the balance passed in the assignation of the Opcode circuit impl.
For the rest this looks good. If you cold provide feedback, I'll approve immediately!
| let balance = if exists { | ||
| block.rws[step.rw_indices[5]] | ||
| .table_assignment_aux(block.randomness) | ||
| .value |
There was a problem hiding this comment.
I'm unsure why do we need block.randomness to set the balance. Is it passed directly as an RLC??
There was a problem hiding this comment.
Hi @CPerezz , I checked function table_assignment_aux. But it seems that only value is needed here, so I replaced it with value_assignment(block.randomness).
And reference function value_assignment, it seems that the argument randomness is used in function random_linear_combine as below:
AccountFieldTag::CodeHash | AccountFieldTag::Balance => {
RandomLinearCombination::random_linear_combine(value.to_le_bytes(), randomness)
}
There was a problem hiding this comment.
Hi @CPerezz , could you help review this again when you have time? Thanks.
5842d77 to
129d531
Compare
CPerezz
left a comment
There was a problem hiding this comment.
LGTM! I'd want another review from someone at Scroll before merging this! @icemelon or @silathdiir could you ping someone? 😄
Yes. I will ping others to help review. Thanks a lot. |
| + (1.expr() - is_warm.expr()) * GasCost::COLD_ACCOUNT_ACCESS.expr(); | ||
|
|
||
| let step_state_transition = StepStateTransition { | ||
| rw_counter: Delta(cb.rw_counter_offset()), |
There was a problem hiding this comment.
rw_counter: Delta(cb.rw_counter_offset()), not good style since we don't know exactly rw counter change, suggest to use normal way rw_counter: 7.expr()
There was a problem hiding this comment.
Replaced cb.rw_counter_offset() with 7.expr().
| /// Error generated by this step | ||
| pub error: Option<ExecError>, | ||
| /// Non existent account addresses | ||
| pub non_existent_accounts: HashSet<Address>, |
There was a problem hiding this comment.
most probably do not need this, for circuit side, existing can be check by reading buss mapping record, for AccountFieldTag::NonExisting, no need additional step info.
There was a problem hiding this comment.
Yes exactly 🙏, I fixed to get both balance and exists in circuit function assign_exec_step as below:
let (balance, exists) = match block.rws[step.rw_indices[5]] {
Rw::Account {
field_tag: AccountFieldTag::Balance,
value,
..
} => (
RandomLinearCombination::random_linear_combine(
value.to_le_bytes(),
block.randomness,
),
true,
),
Rw::Account {
field_tag: AccountFieldTag::NonExisting,
..
} => (F::zero(), false),
_ => unreachable!(),
};
| /// The opcode corresponds to the step | ||
| pub opcode: Option<OpcodeId>, | ||
| /// Non existent account addresses | ||
| pub non_existent_accounts: HashSet<Address>, |
There was a problem hiding this comment.
same as above comment, suggest to remove
|
|
||
| let address = block.rws[step.rw_indices[0]].stack_value().to_address(); | ||
| let mut address_bytes = address.0; | ||
| address_bytes.reverse(); |
There was a problem hiding this comment.
want to know what reason for reverse it
There was a problem hiding this comment.
Try to investigate ethers_core::types::Address and code in eth-types, it seems that the Address is big endian.
|
|
||
| let exists = cb.query_bool(); | ||
| let balance = cb.condition(exists.expr(), |cb| { | ||
| let balance = cb.query_cell(); |
There was a problem hiding this comment.
can the "query_cell" be moved out of the closure? It is some "structure/allocation" info, better not be guarded with "if" branch.
There was a problem hiding this comment.
Moved out query_cell as:
let balance = cb.query_cell();
let exists = cb.query_bool();
cb.condition(exists.expr(), |cb| {
cb.account_read(
from_bytes::expr(&address.cells),
AccountFieldTag::Balance,
balance.expr(),
);
});
| cb.stack_push(select::expr(exists.expr(), balance.expr(), 0.expr())); | ||
|
|
||
| let gas_cost = is_warm.expr() * GasCost::WARM_ACCESS.expr() | ||
| + (1.expr() - is_warm.expr()) * GasCost::COLD_ACCOUNT_ACCESS.expr(); |
There was a problem hiding this comment.
Fixed to:
let gas_cost = select::expr(
is_warm.expr(),
GasCost::WARM_ACCESS.expr(),
GasCost::COLD_ACCOUNT_ACCESS.expr(),
);
Sorry for the wrong revert. Fixed to |
* implement RLC chip * keccak table interfaces * minor * mock chunk tests * aggregation tests * fixes * supporing empty hash preimage * minor * remove tmp data * clean up and address comments * update docs * partial fix clippy * fix chunk construction bug * fix compiling bug * fix padded chunk's data hash * fix bug in number of valid chunks * handle the case of all valid ones * add fixed columns to rlc config * enforce the chunks are orderred * fix bugs in challenges * add missing selectors for aggregation circuit * fix the fixed cells (privacy-ethereum#677) * try to reenable skip first pass * tr to fix skip first pass again * try to fix again * clean up * fixed skip first pass * aggregation parameter with k = 19 * removing unused features; partial address comments * fix clippy * fix clippy * address comment on fixed cells * fix dynamic hash test * try to fix new fixed cells * reverting last 3 commits * Add conversion from witness `Block` to `ChunkHash`. (privacy-ethereum#683) --------- Co-authored-by: Steven <asongala@163.com>
Spec: privacy-ethereum/zkevm-specs#248
Summary
BALANCEbus-mapping and add circuit.Balanceif account exists, otherwise lookupNonExisting.HashSetto save non-existent account addresses in both bus-mapping and circuitExeSteps.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.
Blocked by PR #907