Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions bus-mapping/src/evm/opcodes/callop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,23 @@ impl<const N_ARGS: usize> Opcode for CallOpcode<N_ARGS> {
debug_assert!(found);

let caller_balance = sender_account.balance;
let insufficient_balance = call.value > caller_balance;
let is_call_or_callcode = call.kind == CallKind::Call || call.kind == CallKind::CallCode;
let insufficient_balance = call.value > caller_balance && is_call_or_callcode;

log::debug!(
"insufficient_balance: {}, call type: {:?}, sender_account: {:?} ",
insufficient_balance,
call.kind,
call.caller_address
);
Comment thread
DreamWuGit marked this conversation as resolved.

// read balance of caller to compare to value for insufficient_balance checking
// in circuit, also use for callcode successful case check balance is
// indeed larger than transfer value. for call opcode, it does in
// tranfer gadget implicitly.
state.account_read(
&mut exec_step,
call.address,
call.caller_address,
AccountField::Balance,
caller_balance,
caller_balance,
Expand Down
5 changes: 2 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/callop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {

let caller_balance_word = cb.query_word_rlc();
cb.account_read(
callee_address.expr(),
caller_address.expr(),
AccountFieldTag::Balance,
caller_balance_word.expr(),
);
Expand Down Expand Up @@ -488,8 +488,7 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
self.is_insufficient_balance
.assign(region, offset, caller_balance, value)?;

let is_insufficient = value > caller_balance;

let is_insufficient = (value > caller_balance) && (is_call || is_callcode);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The corresponding circuit expression only does is_insufficient = value > caller_balance. This is because when not(is_call || is_callcode) then value = 0 so value > caller_balance == 0 > caller_balance == false.

So I believe adding the && (is_call || is_callcode here is redundant. Nevertheless maybe it makes things more clear? This is just an observation, not a request to change anything.

// only call opcode do transfer in sucessful case.
let (caller_balance_pair, callee_balance_pair) = if is_call & !is_insufficient {
rw_offset += 2;
Expand Down