Repository navigation
fix(contracts): Validate deploy script parameters - #576
Merged
Merged
Conversation
Once a queued operation's delay has passed anyone may execute it, and OZ Governor lets only the proposer cancel before voting starts. Without a canceller nobody could veto a passed proposal during the delay, so the script now refuses to deploy without TIMELOCK_CANCELLER. The Base Sepolia governance rehearsal passes its guardian as canceller and checks the role.
…ript MAX_ISSUANCE and EARLIEST_SWEEP_TS cannot be changed once the token and vault exist. The script now refuses an issuance other than 150M PEN in 18-decimal units and a sweep floor that is not a future unix time in seconds within the next two years, so a units slip fails before anything is broadcast. It also broadcasts explicitly as msg.sender, the address it already hands the interim admin role to, and returns the deployed contracts. That leaves forge script behaviour unchanged and lets a Foundry test run the script itself: the new test covers each refusal and the happy path.
Most governance parameters are fixed at deploy or can only be changed by a proposal through the governor being deployed, so the script now checks each one before broadcasting: - PEN_TOKEN must be the token of the new VAULT_ADDRESS - TIMELOCK_DELAY is 48h to 30 days; VOTING_DELAY and VOTING_PERIOD are at most 30 days, checked before narrowing to the governor's types - PROPOSAL_THRESHOLD and QUORUM_FLOOR are 18-decimal units between 1 PEN and the total supply, so a whole-PEN figure is refused - TIMELOCK_CANCELLER must not be the deployer and must have code TEST_DEPLOY=true admits the shorter delay, a codeless canceller and a zero floor that testnet drills use, and is refused on Base mainnet. The Base Sepolia rehearsal sets it and passes the vault address. The script broadcasts as msg.sender and returns the deployed contracts, so a Foundry test now runs it: each refusal, the drill override, and the role wiring (the deployer keeps no timelock role, the canceller holds CANCELLER_ROLE).
…overnor tests The canceller is meant to be a dedicated Safe, separate from the pause guardian, so the governor test fixture now grants CANCELLER_ROLE to its own address instead of the guardian's. The Base Sepolia drill keeps reusing its guardian key for the role and now says so.
Having code on the chain is true of any contract, so the governance deploy script now asks the canceller for its Safe threshold instead: getThreshold() must succeed and return a non-zero value, and an EIP-7702 delegated EOA is refused whatever it delegates to. The canceller must also not be PEN_TOKEN, VAULT_ADDRESS or the vault's guardian. TEST_DEPLOY keeps admitting a canceller that is not a Safe and the guardian key, which the testnet drills reuse. The deploy test now uses a stub that answers getThreshold() and covers each refusal.
VOTING_DELAY and VOTING_PERIOD only had an upper bound, so days entered as seconds produced a governor with a vote of a few seconds. The deploy script now requires a voting delay of at least one hour and a voting period of at least one day. TEST_DEPLOY admits the shorter drill windows, which the deploy test now runs.
The canceller check in the governance deploy refused every non-Safe with the same message, including a Safe with threshold 0 and an EIP-7702 delegated EOA, where getThreshold() had answered. It now names the reason: no code on this chain, a delegated EOA, getThreshold() failing or answering anything but one word, or a threshold of 0. The deploy test covers each refusal, including short and long getThreshold() answers.
…igners A 1-of-n canceller Safe is a single key holding a veto over every queued proposal. The governance deploy now refuses a canceller whose Safe threshold is below 2 unless TEST_DEPLOY is set.
…deploy With QUORUM_FRACTION=0 the governor's quorum stays at the permanent floor however much PEN circulates. The governance deploy now refuses 0 unless TEST_DEPLOY is set, which the drills use with drill-scale voting power.
The scripts read their parameters from the process-wide environment and forge runs test functions in parallel. Both scripts are about to read TEST_DEPLOY, so their cases now share one test function instead of two that could race on it.
The migration deploy handed vault admin to whatever ADMIN_SAFE named. It now refuses an address without code on the chain and an EIP-7702 delegated EOA. TEST_DEPLOY, refused on Base mainnet as in the governance deploy, admits a plain key for testnet drills and local runs; the Anvil and Base Sepolia harnesses set it.
The migration deploy accepted any future EARLIEST_SWEEP_TS, so a value an hour or two ahead from a drill environment would have been fixed in the vault for good. It now requires the floor to lie at least 30 days after the deploy block unless TEST_DEPLOY is set; 2027-03-01 still passes for a deploy up to 2027-01-30.
The drill wrote its parameters to the run manifest with JSON.stringify, which throws on the BigInt quorum floor, so a run aborted after its last check and exited non-zero.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Both deploy scripts validate every parameter before broadcasting, so a misconfigured environment stops before anything is deployed.
Deploy.s.sol(migration)MAX_ISSUANCEmust match the fixed supply.EARLIEST_SWEEP_TSmust be given in seconds and, on Base mainnet, lie at least 30 days after the deployment.DeployGovernance.s.solPEN_TOKENmust be the vault's token (VAULT_ADDRESSis required).TIMELOCK_CANCELLERis required: a dedicated Safe with at least two signers, distinct from the guardian, the token and the vault. It receivesCANCELLER_ROLE.TEST_DEPLOY=truerelaxes the multisig and floor checks for testnet drills and is refused on Base mainnet.Testing
forge test: 45 tests, covering every refusal and the production paths on Base mainnet's chain id.