-
Notifications
You must be signed in to change notification settings - Fork 378
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
feat(foundry): publish L2 state in @celo/devchain-anvil
#11107
feat(foundry): publish L2 state in @celo/devchain-anvil
#11107
Conversation
Small house-keeping change to keep Foundry-related bash scripts organised in a single directory. This script doesn't seem to be called from anywhere, and doesn't have a yarn command in `package.json` so it was fine to move it without any changes in other files.
7ac73f7
to
17dc558
Compare
feat: publish L2 state for
|
Severity Level | Results | |
---|---|---|
Contracts | Critical High Medium Low Note Total |
2 3 0 15 41 61 |
Dependencies | Critical High Medium Low Note Total |
0 0 0 0 0 0 |
For more details view the full report in OpenZeppelin Code Inspector
Two helper commands to run two Foundry-related bash scripts during local development.
Successfully deploys bytecode to `proxyAdminAddress`. Does not yet dump state correctly, or call functions to active L2 correctly.
1. `anvil-devchain:start-L2`: which creates and migrates an L2 devchain 2. `anvil-devchain:check-is-running`: which can be used to check that an anvil instance is running locally and serving at localhost:8546
Now successfully activates CeloDistributionSchedule. Does not yet dump state correctly
Simplifies maintenance and readability of scripts.
|
GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
---|---|---|---|---|---|
10538986 | Triggered | Generic High Entropy Secret | 1b90853 | packages/protocol/scripts/foundry/constants.sh | View secret |
10538986 | Triggered | Generic High Entropy Secret | 4a7606b | packages/protocol/scripts/foundry/constants.sh | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Simplifies maintenance and readability of scripts.
At this point, the migration works as intended and the L2 is activated. But, I haven't yet saved the devchain state file. I'll need to refactor the way the L1 and L2 move the state file around.
packages/protocol/scripts/foundry/load_and_migrate_l2_anvil_devchain.sh
Outdated
Show resolved
Hide resolved
@celo/devchain-anvil
@celo/devchain-anvil
…chain.sh` To keep it consistent with the L1 script
On CI it seems like `jq` doesn't find the artifacts without an explicit path ```sh ./scripts/foundry/create_and_migrate_anvil_devchain.sh shell: /usr/bin/bash -e {0} env: FOUNDRY_CACHE_KEY: 2 SUPPORTED_FOUNDRY_VERSION: nightly-f625d0fa7c51e65b4bf1e8f7931cd1c6e2e285e9 ANVIL_PORT: 8546 jq: error: Could not open file build/contracts/Registry.json: No such file or directory jq: error: Could not open file build/contracts/Proxy.json: No such file or directory ``` Source: https://github.com/celo-org/celo-monorepo/actions/runs/9808280627/job/27083755032#step:18:9
Can't find build artifacts on CI, so trying to work out what might be wrong.
Since the constants are read before any foundry compilation occured, the constants can't read from the Foundry artifacts. Locally, I missed this because I had existing artifacts from previous compilations.
Starting L1 from scratch instead of JSON state to circumvent this Anvil bug foundry-rs/foundry#7502.
(for future reference) This PR implements a workaround (in a906048) to prevent a known Anvil bug when loading state. Basically, I'm generating and running an L1 devchain from scatch, and use that to run the integration test here: celo-monorepo/.github/workflows/protocol-devchain-anvil.yml Lines 127 to 146 in a906048
This takes longer than simply starting an L1 devchain from JSON state, but prevents the Anvil bug when loading state. A better approach would be to start an anvil instance using JSON state like here: celo-monorepo/.github/workflows/protocol-devchain-anvil.yml Lines 138 to 154 in 28464b6
Anvil bugKnown issue:
The issue (foundry-rs/foundry#7502) is marked as fixed by this PR: Since we're not on the latest Foundry nightly, we won't be able to benefit from this PR until we bump our version. |
is there a script within this PR where you can import a L1 state and it'll dump the state after the L2? |
packages/protocol/scripts/foundry/create_and_migrate_anvil_l2_devchain.sh
Show resolved
Hide resolved
Co-authored-by: soloseng <[email protected]>
Co-authored-by: soloseng <[email protected]>
@martinvol: Good question, not in the current state. There is a limitation in Foundry that prevents us from loading state, and then dumping state to a different file. For example: $ anvil \
--port 8546 \
--state ~/Downloads/devchain-11107-2024-07-08/devchain.json \
--dump-state ~/Downloads/l2-devchain.json
error: the argument '--state <PATH>' cannot be used with '--dump-state <PATH>' But, this was a design I considered during this PR. We can circumvent this restriction by copying and renaming files during runtime like we do for L1: celo-monorepo/packages/protocol/scripts/foundry/create_and_migrate_anvil_devchain.sh Lines 67 to 68 in ff291e0
But, I took the view that it was overkill because it also required refactoring celo-monorepo/packages/protocol/scripts/foundry/start_anvil.sh Lines 23 to 26 in ff291e0
Definitely doable, but for the scope of this PR, which was to release an L2 devchain, I found the current approach to be the fastest path to an L2 devchain without significantly re-organising our scripts. We can refactor our bash and Foundry scripts to work differently if useful. |
… CELO Arbitrary amount chosen to be approximately equal to `GoldToken.totalSupply()` on the L1 Mainnet (695,313,643 CELO as of this commit). During the real L2 genesis, the VM will calculate and set an appropriate balance. ```sh # Get address of GoldToken $ cast call \ 0x000000000000000000000000000000000000ce10 \ "getAddressForStringOrDie(string calldata identifier)(address)" \ "GoldToken" \ --rpc-url https://forno.celo.org 0x471EcE3750Da237f93B8E339c536989b8978a438 # Call `totalSupply()` on `GoldToken.sol` $ cast call \ 0x471EcE3750Da237f93B8E339c536989b8978a438 \ "totalSupply()(uint256)" \ --rpc-url https://forno.celo.org 695313643195035937058427065 [6.953e26] # Convert units from wei to ether $ cast to-unit 695313643195035937058427065 ether 695313643.195035937058427065 ```
More context, examples, background, files in the package.
5c401a3
into
release/core-contracts/12
Description
create_and_migrate_anvil_l2_devchain.sh
) to create, migrate, and dump L1 and L2 devchain state to distinct JSON files (devchain.json
andl2-devchain.json
respectively).@celo/devchain-anvil
.Other changes
constants.sh
filerun_e2e_tests_in_anvil.sh
file to thescripts/foundry/
directory with other Foundry-related scripts.Migrations.s.sol
by Solidity version for better readabilityTested
Tested L2 migration script ✅
(in a separate terminal) Check that
proxyAdminAddress
has bytecode ✅$ cast rpc eth_getCode \ 0x4200000000000000000000000000000000000018 \ latest \ --rpc-url=http://127.0.0.1:8546 "0x608060405234801561001057600080fd5b506...
(in a separate terminal) Check that
isL2()
istrue
onCeloDistributionSchedule.sol
. ✅For context, we can call
isL2()
onCeloDistributionSchedule.sol
and other core contracts because they inherit fromIsL2Check.sol
Tested each new helper command locally from the `packages/protocol` directory ✅
Related issues
Backwards compatibility
Yes, existing L1 devchain is unchanged, only adding a new L2 devchain state JSON.
Documentation
The set of community facing docs that have been added/modified because of this change