Skip to content

Commit 8b7bc43

Browse files
authored
Fix: Resolve module deployment determinism overlap (#779)
1 parent 2c05ca6 commit 8b7bc43

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

src/factories/ModuleFactory_v1.sol

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ contract ModuleFactory_v1 is
112112
/// @dev moduleProxy => {IOrchestrator_v1}.
113113
mapping(address => address) private _orchestratorOfProxy;
114114

115-
/// @dev Maps a users address to a nonce used for the create2-based deployment.
116-
mapping(address => uint) private _deploymentNonces;
115+
/// @dev Maps the hash of the callers address and the corresponding
116+
/// orchestrator address to a nonce used for the create2-based
117+
/// deployment.
118+
mapping(bytes32 => uint) private _deploymentNonces;
117119

118120
/// @dev Storage gap for future upgrades.
119121
uint[50] private __gap;
@@ -209,16 +211,19 @@ contract ModuleFactory_v1 is
209211
if (workflowConfig.independentUpdates) {
210212
// Use an InverterTransparentUpgradeableProxy as a proxy
211213
proxy = address(
212-
new InverterTransparentUpgradeableProxy_v1{salt: _createSalt()}(
213-
beacon, workflowConfig.independentUpdateAdmin, bytes("")
214-
)
214+
new InverterTransparentUpgradeableProxy_v1{
215+
salt: _createSalt(address(orchestrator))
216+
}(beacon, workflowConfig.independentUpdateAdmin, bytes(""))
215217
);
216218
}
217219
// If not then
218220
else {
219221
// Instead use the Beacon Structure Proxy
220-
proxy =
221-
address(new InverterBeaconProxy_v1{salt: _createSalt()}(beacon));
222+
proxy = address(
223+
new InverterBeaconProxy_v1{
224+
salt: _createSalt(address(orchestrator))
225+
}(beacon)
226+
);
222227
}
223228

224229
_orchestratorOfProxy[proxy] = address(orchestrator);
@@ -286,12 +291,15 @@ contract ModuleFactory_v1 is
286291
emit MetadataRegistered(metadata, beacon);
287292
}
288293

289-
/// @dev Internal function to generate a salt for the create2-based deployment flow.
290-
/// This salt is the hash of (msgSender, nonce), where the
291-
/// nonce is an increasing number for each user.
292-
function _createSalt() internal returns (bytes32) {
294+
/// @dev Internal function to generate a salt for the create2-based
295+
/// deployment flow. This salt is defined as
296+
/// `hash(hash(msgSender, orchestrator), nonce)`
297+
/// where the nonce is an increasing number for each orchestrator.
298+
function _createSalt(address orchestrator) internal returns (bytes32) {
299+
bytes32 callerHash =
300+
keccak256(abi.encodePacked(_msgSender(), orchestrator));
293301
return keccak256(
294-
abi.encodePacked(_msgSender(), _deploymentNonces[_msgSender()]++)
302+
abi.encodePacked(callerHash, _deploymentNonces[callerHash]++)
295303
);
296304
}
297305

0 commit comments

Comments
 (0)