Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Bug: fix to not invoke transfer for call related opcodes (except CALL)#335

Merged
CPerezz merged 6 commits into
privacy-ethereum:masterfrom
scroll-tech:fix/no-transfer-except-call
Dec 19, 2022
Merged

Bug: fix to not invoke transfer for call related opcodes (except CALL)#335
CPerezz merged 6 commits into
privacy-ethereum:masterfrom
scroll-tech:fix/no-transfer-except-call

Conversation

@silathdiir
Copy link
Copy Markdown
Contributor

@silathdiir silathdiir commented Dec 7, 2022

Close #334

Related circuit PR privacy-ethereum/zkevm-circuits#973

As issue described, there should be no transfer invocation for call related opcodes (except CALL) - CALLCODE, DELEGATECALL and STATICCALL.

And callee balance is also needed for checking account existence below (for now). Suppose if it could be fixed to replace with non-existing proofs after using in the BALANCE circuit.

@CPerezz CPerezz self-requested a review December 7, 2022 15:22
Copy link
Copy Markdown
Contributor

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

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

I'd use the lookup for non-existance of accounts

Comment thread src/zkevm_specs/evm/execution/callop.py Outdated
Comment on lines +126 to +129
# TODO:
# Suppose to fix to use non-existing proofs for account existence after it
# has been used for one opcode in zkevm-circuit.
# https://github.com/privacy-scaling-explorations/zkevm-circuits/pull/907
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.

This is already merged here in the specs. So I'm not sure why can't it be done here already. See: #291 which marks this as completed.

I think the specs should always try to be correct. And it's the circuits implementation who needs the "TODO"s, not this repo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deleted the TODO comment. And fixed to pass callee_exists via auxiliary witness data.

Comment thread src/zkevm_specs/evm/execution/callop.py Outdated
Comment on lines +123 to +131
instruction.is_zero(callee_nonce)
* instruction.is_zero(callee_balance_prev)
* is_empty_code_hash
instruction.is_zero(callee_nonce) * instruction.is_zero(callee_balance) * is_empty_code_hash
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.

I'd use the non_existance lookup here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Has been replaced with callee_exists.

Comment thread src/zkevm_specs/evm/execution/callop.py Outdated
)
else:
# Get callee balance for CALLCODE, DELEGATECALL and STATICCALL opcodes.
callee_balance = instruction.account_read(callee_address, AccountFieldTag.Balance)
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.

According to the CALLCODE implementation you linked in #334 (comment)
For CALLCODE you should constraint that value <= callee_balance right?
I think I didn't see this constraint.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed to add a constraint to verify caller balance is greater than or equal to stack value for both CALL and CALLCODE opcodes as below:

if is_call + is_callcode == 1:
    value_lt_caller_balance, value_eq_caller_balance = instruction.compare_word(
        value, caller_balance
)
instruction.constrain_zero(1 - value_lt_caller_balance - value_eq_caller_balance)

@lispc
Copy link
Copy Markdown
Collaborator

lispc commented Dec 9, 2022

@CPerezz don't need to be so strict...

Sometimes we prefer perfect PR, sometimes we prefer urgent PR. For the latter, as long as a PR is better than before, it can be accepted.

This issue is a bit urgent both for pse/zkevm-chain and scroll circuits, related to privacy-ethereum/zkevm-circuits#975 and privacy-ethereum/zkevm-circuits#969

@CPerezz
Copy link
Copy Markdown
Contributor

CPerezz commented Dec 9, 2022

Hey @lispc .

I'm not sure if I'm interpreting your message correctly. But let me be clear. I think that for a codebase this big and complex, being "strict" if you want to call it like this, is not crazy and rather what we all should be when we review.

I don't think I have asked anything crazy considering that we just need to remove 3 lines of code to include the existance lookup swapping it by the balance, codehash and value checks..

In any case, @ed255 I think is in the same line as I am. We cannot merge anything just for the purpose of being fast. And, instead, we should try to fix things propperly (without of course affecting the overall progress of the project).

Summarizing. Using here the non-existance lookup is a task we need to do in the close future and takes 1 day of work MAXIMUM. So why leaving more tech-debt behind when we can already fix it quickly here and avoid more TODO's??

@lispc
Copy link
Copy Markdown
Collaborator

lispc commented Dec 10, 2022

After some discussion we choose to let non-existing proofs be a TODO (future PR). @silathdiir

Anyway 1 day dev time does not mean 1 day diff in wall clock delivery time. Developers have other tasks to do, reviewers ditto.

@andyguzmaneth
Copy link
Copy Markdown
Collaborator

Hi @silathdiir ! Just checking in, are you good to apply the changes to merge this PR?

@silathdiir
Copy link
Copy Markdown
Contributor Author

silathdiir commented Dec 15, 2022

Hi @silathdiir ! Just checking in, are you good to apply the changes to merge this PR?

Yes. Will update this PR according to code review during this weekend. Thanks.

@andyguzmaneth
Copy link
Copy Markdown
Collaborator

Thank you!!

… constraint yo verify caller balance should be greater than or equal to stack `value` (only for CALL and CALLCODE).
@silathdiir
Copy link
Copy Markdown
Contributor Author

Hi @CPerezz and @ed255 , I updated this PR according to above comments. Could you help review again when you have time? Thanks.

@silathdiir silathdiir requested review from CPerezz and ed255 and removed request for CPerezz and ed255 December 18, 2022 02:46
@CPerezz CPerezz requested review from CPerezz and removed request for ed255 December 18, 2022 21:11
Copy link
Copy Markdown
Contributor

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

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

LGTM!

Thanks for this work @silathdiir 🥳

Comment thread specs/opcode/F1CALL_F2CALLCODE_F4DELEGATECALL_FASTATICCALL.md Outdated
Co-authored-by: Carlos Pérez <37264926+CPerezz@users.noreply.github.com>
@CPerezz CPerezz merged commit 0256fe2 into privacy-ethereum:master Dec 19, 2022
@silathdiir silathdiir deleted the fix/no-transfer-except-call branch December 19, 2022 10:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: should delete transfer for CALLCODE, DELEGATECALL and STATICCALL opcodes (except CALL)

5 participants