foundry icon indicating copy to clipboard operation
foundry copied to clipboard

bug: invariant test chooses contract senders which are rejected due to EIP-3607

Open mds1 opened this issue 3 years ago • 1 comments

Component

Forge

Have you ensured that all of these are up to date?

  • [ ] Foundry
  • [ ] Foundryup

What version of Foundry are you on?

forge 0.2.0 (56dc746 2022-08-26T00:07:43.474069Z)

What command(s) is the bug in?

forge test

Operating System

No response

Describe the bug

Using the same test contract as https://github.com/foundry-rs/foundry/issues/2962, sometimes the sender will be a contract chosen from the dictionary. In that case the call reverts with [FAIL. Reason: EvmError: RejectCallerWithCode] due to EIP-3607, similar to https://github.com/foundry-rs/foundry/pull/2090

IMO the ideal solution here is to bypass 3607 since the msg.sender can have code, and this is referring to the fact that tx.origin cannot have code which isn't too relevant for invariant tests.

mds1 avatar Aug 26 '22 15:08 mds1

Yeah implementing the same fix as #2090 here makes sense.

gakonst avatar Aug 26 '22 20:08 gakonst

@mattsse can you pls take a look tomorrow on this? should be simple fix and apparently a big issue for invariant users

gakonst avatar Nov 03 '22 20:11 gakonst

Can confirm that this is a big pain when testing invariants.

What is the fix until this issue gets fixed? Exclude all known contracts with excludeSender?

Update: the solution is to use targetSender, as Lucas Manuel does in his example-invariants repo.

Though I am not quite sure why this works. Does targetSender act as an allowlist? I have opened an issue in forge-std to document the functions available in InvariantTest.

PaulRBerg avatar Jan 25 '23 14:01 PaulRBerg

Looks like #4181 has been merged. Should this issue be closed now?

Update: no, we shouldn't close this issue just yet. I updated Forge via foundryup and removed my targetSender calls, but I am still getting this error:

FAIL. Reason: EvmError: RejectCallerWithCode

PaulRBerg avatar Jan 27 '23 10:01 PaulRBerg

it's not on foundryup yet, but I'm cutting a release now manually

mattsse avatar Jan 27 '23 10:01 mattsse

Oh, I see, thanks.

PaulRBerg avatar Jan 27 '23 11:01 PaulRBerg

@mattsse looks like this is fixed now. I updated via foundryup recently, removed my targetSender call, and my invariant tests passed.

PaulRBerg avatar Jan 31 '23 12:01 PaulRBerg