Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EIP-3607 tests for Sender not EOA #963

Merged
merged 7 commits into from
Oct 17, 2021
Merged

Add EIP-3607 tests for Sender not EOA #963

merged 7 commits into from
Oct 17, 2021

Conversation

marioevz
Copy link
Member

This PR closes #952 .
The following test cases are included:

  • An account with non-empty code sends the following transactions: send value, calls a contract, calls itself, deploys contract, init code executes: call, delegatecall
  • An account with empty code attempts to init into a non-empty code address: contract deployment to non-empty address, init code executes: call, delegatecall, create, create2

All tests are negative test cases and correctly fail.

This PR excludes tests where create and create2 deploy to an existing address since this is already tested by: GeneralStateTests/stCreate2, GeneralStateTests/stCreateTest

@holiman
Copy link
Contributor

holiman commented Oct 13, 2021

Just reading the description, I think this PR might be a bit over-ambitious?
The thing is, any transaction made from a non-EOA account should be rejected out of hand. So I think it would be sufficient to test whether a basic 'send ether to a recipient', 'make a create-tx' are rejected or not. That said, I'm fine with it being as it is, just noting my thoughts.

Also, to clarify; this change should be retroactive, so could be extended for pre-berlin aswell, but that's not important either.

@marioevz
Copy link
Member Author

Thanks for the feedback, what I had in mind was that perhaps other clients implemented this differently and adding some extra checks just to be safe would be ok, but if everyone is inclined to reduce the number of test cases, that is also ok by me.
Also, I will change the fork to be retroactive.
Thanks again.

@qbzzt
Copy link
Collaborator

qbzzt commented Oct 13, 2021

Thanks for the feedback, what I had in mind was that perhaps other clients implemented this differently and adding some extra checks just to be safe would be ok, but if everyone is inclined to reduce the number of test cases, that is also ok by me.

My opinion is that having a few extra tests won't hurt anything, and might save us from an unspecified error in the future.

@MariusVanDerWijden
Copy link
Member

Reminder to self: selfdestruct a contract and send a tx from it after

@marioevz
Copy link
Member Author

Reminder to self: selfdestruct a contract and send a tx from it after

Added this test case in the latest commit.
I first tried the contract to send the self-destruct funds to itself, but since the account is deleted, the funds also are destroyed.

The test case I ended up writing:

  • Self-destruct sends the funds to another account
  • This other account returns the funds to the address that just self-destructed
  • The funds are then finally retrieved with the secretKey

Let me know if this is ok.
Thanks.

@holiman
Copy link
Contributor

holiman commented Oct 14, 2021

Let me know if this is ok.

👍 Looks good to me!

Copy link
Collaborator

@winsvega winsvega left a comment

Choose a reason for hiding this comment

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

I think can merge many tests into one and use data as array.

# Transaction originating from account with code
transaction:
data:
- ':raw 0x00'
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can define multiple data raws here.
all the transactions would get rejected. I don't think there is a much need to cover every possible init data code.
but because each state test is translated into bc test for each fork here. please limit the amount of tests.
if the pre state is the same you can define it in one file with different data raws.

- '400000'
gasPrice: '10'
nonce: '0'
to: ''
Copy link
Collaborator

Choose a reason for hiding this comment

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

the 2 cases here is really when transaction has destination.
and the second when it runs creation. (empty to) this are 2 different files

@@ -0,0 +1,80 @@
# Init into a non-empty account, call from init code

initNonEmptyAccount_call:
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is an interesting case. collision and wrong sender at the same time.

@winsvega
Copy link
Collaborator

yes a good test case but in blockchain test within one block
first transaction destroys the account (selfdestruct)
second one is coming from the destroyed account. (should be valid now, but fail due to the account empty balance)

@marioevz
Copy link
Member Author

yes a good test case but in blockchain test within one block

Yes this was created as a blockchain test in src/BlockchainTestsFiller/ValidBlocks/bcStateTests/contractSuicideThenSendFiller.yml

Also reduced the number of files as suggested in latest commit, and changed the fork to ">=London" to generate less tests.

value: !!int -1

network:
- '>=London'
Copy link
Collaborator

Choose a reason for hiding this comment

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

ok here could be >=Frontier

095e7baea6a6c7c4c2dfeb977efac326af552d87:
balance: '0'
nonce: '0'
code: ':raw 0xdeadbeef'
Copy link
Collaborator

Choose a reason for hiding this comment

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

put something meaningfull like 0x6000600155

value: !!int -1

network:
- '>=London'
Copy link
Collaborator

Choose a reason for hiding this comment

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

here >=Frontiner

@@ -0,0 +1,102 @@
# Account attempts to send tx to create a contract on a non-empty address

initNonEmptyAccount:
Copy link
Collaborator

Choose a reason for hiding this comment

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

put here that collision involved

- '>=London'

result:
6295ee1b4f6dd65047762f924ecd367c17eabf8f:
Copy link
Collaborator

Choose a reason for hiding this comment

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

check a94f5374fce5edbc8e2a8697c15331677e6ebf0b nonce

0xfebc70C40FadB14d796F1d499b3f247e12FBbd94:
balance: '10000000000'
nonce: '0'
code: :raw 0x737ae27a42774a1f034ac7edb93d23cb5a662017d5FF
Copy link
Collaborator

Choose a reason for hiding this comment

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

source code???


# We send back the assets received from the self-destruct opcode
- data: ''
gasLimit: 21000
Copy link
Collaborator

Choose a reason for hiding this comment

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

put more gaslimit as it tend to change to higher number in the future forks

@@ -0,0 +1,92 @@
# Contract self-destructs and then a private key with colliding address attempts to retrieve value from the account.

contractSuicideThenSend:
Copy link
Collaborator

Choose a reason for hiding this comment

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

transaction from selfdestruct

0xd0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0:
balance: '9995800000'

0xfebc70C40FadB14d796F1d499b3f247e12FBbd94:
Copy link
Collaborator

Choose a reason for hiding this comment

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

check nonce

@winsvega winsvega merged commit 779a31c into develop Oct 17, 2021
@winsvega winsvega deleted the eip3607 branch October 17, 2021 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include tests for EIP-3607
5 participants