Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.

[DO NOT MERGE] Debug foundry nonce issues with multiple chains - #17

Draft
larskuhtz wants to merge 2 commits into
mainfrom
lars/test/chain-initialization
Draft

[DO NOT MERGE] Debug foundry nonce issues with multiple chains#17
larskuhtz wants to merge 2 commits into
mainfrom
lars/test/chain-initialization

Conversation

@larskuhtz

Copy link
Copy Markdown
Contributor

Usage

Run from the root of the repository via:

bash ./run-setup-tests.sh | column -s, -t

Notes

A separate deployer is a broadcast account that is different from the account that runs (msg.sender) the script or test.
The builtin deployer is the Foundry default sender account.

  • network (Anvil or external) has no effect on LOCAL_NONCE
  • SEPARATE_DEPLOYER=1 implies LOCAL_NONCE=1
  • BUILTIN_SENDER=1 implies LOCAL_NONCE=0

Conclusions

  • The builtin sender always uses global nonces, which is consistent with the
    design of foundry.
  • A separate deployer always uses local nonces, which is consistent with the
    design of foundry.
  • The use of an external account as sender for the test or script leads to
    inconsistent and unpredictable behavior.

Therefore the use of command lines flags like --sender or --private-key
should be avoided in the context of multiple chains.

Summary of inconsistent behavior

TYPE     INIT_IN_CONSTRUCTOR   SET_SENDER_IN_CONSTRUCTOR   LOCAL_NONCE
test     1                     1                           true
script   1                     1                           false
test     1                     0                           false
script   1                     0                           false
test     0                     1                           false
script   0                     1                           false
test     0                     0                           false
script   0                     0                           true

Details

No separate deployer:

TYPE     CHAINWEB   INIT_IN_CONSTRUCTOR   SET_SENDER_IN_CONSTRUCTOR   SEPARATE_DEPLOYER   BUILDIN_SENDER   LOCAL_NONCE
test     anvil      1                     1                           0                   0                true
script   anvil      1                     1                           0                   0                false
test     anvil      1                     1                           0                   1                false
script   anvil      1                     1                           0                   1                false
test     anvil      1                     0                           0                   0                false
script   anvil      1                     0                           0                   0                false
test     anvil      1                     0                           0                   1                false
script   anvil      1                     0                           0                   1                false
test     anvil      0                     1                           0                   0                false
script   anvil      0                     1                           0                   0                false
test     anvil      0                     1                           0                   1                false
script   anvil      0                     1                           0                   1                false
test     anvil      0                     0                           0                   0                false
script   anvil      0                     0                           0                   0                true
test     anvil      0                     0                           0                   1                false
script   anvil      0                     0                           0                   1                false

Separate deployer:

YPE     CHAINWEB   INIT_IN_CONSTRUCTOR   SET_SENDER_IN_CONSTRUCTOR   SEPARATE_DEPLOYER   BUILDIN_SENDER   LOCAL_NONCE
test     anvil      1                     1                           1                   0                true
script   anvil      1                     1                           1                   0                true
test     anvil      1                     1                           1                   1                true
script   anvil      1                     1                           1                   1                true
test     anvil      1                     0                           1                   0                true
script   anvil      1                     0                           1                   0                true
test     anvil      1                     0                           1                   1                true
script   anvil      1                     0                           1                   1                true
test     anvil      0                     1                           1                   0                true
script   anvil      0                     1                           1                   0                true
test     anvil      0                     1                           1                   1                true
script   anvil      0                     1                           1                   1                true
test     anvil      0                     0                           1                   0                true
script   anvil      0                     0                           1                   0                true
test     anvil      0                     0                           1                   1                true
script   anvil      0                     0                           1                   1                true

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.

1 participant