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

Update testool #1581

Merged
merged 10 commits into from
Sep 20, 2023
Merged

Update testool #1581

merged 10 commits into from
Sep 20, 2023

Conversation

adria0
Copy link
Member

@adria0 adria0 commented Sep 4, 2023

Description

This PR updates the testool

Type of change

  • New feature (non-breaking change which adds functionality)

Contents

  • Upstream some of the changes did by scroll-tech team
  • Removes the individual test selection that there are no longer useful in this stage (this feature was added initially for enabling/disabling some specific tests that that crashed)
  • Updates tests to last version (includes codehash.txt update)

@adria0 adria0 marked this pull request as draft September 4, 2023 10:03
@ChihChengLiang ChihChengLiang linked an issue Sep 4, 2023 that may be closed by this pull request
@adria0
Copy link
Member Author

adria0 commented Sep 4, 2023

Depends on #1554

@adria0 adria0 marked this pull request as ready for review September 4, 2023 10:33
@ChihChengLiang
Copy link
Collaborator

Run cargo test -p testool statetest::yaml::test::bad_balance to reproduce the failure.

I tried rebasing on #1585, but it didn't fix it. Need more investigation

@lispc
Copy link
Collaborator

lispc commented Sep 8, 2023

@ed255 i think the check itself may not be right? i checked the failed case, it indeed first do a Rw { is_write: true, filed: CodeHash, prev_value: 0x0, value: keccak(nil) }, then Rw { is_write: true, filed: Balance, prev_value: 0x0, value: 0x0 }. I think this pattern is right, should not be rejected.

Btw i made a change for this. Here i distinguish on "empty account" and "empty account but been created(writen codehash) " https://github.com/scroll-tech/zkevm-circuits/pull/819/files

@ed255
Copy link
Member

ed255 commented Sep 12, 2023

@ed255 i think the check itself may not be right? i checked the failed case, it indeed first do a Rw { is_write: true, filed: CodeHash, prev_value: 0x0, value: keccak(nil) }, then Rw { is_write: true, filed: Balance, prev_value: 0x0, value: 0x0 }. I think this pattern is right, should not be rejected.

I see an issue in this pattern. Currently the EndTx is doing the following in this case

  1. Create the coinbase account (by setting CodeHash to empty_hash)
  2. Transfer 0 ETH to coinbase

After this we end up with an account in the state that is empty, so technically it shouldn't exist. This account should not exists as a leaf in the MPT, because it's empty. I believe this can be solved in two ways:
a. Let the MPT circuit handle this case: whenever an update uses data of empty account, skip the proof
b. On the EVM circuits, make sure to never create an account that is empty.

I'm more favorable towards option b, because it's easy to add this logic to the EVM gadgets. For example take a look at how a transfer is handled in callop:


If the account doesn't exist but the transfer value is 0, the account is not created. I think we should treat the coinbase transfer in EndTx the same way. Something like this:

if !coinbase_balance.is_zero() {
  if coinbase_account.is_empty() {
    account_write(coinbase, CodeHash, empty_hash, zero)
  }
  account_write(coinbase, Balance, coinbase_balance, coinbase_balance_prev)
}

What do you think about this @lispc ?

@lispc
Copy link
Collaborator

lispc commented Sep 12, 2023

@ed255 i think the check itself may not be right? i checked the failed case, it indeed first do a Rw { is_write: true, filed: CodeHash, prev_value: 0x0, value: keccak(nil) }, then Rw { is_write: true, filed: Balance, prev_value: 0x0, value: 0x0 }. I think this pattern is right, should not be rejected.

I see an issue in this pattern. Currently the EndTx is doing the following in this case

  1. Create the coinbase account (by setting CodeHash to empty_hash)
  2. Transfer 0 ETH to coinbase

After this we end up with an account in the state that is empty, so technically it shouldn't exist. This account should not exists as a leaf in the MPT, because it's empty. I believe this can be solved in two ways: a. Let the MPT circuit handle this case: whenever an update uses data of empty account, skip the proof b. On the EVM circuits, make sure to never create an account that is empty.

I'm more favorable towards option b, because it's easy to add this logic to the EVM gadgets. For example take a look at how a transfer is handled in callop:

If the account doesn't exist but the transfer value is 0, the account is not created. I think we should treat the coinbase transfer in EndTx the same way. Something like this:

if !coinbase_balance.is_zero() {
  if coinbase_account.is_empty() {
    account_write(coinbase, CodeHash, empty_hash, zero)
  }
  account_write(coinbase, Balance, coinbase_balance, coinbase_balance_prev)
}

What do you think about this @lispc ?

Totally agree. We will change this

@z2trillion
Copy link
Collaborator

There is already a value_is_zero gadget in the TransferToGadget: https://github.com/privacy-scaling-explorations/zkevm-circuits/blob/main/zkevm-circuits/src/evm_circuit/util/common_gadget.rs#L345. We can use that to only update the code hash if the value > 0?

@github-actions github-actions bot added the crate-zkevm-circuits Issues related to the zkevm-circuits workspace member label Sep 18, 2023
@lispc
Copy link
Collaborator

lispc commented Sep 18, 2023

The "update branch" button disappeared?

Copy link
Collaborator

@ChihChengLiang ChihChengLiang left a comment

Choose a reason for hiding this comment

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

First round

testool/src/statetest/results.rs Outdated Show resolved Hide resolved
testool/src/statetest/executor.rs Show resolved Hide resolved
testool/Cargo.toml Outdated Show resolved Hide resolved
testool/src/statetest/executor.rs Outdated Show resolved Hide resolved
@ChihChengLiang
Copy link
Collaborator

@lispc, I saw the update branch button again.
I think the update branch button disappeared because it was even with the main branch.
I also noticed that #1609 was merged against the branch of this PR but not the main branch.

adria0 and others added 9 commits September 20, 2023 18:07
### Description

fix end_tx circuit coinbase transfer

### Issue Link


https://github.com/privacy-scaling-explorations/zkevm-circuits/actions/runs/6180463331/job/16776966002?pr=1581

### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Contents

- add rw_delta to TransferTo

### Rationale

N/A

### How Has This Been Tested?

previous failed unit test passed
Copy link
Collaborator

@ChihChengLiang ChihChengLiang left a comment

Choose a reason for hiding this comment

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

LGTM. (Shamelessly pat myself on the back)

I helped Adria to address the feedback because he couldn't reach his device recently due to personal reasons.

Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

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

LGTM!

@ChihChengLiang ChihChengLiang added this pull request to the merge queue Sep 20, 2023
Merged via the queue into main with commit 342faab Sep 20, 2023
13 checks passed
@ChihChengLiang ChihChengLiang deleted the feat/testool_scroll branch September 20, 2023 11:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crate-zkevm-circuits Issues related to the zkevm-circuits workspace member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upstream scroll-tech testool
6 participants