-
Notifications
You must be signed in to change notification settings - Fork 196
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(cli,world): add user defined salt in WorldFactory.deployWorld() #2219
Conversation
🦋 Changeset detectedLatest commit: c98bd03 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Just a couple comments.
packages/world/test/Factories.t.sol
Outdated
testWorldFactory(address(this), 0); | ||
} | ||
|
||
function testFuzzWorldDeploy(address account, uint _salt) public { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added fuzzing test for salt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/world/test/Factories.t.sol
Outdated
// Address we expect for World | ||
// unchecked for the fuzzing test | ||
bytes memory _salt1; | ||
unchecked { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added unchecked here so that the test doesn't revert on overflow/underflow during the fuzzing test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the overall intention here just to generate two different salts?
A more clear way to do this would be to have two salt parameters in the fuzz test, and discard them if the fuzzer generates two that are equal. You can do this with a Foundry assume at the start of the test:
function testWorldFactory(address account, uint256 salt1, uint256 salt2) public {
vm.assume(salt1 != salt2);
...
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved issues brought up in review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there, just remove worldCounts
and a couple nits 🙌
packages/world/test/Factories.t.sol
Outdated
testWorldFactory(address(this), 0); | ||
} | ||
|
||
function testFuzzWorldDeploy(address account, uint _salt) public { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/world/test/Factories.t.sol
Outdated
// Address we expect for World | ||
// unchecked for the fuzzing test | ||
bytes memory _salt1; | ||
unchecked { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the overall intention here just to generate two different salts?
A more clear way to do this would be to have two salt parameters in the fuzz test, and discard them if the fuzzer generates two that are equal. You can do this with a Foundry assume at the start of the test:
function testWorldFactory(address account, uint256 salt1, uint256 salt2) public {
vm.assume(salt1 != salt2);
...
)
Co-authored-by: yonada <[email protected]>
Removed |
packages/world/src/WorldFactory.sol
Outdated
* @return worldAddress The address of the newly deployed World contract. | ||
*/ | ||
function deployWorld() public returns (address worldAddress) { | ||
function deployWorld(bytes memory _salt) public returns (address worldAddress) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small API thing: because Solidity supports calling functions with named parameters now, it might make sense to call this salt
and internally we can call the combined one _salt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
@partylikeits1983 are you good to fix the last suggestion (and get CI to pass)? Otherwise I'm happy to get this over the finish line, but you'll need to enable commits on your branches so I can push to your fork: |
@holic @yonadaaa lmk if there is anything else to fix on this PR. All tests passed on this branch locally. |
Edits by maintainers are turned on for this branch. Is there something specific for repositories with GitHub actions that have secrets? |
@partylikeits1983 thanks for pointing that out, seems my This PR is almost done - I will take this over and get it over the finish line! |
packages/cli/src/runDeploy.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we sort of do in that our e2e tests lean on deploying a world with the mud cli (I think)
Lmk if there is anything else I should fix. |
@@ -58,7 +61,7 @@ export async function deploy<configInput extends ConfigInput>({ | |||
|
|||
const worldDeploy = existingWorldAddress | |||
? await getWorldDeploy(client, existingWorldAddress) | |||
: await deployWorld(client); | |||
: await deployWorld(client, salt ? salt : `0x${randomBytes(32).toString("hex")}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might want to check isHex
here (edit: need to check where this is called, not here)
@@ -89,6 +89,7 @@ const commandModule: CommandModule<typeof devOptions, InferredOptionTypes<typeof | |||
saveDeployment: true, | |||
worldAddress, | |||
srcDir, | |||
salt: undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be nice to do our own internally incrementing counter for this process here, so that restarting the dev process always results in the same contract address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, this might be harder than I initially thought it would be. Since we already pass the worldAddress
in to upgrade worlds, this should be fine.
Just a note that this means that our tests that generate data, snapshots, etc. will be non-deterministic for now (unless we update them to pass in a consistent salt)
This PR adds user-defined salt functionality to the
WorldFactory.deployWorld()
function.Resolves #2214
The modified
WorldFactory.deployWorld()
function allows the world creator to pass in an arbitrary salt value. This makes it easier for developers to have deterministic addresses across chains.The edited function still increments worldCounts when creating a new world, but the worldCount nonce is not used to create a unique salt.
The salt value still uses msg.sender as a parameter to generate a salt. If msg.sender calls deployWorld() a second time with the same bytes _salt value, the transaction will revert.
This PR also updates the Factories.t.sol test.
In the test, the calculated address matches the deployed address via Create2.
Additionally the test expects revert when attempting to deploy a second world with the same _salt value.
Please let me know if I need to edit the PR.