Skip to content

Conversation

pakim249CAL
Copy link
Contributor

@pakim249CAL pakim249CAL commented Mar 19, 2025

Why are these changes needed?

Adds a script to get calldata that would be submitted to a multisig, and adds supporting refactors to minimize code duplication and vectors for misconfiguration. Also adds tests for what is testable on-chain, but there is still some verification that will need to be done offchain such as verifying the contracts on etherscan, making sure proxies have a clean history, etc.

The refactors mainly are:

  • cfg string is referenced and used instead of putting init vars in script storage
  • cfg library is made so that multiple scripts can read the same cfg

Checks

  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • I've checked the new test coverage and the coverage percentage didn't drop.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

@pakim249CAL pakim249CAL marked this pull request as ready for review March 19, 2025 19:55
@pakim249CAL pakim249CAL marked this pull request as draft March 20, 2025 01:23
@pakim249CAL pakim249CAL marked this pull request as ready for review March 20, 2025 23:04
@pakim249CAL pakim249CAL changed the title Verifiable Deployment Calldata script feat: Verifiable Deployment Calldata script Mar 20, 2025
@@ -47,11 +47,11 @@ jobs:
working-directory: ./contracts

- name: Run tests
run: forge test -vvv
run: forge test --no-match-path script/**/*.sol -vvv
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also capture this exclusion regex in the package.json's test command definition? also what's the rationale for not running the script tests as part of CI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test I wrote to test the deployment is meant to be ran after a deployment by a verifier (which may not be the deployer!), ingesting environment variables input by the verifier. This would obviously fail in CI without contracts already deployed. And yes, I guess it would need to be excluded in package.json too.

Maybe there is a better way to do this, but I think in general there should be no need to put tests that are in the script/ folder into CI. If we put tests there meant for CI, they should be in the test/ folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess by default, I could have the test run after running the deployment script using mock values. But then the test would not fail if the correct environment variables are not supplied, which seems like a way that the verifier might make a mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, maybe an even better solution is just to make the BeforeInitializaiton test be done in a script instead of a test. Then it won't be flagged as a test by forge test. I think I'll just do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to having it as a part of a script and not a test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CalldataInitParams memory params = CalldataInitParamsLib.getCalldataInitParams(cfg);
function _logs() internal virtual {
console2.log("Deployment addresses:");
console2.log("Deployment Initializer: ", address(deploymentInitializer));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - inconsistent formatting with other log stmts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

);
}

function _doTests() internal {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this not a redundant simulation with just running the script with --broadcast enabled?

Copy link
Contributor Author

@pakim249CAL pakim249CAL Mar 21, 2025

Choose a reason for hiding this comment

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

How so? I don't think I understand this question. Do you mean that this whole fn is redundant? Basically this function is put into the script to run the same tests that the verifier would run to verify the deployment. That way, the deployer has some assurance that the verifier can run the BeforeVerifiableDeploymentInitialization test on the latest block on the deployed chain and have it pass.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah I see that makes sense - any chance we could capture this role differentiation in a smol comment? At first glance the behavior is a bit hard to decipher

Copy link
Contributor Author

Choose a reason for hiding this comment

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

vm.startPrank(initialOwner);
CalldataInitParams memory params = CalldataInitParamsLib.getCalldataInitParams(cfg);
function _logs() internal virtual {
console2.log("Deployment addresses:");
Copy link
Contributor

Choose a reason for hiding this comment

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

just to learn - how does console2 differ from just regular console?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the foundry doc,

"console2.sol contains patches to console.sol that allow Forge to decode traces for calls to the console, but it is not compatible with Hardhat."

Copy link
Contributor

@ethenotethan ethenotethan left a comment

Choose a reason for hiding this comment

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

LGTM!

@pakim249CAL pakim249CAL merged commit 4338aba into master Mar 31, 2025
12 checks passed
@pakim249CAL pakim249CAL deleted the feat/verifiable-deploy-calldata branch March 31, 2025 20:28
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.

2 participants