From e22edfd572f33898da457dc9465f31c9987fa99b Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 07:20:04 +0000 Subject: [PATCH 01/17] Make deployStepData and deployedAddress virtual for per-network deploy data Co-Authored-By: Claude Opus 5.5 --- src/abstract/RainDeploySuitesBase.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/abstract/RainDeploySuitesBase.sol b/src/abstract/RainDeploySuitesBase.sol index 0753adb8..a4d18d11 100644 --- a/src/abstract/RainDeploySuitesBase.sol +++ b/src/abstract/RainDeploySuitesBase.sol @@ -463,6 +463,7 @@ abstract contract RainDeploySuitesBase { function deployedAddress(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) internal view + virtual returns (address) { return mechanismOf(d, suite).deployedAddress(d, suite, chainId); @@ -479,6 +480,7 @@ abstract contract RainDeploySuitesBase { function deployStepData(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) internal view + virtual returns (bytes memory) { return mechanismOf(d, suite).deployStepData(d, suite, chainId); From 72665573632827de54b6bec73f12f59dafc9baaa Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 07:27:01 +0000 Subject: [PATCH 02/17] Test per-network deploy step data overrides in one broadcast run Co-Authored-By: Claude Opus 5.5 --- test/concrete/MockBeaconBound.sol | 16 ++ test/concrete/PerNetworkBeaconDeploy.sol | 61 +++++ ...oyBroadcast.perNetworkDeployStepData.t.sol | 234 ++++++++++++++++++ 3 files changed, 311 insertions(+) create mode 100644 test/concrete/MockBeaconBound.sol create mode 100644 test/concrete/PerNetworkBeaconDeploy.sol create mode 100644 test/src/abstract/RainDeployBroadcast.perNetworkDeployStepData.t.sol diff --git a/test/concrete/MockBeaconBound.sol b/test/concrete/MockBeaconBound.sol new file mode 100644 index 00000000..bb431903 --- /dev/null +++ b/test/concrete/MockBeaconBound.sol @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +/// @title MockBeaconBound +/// @notice Holds the beacon its constructor is given in storage, so its runtime code is the same whichever beacon. +contract MockBeaconBound { + /// The beacon. + address public sBeacon; + + /// @param beacon The beacon. + //forge-lint: disable-next-line(missing-zero-check) + constructor(address beacon) { + sBeacon = beacon; + } +} diff --git a/test/concrete/PerNetworkBeaconDeploy.sol b/test/concrete/PerNetworkBeaconDeploy.sol new file mode 100644 index 00000000..fc75ca8a --- /dev/null +++ b/test/concrete/PerNetworkBeaconDeploy.sol @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +import {DeployDeclaration, DeploySuite} from "../../src/abstract/RainDeploySuitesBase.sol"; +import {LibMockCreate2Mechanism} from "../lib/LibMockCreate2Mechanism.sol"; +import {MockCreate2Deploy} from "./MockCreate2Deploy.sol"; + +/// @dev The key of the suite `PerNetworkBeaconDeploy` binds to each network's beacon. +string constant BEACON_BOUND_SUITE = "beacon-bound"; + +/// @title PerNetworkBeaconDeploy +/// @notice `MockCreate2Deploy` overriding `deployStepData` and `deployedAddress` so `BEACON_BOUND_SUITE` deploys its +/// creation code with the beacon set for each chain id appended, at that network's salt. +contract PerNetworkBeaconDeploy is MockCreate2Deploy { + mapping(uint256 => address) internal sBeacons; + + function setBeacon(uint256 chainId, address beacon) external { + sBeacons[chainId] = beacon; + } + + function isBeaconBound(DeploySuite memory suite) internal pure returns (bool) { + return keccak256(bytes(suite.suite)) == keccak256(bytes(BEACON_BOUND_SUITE)); + } + + function beaconBoundCreationCode(DeploySuite memory suite, uint256 chainId) internal view returns (bytes memory) { + return abi.encodePacked(suite.creationCode, abi.encode(sBeacons[chainId])); + } + + function deployStepData(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (bytes memory) + { + if (!isBeaconBound(suite)) { + return super.deployStepData(d, suite, chainId); + } + return abi.encode( + LibMockCreate2Mechanism.decode(suite).factory, + LibMockCreate2Mechanism.salt(suite, chainId), + beaconBoundCreationCode(suite, chainId) + ); + } + + function deployedAddress(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (address) + { + if (!isBeaconBound(suite)) { + return super.deployedAddress(d, suite, chainId); + } + return LibMockCreate2Mechanism.create2Address( + LibMockCreate2Mechanism.decode(suite).factory, + LibMockCreate2Mechanism.salt(suite, chainId), + beaconBoundCreationCode(suite, chainId) + ); + } +} diff --git a/test/src/abstract/RainDeployBroadcast.perNetworkDeployStepData.t.sol b/test/src/abstract/RainDeployBroadcast.perNetworkDeployStepData.t.sol new file mode 100644 index 00000000..802c7357 --- /dev/null +++ b/test/src/abstract/RainDeployBroadcast.perNetworkDeployStepData.t.sol @@ -0,0 +1,234 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +import {Test} from "forge-std-1.17.0/src/Test.sol"; +import {Vm} from "forge-std-1.17.0/src/Vm.sol"; +import {DeployDependency, DeploySuite} from "../../../src/abstract/RainDeploySuitesBase.sol"; +import {LibRainDeploy, NetworkDeploys} from "../../../src/lib/LibRainDeploy.sol"; +import {LibRainDeployZoltuMechanism} from "../../../src/lib/LibRainDeployZoltuMechanism.sol"; +import {MockNetworkDeploy} from "../../lib/LibMockNetworkRecord.sol"; +import { + LibMockCreate2Mechanism, + MOCK_CREATE2_FACTORY, + MOCK_CREATE2_SALT, + MockCreate2Mechanism +} from "../../lib/LibMockCreate2Mechanism.sol"; +import {ExampleDeploy} from "../../concrete/ExampleDeploy.sol"; +import {LocalForkVm} from "../../concrete/LocalForkVm.sol"; +import {MockBeaconBound} from "../../concrete/MockBeaconBound.sol"; +import {MockCreate2Deploy} from "../../concrete/MockCreate2Deploy.sol"; +import {MockCreate2Factory} from "../../concrete/MockCreate2Factory.sol"; +import {MockDeployable} from "../../concrete/MockDeployable.sol"; +import {BEACON_BOUND_SUITE, PerNetworkBeaconDeploy} from "../../concrete/PerNetworkBeaconDeploy.sol"; + +/// @title RainDeployBroadcastPerNetworkDeployStepDataTest +/// @notice A consumer overriding `deployStepData` and `deployedAddress` with each network's own data, broadcast to +/// Arbitrum One, Polygon and Base in one run; consumers that do not override. +contract RainDeployBroadcastPerNetworkDeployStepDataTest is Test { + event MockCreate2Verification(string[] networks, string suite, address[] deployed); + + PerNetworkBeaconDeploy internal sDeploy; + LocalForkVm internal sForkVm; + + function setUp() external { + sDeploy = new PerNetworkBeaconDeploy(); + sForkVm = new LocalForkVm(); + vm.etch(MOCK_CREATE2_FACTORY, type(MockCreate2Factory).runtimeCode); + uint256[] memory ids = chainIds(); + for (uint256 i = 0; i < ids.length; i++) { + sDeploy.setBeacon(ids[i], beacon(ids[i])); + } + } + + function chainIds() internal pure returns (uint256[] memory) { + uint256[] memory ids = new uint256[](3); + ids[0] = 42161; + ids[1] = 137; + ids[2] = 8453; + return ids; + } + + function networks() internal pure returns (string[] memory) { + string[] memory names = new string[](3); + names[0] = LibRainDeploy.ARBITRUM_ONE; + names[1] = LibRainDeploy.POLYGON; + names[2] = LibRainDeploy.BASE; + return names; + } + + function beacon(uint256 chainId) internal pure returns (address) { + return address(uint160(uint256(keccak256(abi.encode("beacon", chainId))))); + } + + function salt(uint256 chainId) internal pure returns (bytes32) { + return keccak256(abi.encode(MOCK_CREATE2_SALT, abi.encode(chainId))); + } + + function create2Address(bytes32 create2Salt, bytes memory creationCode) internal pure returns (address) { + return address( + uint160( + uint256( + keccak256(abi.encodePacked(bytes1(0xff), MOCK_CREATE2_FACTORY, create2Salt, keccak256(creationCode))) + ) + ) + ); + } + + function boundCreationCode(address bound) internal pure returns (bytes memory) { + return abi.encodePacked(type(MockBeaconBound).creationCode, abi.encode(bound)); + } + + /// Where `MockBeaconBound` bound to each network's beacon lands at that network's salt. + function boundAddresses() internal pure returns (address[] memory) { + uint256[] memory ids = chainIds(); + address[] memory addresses = new address[](ids.length); + for (uint256 i = 0; i < ids.length; i++) { + addresses[i] = create2Address(salt(ids[i]), boundCreationCode(beacon(ids[i]))); + } + return addresses; + } + + /// `BEACON_BOUND_SUITE` on every network of `chainIds()`, recording `recorded` there. + function beaconBoundSuite(address[] memory recorded) internal pure returns (DeploySuite memory) { + uint256[] memory ids = chainIds(); + MockNetworkDeploy[] memory recordedNetworks = new MockNetworkDeploy[](ids.length); + for (uint256 i = 0; i < ids.length; i++) { + recordedNetworks[i] = + MockNetworkDeploy({chainId: ids[i], data: abi.encode(ids[i]), deployedAddress: recorded[i]}); + } + return DeploySuite({ + suite: BEACON_BOUND_SUITE, + creationCode: type(MockBeaconBound).creationCode, + storedDeployedAddress: address(0), + storedBytecodeHash: keccak256(type(MockBeaconBound).runtimeCode), + storedRuntimeCode: type(MockBeaconBound).runtimeCode, + artifactPath: "test/concrete/MockBeaconBound.sol:MockBeaconBound", + dependencies: new DeployDependency[](0), + mechanismData: LibMockCreate2Mechanism.encode( + MockCreate2Mechanism({ + factory: MOCK_CREATE2_FACTORY, + salt: MOCK_CREATE2_SALT, + perNetwork: true, + networks: recordedNetworks, + root: "" + }) + ), + networks: LibMockCreate2Mechanism.networkNames(recordedNetworks), + describedByMeta: "" + }); + } + + function anyForkExists() internal returns (bool) { + (bool forked,) = address(vm).call(abi.encodeWithSignature("selectFork(uint256)", uint256(0))); + return forked; + } + + /// Each network's step data is the creation code bound to that network's beacon at its salt, derived and recorded + /// at that network's own address. + function testNetworkDeploysCarryEachNetworksOwnDataAndAddress() external view { + address[] memory expected = boundAddresses(); + NetworkDeploys memory deploys = sDeploy.externalNetworkDeploys(beaconBoundSuite(expected), networks()); + uint256[] memory ids = chainIds(); + assertEq(deploys.deployStepData.length, ids.length); + for (uint256 i = 0; i < ids.length; i++) { + assertEq( + deploys.deployStepData[i], + abi.encode(MOCK_CREATE2_FACTORY, salt(ids[i]), boundCreationCode(beacon(ids[i]))) + ); + assertEq(deploys.derivedAddresses[i], expected[i]); + assertEq(deploys.expectedAddresses[i], expected[i]); + } + } + + /// One run deploys each network's own data once, landing at that network's own address holding that network's + /// beacon. + function testOneRunDeploysEachNetworksOwnDataAtItsOwnAddress() external { + address[] memory expected = boundAddresses(); + DeploySuite memory suite = beaconBoundSuite(expected); + uint256[] memory ids = chainIds(); + for (uint256 i = 0; i < ids.length; i++) { + vm.expectCall( + MOCK_CREATE2_FACTORY, + abi.encodeCall(MockCreate2Factory.deploy, (salt(ids[i]), boundCreationCode(beacon(ids[i])))), + 1 + ); + } + vm.expectEmit(address(sDeploy)); + emit MockCreate2Verification(networks(), suite.suite, expected); + (address[] memory deployed,) = + sDeploy.externalDeployAndBroadcast(Vm(address(sForkVm)), networks(), 1, suite, suite); + assertEq(deployed.length, ids.length); + for (uint256 i = 0; i < ids.length; i++) { + assertEq(deployed[i], expected[i]); + assertEq(expected[i].code, type(MockBeaconBound).runtimeCode); + assertEq(MockBeaconBound(expected[i]).sBeacon(), beacon(ids[i])); + } + } + + /// A network whose data no longer derives its recorded address is refused naming both, before any fork. + /// @param index The network whose beacon moves. + /// @param moved The beacon it moves to. + function testRefusesANetworkWhoseDataDerivesOffItsRecordedAddress(uint256 index, address moved) external { + uint256[] memory ids = chainIds(); + index = bound(index, 0, ids.length - 1); + vm.assume(moved != beacon(ids[index])); + address[] memory recorded = boundAddresses(); + DeploySuite memory suite = beaconBoundSuite(recorded); + sDeploy.setBeacon(ids[index], moved); + vm.expectRevert( + abi.encodeWithSelector( + LibRainDeploy.UnexpectedDeployedAddress.selector, + recorded[index], + create2Address(salt(ids[index]), boundCreationCode(moved)) + ) + ); + sDeploy.externalDeployAndBroadcast(vm, networks(), 1, suite, suite); + assertFalse(anyForkExists()); + } + + /// A Zoltu consumer that overrides neither hook gets the creation code and its one Zoltu address on every network. + function testNonOverridingZoltuConsumerKeepsOneCreationCodeAndAddressEverywhere() external { + ExampleDeploy deploy = new ExampleDeploy(); + address zoltu = LibRainDeploy.zoltuAddress(type(MockDeployable).creationCode); + DeploySuite memory suite = DeploySuite({ + suite: "zoltu", + creationCode: type(MockDeployable).creationCode, + storedDeployedAddress: zoltu, + storedBytecodeHash: keccak256(type(MockDeployable).runtimeCode), + storedRuntimeCode: type(MockDeployable).runtimeCode, + artifactPath: "test/concrete/MockDeployable.sol:MockDeployable", + dependencies: new DeployDependency[](0), + mechanismData: LibRainDeployZoltuMechanism.mechanismData(), + networks: new string[](0), + describedByMeta: "" + }); + NetworkDeploys memory deploys = deploy.externalNetworkDeploys(suite, networks()); + assertEq(deploys.deployStepData.length, chainIds().length); + for (uint256 i = 0; i < deploys.deployStepData.length; i++) { + assertEq(deploys.deployStepData[i], type(MockDeployable).creationCode); + assertEq(deploys.derivedAddresses[i], zoltu); + assertEq(deploys.expectedAddresses[i], zoltu); + } + } + + /// A per-network consumer that overrides neither hook gets its mechanism's data and address on each network. + function testNonOverridingPerNetworkConsumerKeepsTheMechanismsDataOnEachNetwork() external { + MockCreate2Deploy deploy = new MockCreate2Deploy(); + string[] memory names = new string[](2); + names[0] = LibRainDeploy.ARBITRUM_ONE; + names[1] = LibRainDeploy.POLYGON; + uint256[2] memory ids = [uint256(42161), 137]; + NetworkDeploys memory deploys = deploy.externalNetworkDeploys(deploy.externalMockRelease(), names); + assertEq(deploys.deployStepData.length, ids.length); + for (uint256 i = 0; i < ids.length; i++) { + address expected = create2Address(salt(ids[i]), type(MockDeployable).creationCode); + assertEq( + deploys.deployStepData[i], + abi.encode(MOCK_CREATE2_FACTORY, salt(ids[i]), type(MockDeployable).creationCode) + ); + assertEq(deploys.derivedAddresses[i], expected); + assertEq(deploys.expectedAddresses[i], expected); + } + } +} From b9257ff622ae26df992386112f70ecb8456e8927 Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 07:29:28 +0000 Subject: [PATCH 03/17] Format per-network deploy step data test Co-Authored-By: Claude Opus 5.5 --- .../RainDeployBroadcast.perNetworkDeployStepData.t.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/src/abstract/RainDeployBroadcast.perNetworkDeployStepData.t.sol b/test/src/abstract/RainDeployBroadcast.perNetworkDeployStepData.t.sol index 802c7357..02f64deb 100644 --- a/test/src/abstract/RainDeployBroadcast.perNetworkDeployStepData.t.sol +++ b/test/src/abstract/RainDeployBroadcast.perNetworkDeployStepData.t.sol @@ -69,7 +69,9 @@ contract RainDeployBroadcastPerNetworkDeployStepDataTest is Test { return address( uint160( uint256( - keccak256(abi.encodePacked(bytes1(0xff), MOCK_CREATE2_FACTORY, create2Salt, keccak256(creationCode))) + keccak256( + abi.encodePacked(bytes1(0xff), MOCK_CREATE2_FACTORY, create2Salt, keccak256(creationCode)) + ) ) ) ); From 88b41a271d36903b4130d5e5402783c2d3d402ce Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 07:46:48 +0000 Subject: [PATCH 04/17] Refuse the deploy-key seat check when the deployed address has no code or owner() is unreadable Co-Authored-By: Claude Opus 5.5 --- src/abstract/RainDeployBroadcast.sol | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/abstract/RainDeployBroadcast.sol b/src/abstract/RainDeployBroadcast.sol index a2ae7f01..41c3b43f 100644 --- a/src/abstract/RainDeployBroadcast.sol +++ b/src/abstract/RainDeployBroadcast.sol @@ -24,6 +24,13 @@ import {DeploySuiteIndex, LibRainDeployDeclaration} from "../lib/LibRainDeployDe /// whose low 160 bits are the deploy key. error SuiteSeatsDeployKey(string suite, address deployed); +/// @notice The address a suite deploys to on a chain id MUST hold code after the local deploy, and an `owner()` that +/// succeeds there MUST return at least a word, so the seat check never passes on an address it cannot read. +/// @param suite The suite being broadcast. +/// @param deployed The address with no code, or whose `owner()` succeeded with less than a word. +/// @param chainId The chain id deployed under. +error SuiteOwnerUnreadable(string suite, address deployed, uint256 chainId); + /// @notice Every network a run deploys to MUST be one of the declaration's networks. /// @param network The entry of `d.deployNetworks` missing from `d.networks`. error DeployNetworkUndeclared(string network); @@ -327,11 +334,16 @@ abstract contract RainDeployBroadcast is RainDeploySuitesBase, Script { address deployed = deployedAddress(d, suite, chainIds[i]); // slither-disable-next-line low-level-calls (bool answered, bytes memory owner) = deployed.staticcall(abi.encodeCall(IERC5313.owner, ())); + bool hasCode = deployed.code.length > 0; // Restores the chain id with the state. if (!vm.revertToState(snapshotId)) { revert DerivationSnapshotRevertFailed(suite.suite, snapshotId); } - if (answered && owner.length >= 0x20 && address(uint160(abi.decode(owner, (uint256)))) == deployer) { + // A revert is a suite without `owner()`; an empty success is unreadable. + if (!hasCode || (answered && owner.length < 0x20)) { + revert SuiteOwnerUnreadable(suite.suite, deployed, chainIds[i]); + } + if (answered && address(uint160(abi.decode(owner, (uint256)))) == deployer) { revert SuiteSeatsDeployKey(suite.suite, deployed); } } From a41ab2196d813bcdca4853ea07bae3d1bee0956e Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 07:49:55 +0000 Subject: [PATCH 05/17] Seat check deploys each network's deploy step data through a local twin of the deploy step Co-Authored-By: Claude Opus 5.5 --- src/abstract/RainDeployBroadcast.sol | 6 ++--- src/abstract/RainDeploySuitesBase.sol | 33 +++++++++++++++++++++++++ src/lib/LibRainDeployDeclaration.sol | 1 + src/lib/LibRainDeployZoltuMechanism.sol | 15 +++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/abstract/RainDeployBroadcast.sol b/src/abstract/RainDeployBroadcast.sol index 41c3b43f..e5c22ed1 100644 --- a/src/abstract/RainDeployBroadcast.sol +++ b/src/abstract/RainDeployBroadcast.sol @@ -310,7 +310,8 @@ abstract contract RainDeployBroadcast is RainDeploySuitesBase, Script { return targets; } - /// Deploys `suite` locally with `deployer` as sender and origin, once under each of `chainIds`, and refuses + /// Deploys `deployStepData` for each of `chainIds` locally, under that chain id, through the local twin of the + /// suite's deploy step with `deployer` as sender and origin, and refuses /// `SuiteSeatsDeployKey` when the address deployed for that chain id answers `owner()` with a first word whose /// low 160 bits are `deployer`. The suite's constructor runs on the local EVM with its dependency closure /// etched, so it MUST succeed there under each chain id: one that reverts locally (say, by calling an undeclared @@ -329,9 +330,8 @@ abstract contract RainDeployBroadcast is RainDeploySuitesBase, Script { uint256 snapshotId = vm.snapshotState(); vm.chainId(chainIds[i]); vm.startPrank(deployer, deployer); - deployLocallyOnChain(d, index, vm, suite); + address deployed = deployStepDataLocally(d, index, vm, suite, chainIds[i], deployer); vm.stopPrank(); - address deployed = deployedAddress(d, suite, chainIds[i]); // slither-disable-next-line low-level-calls (bool answered, bytes memory owner) = deployed.staticcall(abi.encodeCall(IERC5313.owner, ())); bool hasCode = deployed.code.length > 0; diff --git a/src/abstract/RainDeploySuitesBase.sol b/src/abstract/RainDeploySuitesBase.sol index a4d18d11..12209257 100644 --- a/src/abstract/RainDeploySuitesBase.sol +++ b/src/abstract/RainDeploySuitesBase.sol @@ -146,6 +146,10 @@ error ZoltuDerivationMismatch(string suite, address formulaAddress, address fact /// @param suite The suite carrying the data. error UnexpectedMechanismData(string suite); +/// Thrown when the local twin of a suite's deploy step puts its per-network data somewhere other than +/// `deployedAddress` for that chain id. +error DeployStepAddressMismatch(string suite, uint256 chainId, address expected, address actual); + /// Thrown when a Zoltu release's frozen record declares `MECHANISM_DATA`. /// @param path The record file. error FrozenSnapshotMechanismDataUnexpected(string path); @@ -317,6 +321,9 @@ struct DeployMechanismHandler { function(DeployDeclaration memory, DeploySuite memory) internal view returns (function(Vm, string memory, address, bytes memory) internal returns (address)) deployStep; + function(DeployDeclaration memory, DeploySuite memory) + internal + view returns (function(Vm, address, bytes memory) internal returns (address)) deployStepLocally; function(DeployDeclaration memory, DeploySuiteIndex memory, Vm, DeploySuite memory) internal returns (address[] memory) deployLocally; function(DeployDeclaration memory, DeploySuiteIndex memory, Vm, DeploySuite memory) internal deployLocallyOnChain; @@ -501,6 +508,32 @@ abstract contract RainDeploySuitesBase { return mechanismOf(d, suite).deployLocally(d, index, vm, suite); } + /// Deploys `deployStepData(d, suite, chainId)` through the local twin of the suite's deploy step with its + /// dependency closure etched, refusing `DeployStepAddressMismatch` unless it lands at + /// `deployedAddress(d, suite, chainId)`. + /// @return The address deployed for `chainId`. + function deployStepDataLocally( + DeployDeclaration memory d, + DeploySuiteIndex memory index, + Vm vm, + DeploySuite memory suite, + uint256 chainId, + address deployer + ) internal returns (address) { + address expected = deployedAddress(d, suite, chainId); + address[] memory own = new address[](1); + own[0] = expected; + LibRainDeployDeclaration.etchDependencyClosure(d, index, vm, suite, own); + vm.etch(expected, hex""); + vm.resetNonce(expected); + address actual = + mechanismOf(d, suite).deployStepLocally(d, suite)(vm, deployer, deployStepData(d, suite, chainId)); + if (actual != expected) { + revert DeployStepAddressMismatch(suite.suite, chainId, expected, actual); + } + return actual; + } + function deployLocallyOnChain( DeployDeclaration memory d, DeploySuiteIndex memory index, diff --git a/src/lib/LibRainDeployDeclaration.sol b/src/lib/LibRainDeployDeclaration.sol index ae41bcfb..9b4782f4 100644 --- a/src/lib/LibRainDeployDeclaration.sol +++ b/src/lib/LibRainDeployDeclaration.sol @@ -151,6 +151,7 @@ library LibRainDeployDeclaration { h.recordedAddress, h.deployStepData, h.deployStep, + h.deployStepLocally, h.deployLocally, h.deployLocallyOnChain, h.addUnrecordedNetworks, diff --git a/src/lib/LibRainDeployZoltuMechanism.sol b/src/lib/LibRainDeployZoltuMechanism.sol index 033c0f43..12168987 100644 --- a/src/lib/LibRainDeployZoltuMechanism.sol +++ b/src/lib/LibRainDeployZoltuMechanism.sol @@ -35,6 +35,7 @@ library LibRainDeployZoltuMechanism { recordedAddress: recordedAddress, deployStepData: deployStepData, deployStep: deployStep, + deployStepLocally: deployStepLocally, deployLocally: deployLocally, deployLocallyOnChain: deployLocallyOnChain, addUnrecordedNetworks: addUnrecordedNetworks, @@ -111,6 +112,20 @@ library LibRainDeployZoltuMechanism { return LibRainDeploy.zoltuDeployStep; } + function deployStepLocally(DeployDeclaration memory, DeploySuite memory suite) + internal + pure + returns (function(Vm, address, bytes memory) internal returns (address)) + { + checkMechanismData(suite); + return zoltuDeployStepLocally; + } + + /// `LibRainDeploy.zoltuDeployStep` without the broadcast. A Zoltu address does not depend on the deployer. + function zoltuDeployStepLocally(Vm vm, address, bytes memory creationCode) internal returns (address) { + return LibRainDeploy.etchAndDeployZoltu(vm, creationCode); + } + /// Deploys through the etched Zoltu factory with its dependency closure etched, refusing /// `ZoltuDerivationMismatch` where the factory and `LibRainDeploy.zoltuAddress` disagree. /// @return Its one address, once per each of its `networks`. From b13cd1df05ad66fe08e2f70f6179f9569dcdcbb0 Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 12:33:06 +0000 Subject: [PATCH 06/17] Derive each suite's code per chain through its deploy step data Co-Authored-By: Claude Opus 5.5 --- src/abstract/RainDeployVerifyBase.sol | 77 +++++++++++++------ src/abstract/RainDeployVerifyChain.sol | 14 ++-- src/abstract/RainDeployVerifySnapshotBase.sol | 6 +- 3 files changed, 63 insertions(+), 34 deletions(-) diff --git a/src/abstract/RainDeployVerifyBase.sol b/src/abstract/RainDeployVerifyBase.sol index 8fcff011..a7ac91bc 100644 --- a/src/abstract/RainDeployVerifyBase.sol +++ b/src/abstract/RainDeployVerifyBase.sol @@ -18,52 +18,79 @@ import {DeploySuiteIndex, LibRainDeployDeclaration} from "../lib/LibRainDeployDe /// @param suite The suite derived. error NoDerivedDeployment(string suite); -/// What a suite derives, by itself, through its own mechanism. +/// Thrown when a check asks for a suite's derived code on a chain its derivation has no code for. +/// @param suite The suite derived. +/// @param chainId The chain asked for. +error NotDerivedOnChain(string suite, uint256 chainId); + +/// What a suite derives, by itself, through its own mechanism, on each of its `networks`. struct DerivedDeploy { /// The suite the derivation came from. string suite; + /// The chain id of each of the suite's `networks`, in order. + uint256[] chainIds; /// The address the suite's mechanism deploys it to on each of its `networks`, in order. `address(0)` where a /// per-network mechanism records nothing on that network. address[] deployedAddresses; - /// The code hash the mechanism leaves behind at those addresses. - bytes32 bytecodeHash; + /// The code hash that chain's deploy step data leaves at that address, in order. `bytes32(0)` where the address + /// is `address(0)`. + bytes32[] bytecodeHashes; } /// @title RainDeployVerifyBase /// @notice The derivation every deploy-verification group shares. abstract contract RainDeployVerifyBase is RainDeploySuitesBase, Test { - /// Derives where a suite's mechanism puts it and the code hash it leaves there, from the suite - /// alone. + /// Derives where a suite's mechanism puts it on each of its `networks` and the code hash that chain's deploy step + /// data leaves there, deployed under that chain id, from the suite alone. /// @param suite The suite to derive from. - /// @return The addresses and code hash the suite's mechanism produces. + /// @return The addresses and code hashes the suite's mechanism produces. function deriveDeployment(DeployDeclaration memory d, DeploySuiteIndex memory index, DeploySuite memory suite) internal returns (DerivedDeploy memory) { - uint256 snapshotId = vm.snapshotState(); - - address[] memory deployedAddresses = deployLocally(d, index, vm, suite); - // `address(0)` is a network with nothing recorded, and its code hash is not the suite's. - uint256 deployed = 0; - while (deployed < deployedAddresses.length && deployedAddresses[deployed] == address(0)) { - deployed++; + uint256[] memory chainIds = suiteChainIds(suite); + DerivedDeploy memory derived = DerivedDeploy({ + suite: suite.suite, + chainIds: chainIds, + deployedAddresses: new address[](chainIds.length), + bytecodeHashes: new bytes32[](chainIds.length) + }); + bool anyDerived = false; + for (uint256 i = 0; i < chainIds.length; i++) { + // `address(0)` is a network with nothing recorded, and has no code of the suite's. + if (deployedAddress(d, suite, chainIds[i]) == address(0)) { + continue; + } + uint256 snapshotId = vm.snapshotState(); + vm.chainId(chainIds[i]); + address deployed = deployStepDataLocally(d, index, vm, suite, chainIds[i], address(this)); + derived.deployedAddresses[i] = deployed; + derived.bytecodeHashes[i] = deployed.codehash; + anyDerived = true; + // A failed revert is unrecoverable, not a warning to silence. The etch + // and the nonce reset would survive into every later derivation, whose + // results would then look entirely plausible while describing state + // this call planted. + if (!vm.revertToState(snapshotId)) { + revert DerivationSnapshotRevertFailed(suite.suite, snapshotId); + } } - if (deployed == deployedAddresses.length) { + if (!anyDerived) { revert NoDerivedDeployment(suite.suite); } - DerivedDeploy memory derived = DerivedDeploy({ - suite: suite.suite, deployedAddresses: deployedAddresses, bytecodeHash: deployedAddresses[deployed].codehash - }); + return derived; + } - // A failed revert is unrecoverable, not a warning to silence. The etch - // and the nonce reset would survive into every later derivation, whose - // results would then look entirely plausible while describing state - // this call planted. - if (!vm.revertToState(snapshotId)) { - revert DerivationSnapshotRevertFailed(suite.suite, snapshotId); + /// @param derived A suite's derivation. + /// @param chainId The chain. + /// @return The code hash derived for the suite on `chainId`, refusing `NotDerivedOnChain` where there is none. + function derivedBytecodeHash(DerivedDeploy memory derived, uint256 chainId) internal pure returns (bytes32) { + for (uint256 i = 0; i < derived.chainIds.length; i++) { + if (derived.chainIds[i] == chainId && derived.deployedAddresses[i] != address(0)) { + return derived.bytecodeHashes[i]; + } } - - return derived; + revert NotDerivedOnChain(derived.suite, chainId); } /// Derives every suite once, before anything forks. Callers that compare diff --git a/src/abstract/RainDeployVerifyChain.sol b/src/abstract/RainDeployVerifyChain.sol index 3d5a33a9..1567c886 100644 --- a/src/abstract/RainDeployVerifyChain.sol +++ b/src/abstract/RainDeployVerifyChain.sol @@ -116,7 +116,7 @@ abstract contract RainDeployVerifyChain is RainDeployVerifyBase { console2.log("Not required on network:", derived[j].suite, networks[i].name); continue; } - checkSuiteOnNetwork(networks[i].name, suites[j], derived[j], addresses[i][j]); + checkSuiteOnNetwork(networks[i], suites[j], derived[j], addresses[i][j]); checkOnChain(d, suites[j], networks[i].name, networks[i].chainId, addresses[i][j]); checkDescribedByMetaEmitted(d, forkVm, networks[i], suites[j], addresses[i][j]); } @@ -184,19 +184,19 @@ abstract contract RainDeployVerifyChain is RainDeployVerifyBase { } /// The selected fork MUST hold `suite` at `deployedAddress` with its derived code and its declared dependencies. - /// @param network The network's name, for the refusal. + /// @param network The network. /// @param suite The suite. - /// @param derived The suite's derivation. + /// @param derived The suite's derivation, checked at its code hash on `network`'s chain id. /// @param deployedAddress The suite's address on the network. function checkSuiteOnNetwork( - string memory network, + SupportedNetwork memory network, DeploySuite memory suite, DerivedDeploy memory derived, address deployedAddress ) internal view { - console2.log("Checking suite on network:", derived.suite, network); - LibRainDeploy.checkDeclaredDependencies(network, suite.dependencies); - LibRainDeploy.checkDeployedCode(network, deployedAddress, derived.bytecodeHash); + console2.log("Checking suite on network:", derived.suite, network.name); + LibRainDeploy.checkDeclaredDependencies(network.name, suite.dependencies); + LibRainDeploy.checkDeployedCode(network.name, deployedAddress, derivedBytecodeHash(derived, network.chainId)); } /// Every RELEASED suite MUST be live, with the code its creation code produces and its declared diff --git a/src/abstract/RainDeployVerifySnapshotBase.sol b/src/abstract/RainDeployVerifySnapshotBase.sol index 2c73c319..b06b3e45 100644 --- a/src/abstract/RainDeployVerifySnapshotBase.sol +++ b/src/abstract/RainDeployVerifySnapshotBase.sol @@ -91,8 +91,10 @@ abstract contract RainDeployVerifySnapshotBase is RainDeployVerifyBase { } } - if (suite.storedBytecodeHash != derived.bytecodeHash) { - revert StoredCodeHashMismatch(suite.suite, suite.storedBytecodeHash, derived.bytecodeHash); + for (uint256 i = 0; i < derived.chainIds.length; i++) { + if (derived.deployedAddresses[i] != address(0) && suite.storedBytecodeHash != derived.bytecodeHashes[i]) { + revert StoredCodeHashMismatch(suite.suite, suite.storedBytecodeHash, derived.bytecodeHashes[i]); + } } bytes32 runtimeCodeHash = keccak256(suite.storedRuntimeCode); From e050d9f8b5d8cb33191d5a8befe3332214363247 Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 12:35:57 +0000 Subject: [PATCH 07/17] Compare each chain's code against that chain's expected code hash Co-Authored-By: Claude Opus 5.5 --- src/abstract/RainDeployBroadcast.sol | 2 +- src/abstract/RainDeployDeclarationChecks.sol | 24 +++++++++++++- src/abstract/RainDeploySuitesBase.sol | 33 +++++++++++++++++++ src/abstract/RainDeployVerifySnapshotBase.sol | 8 +++-- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/abstract/RainDeployBroadcast.sol b/src/abstract/RainDeployBroadcast.sol index e5c22ed1..fab1e42d 100644 --- a/src/abstract/RainDeployBroadcast.sol +++ b/src/abstract/RainDeployBroadcast.sol @@ -233,7 +233,7 @@ abstract contract RainDeployBroadcast is RainDeploySuitesBase, Script { step, deploys.deployStepData[i], deploys.expectedAddresses[i], - suite.storedBytecodeHash + checkedExpectedBytecodeHash(d, suite, configs[i].chainId) ); } return forkIds; diff --git a/src/abstract/RainDeployDeclarationChecks.sol b/src/abstract/RainDeployDeclarationChecks.sol index e3edd36d..e5758a80 100644 --- a/src/abstract/RainDeployDeclarationChecks.sol +++ b/src/abstract/RainDeployDeclarationChecks.sol @@ -284,7 +284,7 @@ abstract contract RainDeployDeclarationChecks is RainDeploySuitesBase, Test { (uint256[] memory suiteIndexes, uint256[] memory externalIndexes) = LibRainDeployDeclaration.resolveDependency(siblings, externals, suites[i].suite, dependency); for (uint256 k = 0; k < suiteIndexes.length; k++) { - checkCodeHash(suites[i].suite, dependency, declared, suites[suiteIndexes[k]].storedBytecodeHash); + checkSiblingCodeHash(d, suites[i].suite, dependency, declared, suites[suiteIndexes[k]]); } for (uint256 k = 0; k < externalIndexes.length; k++) { checkCodeHash(suites[i].suite, dependency, declared, externals[externalIndexes[k]].codeHash); @@ -293,6 +293,28 @@ abstract contract RainDeployDeclarationChecks is RainDeploySuitesBase, Test { } } + /// `declared` MUST be `sibling`'s expected code hash on every chain `sibling` is recorded at `dependency`. + /// @param d The declaration. + /// @param suite The suite declaring the dependency. + /// @param dependency The dependency. + /// @param declared The hash of the runtime code declared at it. + /// @param sibling The suite recorded at it. + function checkSiblingCodeHash( + DeployDeclaration memory d, + string memory suite, + address dependency, + bytes32 declared, + DeploySuite memory sibling + ) internal view { + uint256[] memory chainIds = suiteChainIds(sibling); + (bool[] memory recorded, address[] memory addresses) = recordedAddresses(d, sibling); + for (uint256 j = 0; j < chainIds.length; j++) { + if (recorded[j] && addresses[j] == dependency) { + checkCodeHash(suite, dependency, declared, checkedExpectedBytecodeHash(d, sibling, chainIds[j])); + } + } + } + /// @param suite The suite declaring the dependency. /// @param dependency The dependency. /// @param declared The hash of the runtime code declared at it. diff --git a/src/abstract/RainDeploySuitesBase.sol b/src/abstract/RainDeploySuitesBase.sol index 12209257..9de212f0 100644 --- a/src/abstract/RainDeploySuitesBase.sol +++ b/src/abstract/RainDeploySuitesBase.sol @@ -178,6 +178,10 @@ error DependencyCycle(string suite); /// @param chainId A chain its mechanism records no address for it on. error UnrecordedOnNetwork(string suite, uint256 chainId); +/// @param suite The suite. +/// @param chainId A chain it has no expected code hash on. +error NoExpectedBytecodeHash(string suite, uint256 chainId); + /// One deployable unit. struct DeploySuite { /// The key. Unique across every suite a repo declares, and held to the key @@ -484,6 +488,35 @@ abstract contract RainDeploySuitesBase { return LibRainDeployDeclaration.recordedAddress(d, suite, chainId); } + /// The code hash `suite` must have on a chain; override for a suite whose code differs per chain. + /// @param suite The suite. + /// @return The expected code hash, zero when it has none. + function expectedBytecodeHash(DeployDeclaration memory, DeploySuite memory suite, uint256) + internal + view + virtual + returns (bytes32) + { + return suite.storedBytecodeHash; + } + + /// `expectedBytecodeHash`, refusing a chain without one. + /// @param d The declaration. + /// @param suite The suite. + /// @param chainId The chain id. + /// @return The expected code hash. + function checkedExpectedBytecodeHash(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + returns (bytes32) + { + bytes32 expected = expectedBytecodeHash(d, suite, chainId); + if (expected == bytes32(0)) { + revert NoExpectedBytecodeHash(suite.suite, chainId); + } + return expected; + } + function deployStepData(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) internal view diff --git a/src/abstract/RainDeployVerifySnapshotBase.sol b/src/abstract/RainDeployVerifySnapshotBase.sol index b06b3e45..71105c3a 100644 --- a/src/abstract/RainDeployVerifySnapshotBase.sol +++ b/src/abstract/RainDeployVerifySnapshotBase.sol @@ -92,8 +92,12 @@ abstract contract RainDeployVerifySnapshotBase is RainDeployVerifyBase { } for (uint256 i = 0; i < derived.chainIds.length; i++) { - if (derived.deployedAddresses[i] != address(0) && suite.storedBytecodeHash != derived.bytecodeHashes[i]) { - revert StoredCodeHashMismatch(suite.suite, suite.storedBytecodeHash, derived.bytecodeHashes[i]); + if (derived.deployedAddresses[i] == address(0)) { + continue; + } + bytes32 expected = checkedExpectedBytecodeHash(d, suite, derived.chainIds[i]); + if (expected != derived.bytecodeHashes[i]) { + revert StoredCodeHashMismatch(suite.suite, expected, derived.bytecodeHashes[i]); } } From 4bf63012641a230ae1047793f69d973e4303d65a Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 12:37:41 +0000 Subject: [PATCH 08/17] Give the mock mechanisms a local twin of their deploy step Co-Authored-By: Claude Opus 5.5 --- test/lib/LibMockCreate2Mechanism.sol | 17 +++++++++++++++++ test/lib/LibMockSaltMechanism.sol | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/test/lib/LibMockCreate2Mechanism.sol b/test/lib/LibMockCreate2Mechanism.sol index 3ffc6a8d..7ade8735 100644 --- a/test/lib/LibMockCreate2Mechanism.sol +++ b/test/lib/LibMockCreate2Mechanism.sol @@ -56,6 +56,7 @@ library LibMockCreate2Mechanism { recordedAddress: recordedAddress, deployStepData: deployStepData, deployStep: deployStep, + deployStepLocally: deployStepLocally, deployLocally: deployLocally, deployLocallyOnChain: deployLocallyOnChain, addUnrecordedNetworks: addUnrecordedNetworks, @@ -173,6 +174,14 @@ library LibMockCreate2Mechanism { return deployed; } + /// `create2DeployStep` without the broadcast, the factory etched. A CREATE2 address does not depend on the + /// deployer. + function create2DeployStepLocally(Vm vm, address, bytes memory data) internal returns (address) { + (address factory, bytes32 stepSalt, bytes memory creationCode) = abi.decode(data, (address, bytes32, bytes)); + vm.etch(factory, type(MockCreate2Factory).runtimeCode); + return MockCreate2Factory(factory).deploy(stepSalt, creationCode); + } + function deployAt(Vm vm, DeploySuite memory suite, bytes32 atSalt, address derived) internal { vm.etch(derived, hex""); vm.resetNonce(derived); @@ -231,6 +240,14 @@ library LibMockCreate2Mechanism { return create2DeployStep; } + function deployStepLocally(DeployDeclaration memory, DeploySuite memory) + internal + pure + returns (function(Vm, address, bytes memory) internal returns (address)) + { + return create2DeployStepLocally; + } + /// @return One address per each of its `networks`; a single-address suite is deployed once. A per-network suite /// returns `address(0)` for, and deploys nothing on, a network its payload records nothing on. function deployLocally(DeployDeclaration memory d, DeploySuiteIndex memory index, Vm vm, DeploySuite memory suite) diff --git a/test/lib/LibMockSaltMechanism.sol b/test/lib/LibMockSaltMechanism.sol index 754b0235..fae0db51 100644 --- a/test/lib/LibMockSaltMechanism.sol +++ b/test/lib/LibMockSaltMechanism.sol @@ -32,6 +32,7 @@ library LibMockSaltMechanism { recordedAddress: recordedAddress, deployStepData: deployStepData, deployStep: deployStep, + deployStepLocally: deployStepLocally, deployLocally: deployLocally, deployLocallyOnChain: deployLocallyOnChain, addUnrecordedNetworks: addUnrecordedNetworks, @@ -98,6 +99,14 @@ library LibMockSaltMechanism { return LibMockCreate2Mechanism.create2DeployStep; } + function deployStepLocally(DeployDeclaration memory, DeploySuite memory) + internal + pure + returns (function(Vm, address, bytes memory) internal returns (address)) + { + return LibMockCreate2Mechanism.create2DeployStepLocally; + } + /// @return Its one address, once per each of its `networks`. function deployLocally(DeployDeclaration memory d, DeploySuiteIndex memory index, Vm vm, DeploySuite memory suite) internal From 64c4c8a602816cca89264fa7b6e30f8c97f3c0ea Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 12:38:54 +0000 Subject: [PATCH 09/17] Check each chain's derived code hash where tests read the derivation Co-Authored-By: Claude Opus 5.5 --- ...inDeployVerifyBase.dependencyClosure.t.sol | 6 ++- .../RainDeployVerifyBase.mockMechanism.t.sol | 48 +++++++++++++++++-- test/src/abstract/RainDeployVerifyBase.t.sol | 27 +++++++---- 3 files changed, 69 insertions(+), 12 deletions(-) diff --git a/test/src/abstract/RainDeployVerifyBase.dependencyClosure.t.sol b/test/src/abstract/RainDeployVerifyBase.dependencyClosure.t.sol index 105d4bc4..76e329ab 100644 --- a/test/src/abstract/RainDeployVerifyBase.dependencyClosure.t.sol +++ b/test/src/abstract/RainDeployVerifyBase.dependencyClosure.t.sol @@ -21,7 +21,11 @@ contract RainDeployVerifyBaseDependencyClosureTest is TransitiveDependencyDeploy assertEq(derived.suite, "dependent"); assertEq(derived.deployedAddresses.length, suite.networks.length); assertEq(derived.deployedAddresses[0], suite.storedDeployedAddress); - assertEq(derived.bytecodeHash, keccak256(type(MockDependencyReaderCaller).runtimeCode)); + for (uint256 i = 0; i < derived.chainIds.length; i++) { + assertEq( + derivedBytecodeHash(derived, derived.chainIds[i]), keccak256(type(MockDependencyReaderCaller).runtimeCode) + ); + } assertEq(sibling.code.length, 0); assertEq(READ_DEPENDENCY.code.length, 0); } diff --git a/test/src/abstract/RainDeployVerifyBase.mockMechanism.t.sol b/test/src/abstract/RainDeployVerifyBase.mockMechanism.t.sol index 336e5dbf..981f60e2 100644 --- a/test/src/abstract/RainDeployVerifyBase.mockMechanism.t.sol +++ b/test/src/abstract/RainDeployVerifyBase.mockMechanism.t.sol @@ -2,7 +2,12 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {DerivedDeploy, NoDerivedDeployment, RainDeployVerifyBase} from "../../../src/abstract/RainDeployVerifyBase.sol"; +import { + DerivedDeploy, + NoDerivedDeployment, + NotDerivedOnChain, + RainDeployVerifyBase +} from "../../../src/abstract/RainDeployVerifyBase.sol"; import {DeployDeclaration, DeploySuite} from "../../../src/abstract/RainDeploySuitesBase.sol"; import {LibRainDeploy} from "../../../src/lib/LibRainDeploy.sol"; import {LibRainDeployDeclaration} from "../../../src/lib/LibRainDeployDeclaration.sol"; @@ -48,7 +53,9 @@ contract RainDeployVerifyBaseMockMechanismTest is MockCreate2DeploySuites, RainD assertEq(derived.deployedAddresses[0], address(0)); assertEq(derived.deployedAddresses[1], mockNetwork(42161).deployedAddress); assertEq(derived.deployedAddresses[2], mockNetwork(137).deployedAddress); - assertEq(derived.bytecodeHash, keccak256(type(MockDeployable).runtimeCode)); + assertEq(derived.bytecodeHashes[0], bytes32(0)); + assertEq(derivedBytecodeHash(derived, 42161), keccak256(type(MockDeployable).runtimeCode)); + assertEq(derivedBytecodeHash(derived, 137), keccak256(type(MockDeployable).runtimeCode)); } /// An unrecorded network between recorded ones changes nothing about the hash. @@ -63,7 +70,9 @@ contract RainDeployVerifyBaseMockMechanismTest is MockCreate2DeploySuites, RainD assertEq(derived.deployedAddresses[0], mockNetwork(42161).deployedAddress); assertEq(derived.deployedAddresses[1], address(0)); assertEq(derived.deployedAddresses[2], mockNetwork(137).deployedAddress); - assertEq(derived.bytecodeHash, keccak256(type(MockDeployable).runtimeCode)); + assertEq(derived.bytecodeHashes[1], bytes32(0)); + assertEq(derivedBytecodeHash(derived, 42161), keccak256(type(MockDeployable).runtimeCode)); + assertEq(derivedBytecodeHash(derived, 137), keccak256(type(MockDeployable).runtimeCode)); } /// Every network unrecorded leaves no code to hash, and the derivation refuses rather than hashing `address(0)`. @@ -84,4 +93,37 @@ contract RainDeployVerifyBaseMockMechanismTest is MockCreate2DeploySuites, RainD vm.expectRevert(abi.encodeWithSelector(NoDerivedDeployment.selector, release.suite)); this.externalDeriveDeployment(release); } + + function externalDerivedBytecodeHash(DerivedDeploy memory derived, uint256 chainId) + external + pure + returns (bytes32) + { + return derivedBytecodeHash(derived, chainId); + } + + /// A network the suite records nothing on has no derived code, and asking for it refuses rather than answering + /// the zero hash in its slot. + function testDerivedHashRefusesAnUnrecordedNetwork() external { + string[] memory networks = new string[](3); + networks[0] = LibRainDeploy.ARBITRUM_ONE; + networks[1] = LibRainDeploy.BASE; + networks[2] = LibRainDeploy.POLYGON; + DeploySuite memory release = releaseOn(networks); + DerivedDeploy memory derived = this.externalDeriveDeployment(release); + + vm.expectRevert(abi.encodeWithSelector(NotDerivedOnChain.selector, release.suite, uint256(8453))); + this.externalDerivedBytecodeHash(derived, 8453); + } + + /// A chain outside the suite's networks has no derived code either. + /// @param chainId A chain id that is neither of the release's. + function testDerivedHashRefusesAChainOffTheSuitesNetworks(uint256 chainId) external { + vm.assume(chainId != 42161 && chainId != 137); + DeploySuite memory release = mockRelease(); + DerivedDeploy memory derived = this.externalDeriveDeployment(release); + + vm.expectRevert(abi.encodeWithSelector(NotDerivedOnChain.selector, release.suite, chainId)); + this.externalDerivedBytecodeHash(derived, chainId); + } } diff --git a/test/src/abstract/RainDeployVerifyBase.t.sol b/test/src/abstract/RainDeployVerifyBase.t.sol index a95fcc44..f1748f50 100644 --- a/test/src/abstract/RainDeployVerifyBase.t.sol +++ b/test/src/abstract/RainDeployVerifyBase.t.sol @@ -70,16 +70,17 @@ contract RainDeployVerifyBaseTest is ExampleDeploySuites, RainDeployVerifyBase { assertEq(derived.suite, "a-declared-key"); assertEq(derived.deployedAddresses.length, suite.networks.length); + assertEq(derived.bytecodeHashes.length, suite.networks.length); for (uint256 i = 0; i < derived.deployedAddresses.length; i++) { assertEq(derived.deployedAddresses[i], CONFIG_REGISTRY_DEPLOYED_ADDRESS); + assertEq(derived.bytecodeHashes[i], keccak256(CONFIG_REGISTRY_RUNTIME_CODE)); } - assertEq(derived.bytecodeHash, keccak256(CONFIG_REGISTRY_RUNTIME_CODE)); // The recorded fields really were something else, so agreeing with the // creation code is a different answer from echoing them back. assertNotEq(derived.deployedAddresses[0], suite.storedDeployedAddress); - assertNotEq(derived.bytecodeHash, suite.storedBytecodeHash); - assertNotEq(derived.bytecodeHash, keccak256(suite.storedRuntimeCode)); + assertNotEq(derived.bytecodeHashes[0], suite.storedBytecodeHash); + assertNotEq(derived.bytecodeHashes[0], keccak256(suite.storedRuntimeCode)); } /// EVERY suite MUST be derived, once each, into the position it was handed @@ -101,14 +102,16 @@ contract RainDeployVerifyBaseTest is ExampleDeploySuites, RainDeployVerifyBase { for (uint256 i = 0; i < suites.length; i++) { assertEq(derived[i].suite, suites[i].suite); assertEq(derived[i].deployedAddresses[0], suites[i].storedDeployedAddress); - assertEq(derived[i].bytecodeHash, suites[i].storedBytecodeHash); + for (uint256 j = 0; j < derived[i].chainIds.length; j++) { + assertEq(derivedBytecodeHash(derived[i], derived[i].chainIds[j]), suites[i].storedBytecodeHash); + } } // Positional is a claim only while the positions differ. The first two // suites are different contracts at different addresses, and the last // is neither of them. assertNotEq(derived[0].deployedAddresses[0], derived[1].deployedAddresses[0]); - assertNotEq(derived[0].bytecodeHash, derived[1].bytecodeHash); + assertNotEq(derived[0].bytecodeHashes[0], derived[1].bytecodeHashes[0]); assertNotEq(derived[3].suite, derived[0].suite); } @@ -180,6 +183,14 @@ contract RainDeployVerifyBaseTest is ExampleDeploySuites, RainDeployVerifyBase { return addresses; } + /// Every chain `derived` covers MUST derive `expected`. + function assertEveryChainDerives(DerivedDeploy memory derived, bytes32 expected) internal pure { + assertGt(derived.chainIds.length, 0); + for (uint256 i = 0; i < derived.chainIds.length; i++) { + assertEq(derivedBytecodeHash(derived, derived.chainIds[i]), expected); + } + } + /// External wrapper, so a derivation that cannot run its constructor is a /// failed CALL rather than a reverted test. /// @param suite The suite to derive. @@ -204,7 +215,7 @@ contract RainDeployVerifyBaseTest is ExampleDeploySuites, RainDeployVerifyBase { ); assertEq(derived.deployedAddresses[0], LibRainDeploy.zoltuAddress(creationCode)); - assertEq(derived.bytecodeHash, keccak256(type(MockDependentDeployable).runtimeCode)); + assertEveryChainDerives(derived, keccak256(type(MockDependentDeployable).runtimeCode)); assertEq(FIRST_DEPENDENCY.code.length, 0, "the dependency etch survived the derivation"); assertEq(derived.deployedAddresses[0].code.length, 0, "the local deploy survived the derivation"); @@ -233,7 +244,7 @@ contract RainDeployVerifyBaseTest is ExampleDeploySuites, RainDeployVerifyBase { ); assertEq(derived.deployedAddresses[0], LibRainDeploy.zoltuAddress(creationCode)); - assertEq(derived.bytecodeHash, keccak256(type(MockDependentDeployable).runtimeCode)); + assertEveryChainDerives(derived, keccak256(type(MockDependentDeployable).runtimeCode)); assertEq(FIRST_DEPENDENCY.code.length, 0, "the first dependency etch survived the derivation"); assertEq(SECOND_DEPENDENCY.code.length, 0, "the second dependency etch survived the derivation"); @@ -289,7 +300,7 @@ contract RainDeployVerifyBaseTest is ExampleDeploySuites, RainDeployVerifyBase { deriveDeployment(d, LibRainDeployDeclaration.emptyIndex(), dependentSuite(creationCode, dependencies)); assertEq(derived.deployedAddresses[0], LibRainDeploy.zoltuAddress(creationCode)); - assertEq(derived.bytecodeHash, keccak256(type(MockDependentDeployable).runtimeCode)); + assertEveryChainDerives(derived, keccak256(type(MockDependentDeployable).runtimeCode)); } /// A dependency declared with NO code is etched as no code, so a suite that From 5124971f33e5fe539ce8b234525ae00f8b4a0dd9 Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 12:47:45 +0000 Subject: [PATCH 10/17] Per-chain code test harness and snapshot-base tests (WIP, needs src compile) Co-Authored-By: Claude Opus 5.5 --- test/abstract/PerChainCodeDeploySuites.sol | 151 ++++++++++++ test/concrete/MockImmutableBeaconBound.sol | 16 ++ ...eployVerifySnapshotBase.perChainCode.t.sol | 223 ++++++++++++++++++ 3 files changed, 390 insertions(+) create mode 100644 test/abstract/PerChainCodeDeploySuites.sol create mode 100644 test/concrete/MockImmutableBeaconBound.sol create mode 100644 test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol diff --git a/test/abstract/PerChainCodeDeploySuites.sol b/test/abstract/PerChainCodeDeploySuites.sol new file mode 100644 index 00000000..69195979 --- /dev/null +++ b/test/abstract/PerChainCodeDeploySuites.sol @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity ^0.8.25; + +import {StdConstants} from "forge-std-1.17.0/src/StdConstants.sol"; +import {DeployDependency, DeploySuite} from "../../src/abstract/RainDeploySuitesBase.sol"; +import {LibRainDeploy} from "../../src/lib/LibRainDeploy.sol"; +import {MockNetworkDeploy} from "../lib/LibMockNetworkRecord.sol"; +import { + LibMockCreate2Mechanism, + MOCK_CREATE2_FACTORY, + MOCK_CREATE2_SALT, + MockCreate2Mechanism +} from "../lib/LibMockCreate2Mechanism.sol"; +import {MockImmutableBeaconBound} from "../concrete/MockImmutableBeaconBound.sol"; +import {MockCreate2DeploySuites} from "./MockCreate2DeploySuites.sol"; + +/// @dev The key of the suite whose deploy step data and runtime code differ per chain. +string constant PER_CHAIN_CODE_SUITE = "per-chain-code"; + +/// @title PerChainCodeDeploySuites +/// @notice `PER_CHAIN_CODE_SUITE`: `MockImmutableBeaconBound` bound to each chain's beacon, at that chain's mock salt, +/// with each chain's expected code hash set from outside. A harness overrides `deployStepData`, `deployedAddress` and +/// `expectedBytecodeHash` with the `perChain*` functions for that suite. +abstract contract PerChainCodeDeploySuites is MockCreate2DeploySuites { + mapping(uint256 => address) internal sBeacons; + mapping(uint256 => bytes32) internal sExpectedBytecodeHashes; + /// Nonzero where `deployedAddress` answers other than where the chain's data lands. + mapping(uint256 => address) internal sMisdeclaredAddresses; + /// Where `deployedAddress` answers `address(0)`. + mapping(uint256 => bool) internal sUndeployed; + + function setBeacon(uint256 chainId, address beacon) external { + sBeacons[chainId] = beacon; + } + + function setExpectedBytecodeHash(uint256 chainId, bytes32 expected) external { + sExpectedBytecodeHashes[chainId] = expected; + } + + function setMisdeclaredAddress(uint256 chainId, address misdeclared) external { + sMisdeclaredAddresses[chainId] = misdeclared; + } + + function setUndeployed(uint256 chainId) external { + sUndeployed[chainId] = true; + } + + function perChainBeacon(uint256 chainId) internal pure returns (address) { + return address(uint160(uint256(keccak256(abi.encode("rain.deploy.per-chain-code.beacon", chainId))))); + } + + /// Binds each of `perChainCodeChainIds()` to its own beacon, expecting the code `MockImmutableBeaconBound` has + /// when `new` deploys it with that beacon. + function bindPerChainCode() external { + uint256[] memory chainIds = perChainCodeChainIds(); + for (uint256 i = 0; i < chainIds.length; i++) { + address beacon = perChainBeacon(chainIds[i]); + sBeacons[chainIds[i]] = beacon; + sExpectedBytecodeHashes[chainIds[i]] = address(new MockImmutableBeaconBound(beacon)).codehash; + } + } + + function isPerChainCode(DeploySuite memory suite) internal pure returns (bool) { + return keccak256(bytes(suite.suite)) == keccak256(bytes(PER_CHAIN_CODE_SUITE)); + } + + function perChainCreationCode(uint256 chainId) internal view returns (bytes memory) { + return abi.encodePacked(type(MockImmutableBeaconBound).creationCode, abi.encode(sBeacons[chainId])); + } + + function perChainDeployStepData(DeploySuite memory suite, uint256 chainId) internal view returns (bytes memory) { + return abi.encode(MOCK_CREATE2_FACTORY, LibMockCreate2Mechanism.salt(suite, chainId), perChainCreationCode(chainId)); + } + + function perChainLandingAddress(DeploySuite memory suite, uint256 chainId) internal view returns (address) { + return LibMockCreate2Mechanism.create2Address( + MOCK_CREATE2_FACTORY, LibMockCreate2Mechanism.salt(suite, chainId), perChainCreationCode(chainId) + ); + } + + function perChainDeployedAddress(DeploySuite memory suite, uint256 chainId) internal view returns (address) { + if (sUndeployed[chainId]) { + return address(0); + } + address misdeclared = sMisdeclaredAddresses[chainId]; + return misdeclared == address(0) ? perChainLandingAddress(suite, chainId) : misdeclared; + } + + function perChainExpectedBytecodeHash(uint256 chainId) internal view returns (bytes32) { + return sExpectedBytecodeHashes[chainId]; + } + + /// `PER_CHAIN_CODE_SUITE` on each of `chainIds`, recording where each chain's data lands. Its stored code is the + /// artifact's, with a zero beacon no chain's data deploys. + function perChainCodeSuite(uint256[] memory chainIds) internal view returns (DeploySuite memory) { + string memory artifactPath = "test/concrete/MockImmutableBeaconBound.sol:MockImmutableBeaconBound"; + bytes memory storedRuntimeCode = StdConstants.VM.getDeployedCode(artifactPath); + MockNetworkDeploy[] memory networks = new MockNetworkDeploy[](chainIds.length); + for (uint256 i = 0; i < chainIds.length; i++) { + bytes memory data = abi.encode(chainIds[i]); + networks[i] = MockNetworkDeploy({ + chainId: chainIds[i], + data: data, + deployedAddress: LibMockCreate2Mechanism.create2Address( + MOCK_CREATE2_FACTORY, + LibMockCreate2Mechanism.networkSalt(MOCK_CREATE2_SALT, data), + perChainCreationCode(chainIds[i]) + ) + }); + } + return DeploySuite({ + networks: LibMockCreate2Mechanism.networkNames(networks), + suite: PER_CHAIN_CODE_SUITE, + creationCode: type(MockImmutableBeaconBound).creationCode, + storedDeployedAddress: address(0), + storedBytecodeHash: keccak256(storedRuntimeCode), + storedRuntimeCode: storedRuntimeCode, + artifactPath: artifactPath, + dependencies: new DeployDependency[](0), + mechanismData: LibMockCreate2Mechanism.encode( + MockCreate2Mechanism({ + factory: MOCK_CREATE2_FACTORY, + salt: MOCK_CREATE2_SALT, + perNetwork: true, + networks: networks, + root: sMockRecordRoot + }) + ), + describedByMeta: "" + }); + } + + /// Arbitrum One, Polygon and Base. + function perChainCodeChainIds() internal pure returns (uint256[] memory) { + uint256[] memory chainIds = new uint256[](3); + chainIds[0] = 42161; + chainIds[1] = 137; + chainIds[2] = 8453; + return chainIds; + } + + /// The aliases of `perChainCodeChainIds()`, in order. + function perChainCodeNetworks() internal pure returns (string[] memory) { + string[] memory names = new string[](3); + names[0] = LibRainDeploy.ARBITRUM_ONE; + names[1] = LibRainDeploy.POLYGON; + names[2] = LibRainDeploy.BASE; + return names; + } +} diff --git a/test/concrete/MockImmutableBeaconBound.sol b/test/concrete/MockImmutableBeaconBound.sol new file mode 100644 index 00000000..627c3f68 --- /dev/null +++ b/test/concrete/MockImmutableBeaconBound.sol @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +/// @title MockImmutableBeaconBound +/// @notice Holds the beacon its constructor is given as an immutable, so its runtime code differs per beacon. +contract MockImmutableBeaconBound { + /// The beacon. + address public immutable iBeacon; + + /// @param beacon The beacon. + //forge-lint: disable-next-line(missing-zero-check) + constructor(address beacon) { + iBeacon = beacon; + } +} diff --git a/test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol b/test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol new file mode 100644 index 00000000..5a218cbd --- /dev/null +++ b/test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol @@ -0,0 +1,223 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +import { + DeployCandidate, + DeployDeclaration, + DeploySuite, + DeployStepAddressMismatch, + NoExpectedBytecodeHash +} from "../../../src/abstract/RainDeploySuitesBase.sol"; +import {DerivedDeploy, NoDerivedDeployment, NotDerivedOnChain} from "../../../src/abstract/RainDeployVerifyBase.sol"; +import { + RainDeployVerifySnapshotBase, + StoredCodeHashMismatch +} from "../../../src/abstract/RainDeployVerifySnapshotBase.sol"; +import {LibRainDeployDeclaration} from "../../../src/lib/LibRainDeployDeclaration.sol"; +import {LibMockCreate2Mechanism} from "../../lib/LibMockCreate2Mechanism.sol"; +import {MockImmutableBeaconBound} from "../../concrete/MockImmutableBeaconBound.sol"; +import {PerChainCodeDeploySuites} from "../../abstract/PerChainCodeDeploySuites.sol"; + +/// @title RainDeployVerifySnapshotBasePerChainCodeTest +/// @notice A suite whose deploy step data and runtime code differ per chain, derived and held to each chain's own +/// expected code hash. +contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuites, RainDeployVerifySnapshotBase { + function setUp() external { + this.bindPerChainCode(); + } + + function declaration() internal view override returns (DeployDeclaration memory) { + DeployDeclaration memory d; + LibRainDeployDeclaration.extend(d); + LibMockCreate2Mechanism.extend(d); + DeployCandidate[] memory candidates = new DeployCandidate[](1); + candidates[0] = DeployCandidate({snapshot: perChainCodeSuite(perChainCodeChainIds()), unanchorableReason: ""}); + LibRainDeployDeclaration.addCandidates(d, candidates); + return d; + } + + function deployStepData(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (bytes memory) + { + return isPerChainCode(suite) ? perChainDeployStepData(suite, chainId) : super.deployStepData(d, suite, chainId); + } + + function deployedAddress(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (address) + { + return isPerChainCode(suite) ? perChainDeployedAddress(suite, chainId) : super.deployedAddress(d, suite, chainId); + } + + function expectedBytecodeHash(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (bytes32) + { + return isPerChainCode(suite) + ? perChainExpectedBytecodeHash(chainId) + : super.expectedBytecodeHash(d, suite, chainId); + } + + function externalDeriveDeployment(DeploySuite memory suite) external returns (DerivedDeploy memory) { + return deriveDeployment(declaration(), LibRainDeployDeclaration.emptyIndex(), suite); + } + + function externalDerivedBytecodeHash(DerivedDeploy memory derived, uint256 chainId) + external + pure + returns (bytes32) + { + return derivedBytecodeHash(derived, chainId); + } + + function externalCheckInternallyConsistent(DeploySuite memory suite) external { + checkInternallyConsistent(declaration(), LibRainDeployDeclaration.emptyIndex(), suite); + } + + function externalExpectedBytecodeHash(DeploySuite memory suite, uint256 chainId) external view returns (bytes32) { + return expectedBytecodeHash(declaration(), suite, chainId); + } + + function suite() internal view returns (DeploySuite memory) { + return perChainCodeSuite(perChainCodeChainIds()); + } + + /// The code `new` leaves for `chainId`'s beacon. + function newCodeHash(uint256 chainId) internal returns (bytes32) { + return address(new MockImmutableBeaconBound(perChainBeacon(chainId))).codehash; + } + + /// Each chain derives at the address its own data lands at, with the code its own beacon gives, none of which is + /// the stored code or another chain's. + function testDerivesEachChainsOwnAddressAndCode() external { + uint256[] memory chainIds = perChainCodeChainIds(); + DerivedDeploy memory derived = this.externalDeriveDeployment(suite()); + + assertEq(derived.chainIds, chainIds); + assertEq(derived.deployedAddresses.length, chainIds.length); + assertEq(derived.bytecodeHashes.length, chainIds.length); + for (uint256 i = 0; i < chainIds.length; i++) { + bytes32 expected = newCodeHash(chainIds[i]); + assertEq( + derived.deployedAddresses[i], + LibMockCreate2Mechanism.create2Address( + LibMockCreate2Mechanism.decode(suite()).factory, + LibMockCreate2Mechanism.salt(suite(), chainIds[i]), + abi.encodePacked(type(MockImmutableBeaconBound).creationCode, abi.encode(perChainBeacon(chainIds[i]))) + ) + ); + assertEq(derived.bytecodeHashes[i], expected); + assertEq(this.externalDerivedBytecodeHash(derived, chainIds[i]), expected); + assertNotEq(expected, suite().storedBytecodeHash); + for (uint256 j = 0; j < i; j++) { + assertNotEq(derived.bytecodeHashes[i], derived.bytecodeHashes[j]); + assertNotEq(derived.deployedAddresses[i], derived.deployedAddresses[j]); + } + assertEq(derived.deployedAddresses[i].code.length, 0, "the local deploy survived the derivation"); + } + } + + /// Every chain held to its own expected code hash is consistent. + function testInternallyConsistentOnEveryChain() external { + this.externalCheckInternallyConsistent(suite()); + } + + /// The declaration's candidate passes the group's own test. + function testDeclaredPerChainCodeSuiteIsInternallyConsistent() external { + this.testSnapshotInternallyConsistent(); + } + + /// A chain expecting another chain's code is refused, naming its expectation and the code its own data derives. + /// @param a The chain whose code is expected. + /// @param b The chain expecting it. + function testRefusesAChainExpectingAnotherChainsCode(uint256 a, uint256 b) external { + uint256[] memory chainIds = perChainCodeChainIds(); + a = bound(a, 0, chainIds.length - 1); + b = bound(b, 0, chainIds.length - 1); + vm.assume(a != b); + bytes32 other = newCodeHash(chainIds[a]); + this.setExpectedBytecodeHash(chainIds[b], other); + + vm.expectRevert( + abi.encodeWithSelector(StoredCodeHashMismatch.selector, PER_CHAIN_CODE_SUITE, other, newCodeHash(chainIds[b])) + ); + this.externalCheckInternallyConsistent(suite()); + } + + /// A chain with no expected code hash is refused rather than compared against zero. + /// @param index The chain with none. + function testRefusesAChainWithNoExpectedCodeHash(uint256 index) external { + uint256[] memory chainIds = perChainCodeChainIds(); + index = bound(index, 0, chainIds.length - 1); + this.setExpectedBytecodeHash(chainIds[index], bytes32(0)); + + vm.expectRevert(abi.encodeWithSelector(NoExpectedBytecodeHash.selector, PER_CHAIN_CODE_SUITE, chainIds[index])); + this.externalCheckInternallyConsistent(suite()); + } + + /// A chain whose `deployedAddress` is not where its data lands is refused naming both. + /// @param index The misdeclared chain. + function testRefusesADeployedAddressTheChainsDataDoesNotLandAt(uint256 index) external { + uint256[] memory chainIds = perChainCodeChainIds(); + index = bound(index, 0, chainIds.length - 1); + address misdeclared = address(0xdead); + address landing = perChainLandingAddress(suite(), chainIds[index]); + this.setMisdeclaredAddress(chainIds[index], misdeclared); + + vm.expectRevert( + abi.encodeWithSelector( + DeployStepAddressMismatch.selector, PER_CHAIN_CODE_SUITE, chainIds[index], misdeclared, landing + ) + ); + this.externalDeriveDeployment(suite()); + } + + /// A chain the suite deploys nothing on derives no code, and asking for it refuses. + /// @param index The chain deploying nothing. + function testDerivedHashRefusesAChainDeployingNothing(uint256 index) external { + uint256[] memory chainIds = perChainCodeChainIds(); + index = bound(index, 0, chainIds.length - 1); + this.setUndeployed(chainIds[index]); + DerivedDeploy memory derived = this.externalDeriveDeployment(suite()); + + assertEq(derived.deployedAddresses[index], address(0)); + assertEq(derived.bytecodeHashes[index], bytes32(0)); + vm.expectRevert(abi.encodeWithSelector(NotDerivedOnChain.selector, PER_CHAIN_CODE_SUITE, chainIds[index])); + this.externalDerivedBytecodeHash(derived, chainIds[index]); + } + + /// A suite deploying nothing on any chain derives nothing. + function testRefusesASuiteDeployingNothingOnAnyChain() external { + uint256[] memory chainIds = perChainCodeChainIds(); + for (uint256 i = 0; i < chainIds.length; i++) { + this.setUndeployed(chainIds[i]); + } + + vm.expectRevert(abi.encodeWithSelector(NoDerivedDeployment.selector, PER_CHAIN_CODE_SUITE)); + this.externalDeriveDeployment(suite()); + } + + /// A suite that does not override expects its stored code hash on every chain. + /// @param chainId Any chain. + function testSingleHashSuiteExpectsItsStoredHashOnEveryChain(uint256 chainId) external view { + DeploySuite memory release = mockRelease(); + assertEq(this.externalExpectedBytecodeHash(release, chainId), release.storedBytecodeHash); + } + + /// A single-hash suite with no stored code hash is refused on its first chain. + function testRefusesASingleHashSuiteWithNoStoredHash() external { + DeploySuite memory release = mockRelease(); + release.storedBytecodeHash = bytes32(0); + + vm.expectRevert(abi.encodeWithSelector(NoExpectedBytecodeHash.selector, release.suite, uint256(42161))); + this.externalCheckInternallyConsistent(release); + } +} From f45f0fb3cfec7f504545c785337bd727d465d60e Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 12:49:40 +0000 Subject: [PATCH 11/17] Split deployStepDataLocally past stack too deep; derive only recorded networks Co-Authored-By: Claude Opus 5.5 --- src/abstract/RainDeploySuitesBase.sol | 31 +++++++++++++++++++++------ src/abstract/RainDeployVerifyBase.sol | 5 +++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/abstract/RainDeploySuitesBase.sol b/src/abstract/RainDeploySuitesBase.sol index 9de212f0..85073f0e 100644 --- a/src/abstract/RainDeploySuitesBase.sol +++ b/src/abstract/RainDeploySuitesBase.sol @@ -554,17 +554,36 @@ abstract contract RainDeploySuitesBase { address deployer ) internal returns (address) { address expected = deployedAddress(d, suite, chainId); + clearForDeployStep(d, index, vm, suite, expected); + address actual = runDeployStepLocally(d, vm, suite, chainId, deployer); + if (actual != expected) { + revert DeployStepAddressMismatch(suite.suite, chainId, expected, actual); + } + return actual; + } + + function clearForDeployStep( + DeployDeclaration memory d, + DeploySuiteIndex memory index, + Vm vm, + DeploySuite memory suite, + address expected + ) private { address[] memory own = new address[](1); own[0] = expected; LibRainDeployDeclaration.etchDependencyClosure(d, index, vm, suite, own); vm.etch(expected, hex""); vm.resetNonce(expected); - address actual = - mechanismOf(d, suite).deployStepLocally(d, suite)(vm, deployer, deployStepData(d, suite, chainId)); - if (actual != expected) { - revert DeployStepAddressMismatch(suite.suite, chainId, expected, actual); - } - return actual; + } + + function runDeployStepLocally( + DeployDeclaration memory d, + Vm vm, + DeploySuite memory suite, + uint256 chainId, + address deployer + ) private returns (address) { + return mechanismOf(d, suite).deployStepLocally(d, suite)(vm, deployer, deployStepData(d, suite, chainId)); } function deployLocallyOnChain( diff --git a/src/abstract/RainDeployVerifyBase.sol b/src/abstract/RainDeployVerifyBase.sol index a7ac91bc..bebc37af 100644 --- a/src/abstract/RainDeployVerifyBase.sol +++ b/src/abstract/RainDeployVerifyBase.sol @@ -55,10 +55,11 @@ abstract contract RainDeployVerifyBase is RainDeploySuitesBase, Test { deployedAddresses: new address[](chainIds.length), bytecodeHashes: new bytes32[](chainIds.length) }); + (bool[] memory recorded,) = recordedAddresses(d, suite); bool anyDerived = false; for (uint256 i = 0; i < chainIds.length; i++) { - // `address(0)` is a network with nothing recorded, and has no code of the suite's. - if (deployedAddress(d, suite, chainIds[i]) == address(0)) { + // Mechanisms refuse to address a network they record nothing on. + if (!recorded[i]) { continue; } uint256 snapshotId = vm.snapshotState(); From 2b45c032dfadf3e94c6ee62d9cad0780a96c4f7d Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 12:53:00 +0000 Subject: [PATCH 12/17] Split deployToConfigs per network past stack too deep Co-Authored-By: Claude Opus 5.5 --- src/abstract/RainDeployBroadcast.sol | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/abstract/RainDeployBroadcast.sol b/src/abstract/RainDeployBroadcast.sol index fab1e42d..6f9398ca 100644 --- a/src/abstract/RainDeployBroadcast.sol +++ b/src/abstract/RainDeployBroadcast.sol @@ -225,20 +225,28 @@ abstract contract RainDeployBroadcast is RainDeploySuitesBase, Script { ); for (uint256 i = 0; i < configs.length; i++) { LibRainDeploy.selectCheckedFork(vm, configs[i], forkIds[i], closure); - preDeployCheck(d, suite, configs[i]); - LibRainDeploy.deployStepToSelectedFork( - vm, - configs[i].name, - deployer, - step, - deploys.deployStepData[i], - deploys.expectedAddresses[i], - checkedExpectedBytecodeHash(d, suite, configs[i].chainId) - ); + deployToSelectedFork(d, vm, suite, configs[i], deployer, step, deploys, i); } return forkIds; } + function deployToSelectedFork( + DeployDeclaration memory d, + Vm vm, + DeploySuite memory suite, + SupportedNetwork memory config, + address deployer, + function(Vm, string memory, address, bytes memory) internal returns (address) step, + NetworkDeploys memory deploys, + uint256 i + ) private { + preDeployCheck(d, suite, config); + bytes32 expectedHash = checkedExpectedBytecodeHash(d, suite, config.chainId); + LibRainDeploy.deployStepToSelectedFork( + vm, config.name, deployer, step, deploys.deployStepData[i], deploys.expectedAddresses[i], expectedHash + ); + } + /// Asserts `network`'s state on its selected fork before `suite` is deployed there; a revert aborts the /// broadcast. A no-op unless overridden. /// @param d The declaration. From 3664c9d4e1aeacf1d85a9a9adf268bde69381116 Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 12:56:58 +0000 Subject: [PATCH 13/17] Finish per-chain code snapshot-base tests against recorded-chain derivation Co-Authored-By: Claude Opus 5.5 --- test/abstract/PerChainCodeDeploySuites.sol | 23 +++++-- ...eployVerifySnapshotBase.perChainCode.t.sol | 68 +++++++++++++------ 2 files changed, 66 insertions(+), 25 deletions(-) diff --git a/test/abstract/PerChainCodeDeploySuites.sol b/test/abstract/PerChainCodeDeploySuites.sol index 69195979..033cf724 100644 --- a/test/abstract/PerChainCodeDeploySuites.sol +++ b/test/abstract/PerChainCodeDeploySuites.sol @@ -29,6 +29,8 @@ abstract contract PerChainCodeDeploySuites is MockCreate2DeploySuites { mapping(uint256 => address) internal sMisdeclaredAddresses; /// Where `deployedAddress` answers `address(0)`. mapping(uint256 => bool) internal sUndeployed; + /// Among the suite's `networks` but recorded nothing on by its mechanism. + mapping(uint256 => bool) internal sUnrecorded; function setBeacon(uint256 chainId, address beacon) external { sBeacons[chainId] = beacon; @@ -46,6 +48,10 @@ abstract contract PerChainCodeDeploySuites is MockCreate2DeploySuites { sUndeployed[chainId] = true; } + function setUnrecorded(uint256 chainId) external { + sUnrecorded[chainId] = true; + } + function perChainBeacon(uint256 chainId) internal pure returns (address) { return address(uint160(uint256(keccak256(abi.encode("rain.deploy.per-chain-code.beacon", chainId))))); } @@ -91,15 +97,21 @@ abstract contract PerChainCodeDeploySuites is MockCreate2DeploySuites { return sExpectedBytecodeHashes[chainId]; } - /// `PER_CHAIN_CODE_SUITE` on each of `chainIds`, recording where each chain's data lands. Its stored code is the - /// artifact's, with a zero beacon no chain's data deploys. + /// `PER_CHAIN_CODE_SUITE` on each of `chainIds`, recording where each chain's data lands except on chains set + /// unrecorded. Its stored code is the artifact's, with a zero beacon no chain's data deploys. function perChainCodeSuite(uint256[] memory chainIds) internal view returns (DeploySuite memory) { string memory artifactPath = "test/concrete/MockImmutableBeaconBound.sol:MockImmutableBeaconBound"; bytes memory storedRuntimeCode = StdConstants.VM.getDeployedCode(artifactPath); + string[] memory names = new string[](chainIds.length); MockNetworkDeploy[] memory networks = new MockNetworkDeploy[](chainIds.length); + uint256 recorded = 0; for (uint256 i = 0; i < chainIds.length; i++) { + names[i] = LibMockCreate2Mechanism.networkName(chainIds[i]); + if (sUnrecorded[chainIds[i]]) { + continue; + } bytes memory data = abi.encode(chainIds[i]); - networks[i] = MockNetworkDeploy({ + networks[recorded++] = MockNetworkDeploy({ chainId: chainIds[i], data: data, deployedAddress: LibMockCreate2Mechanism.create2Address( @@ -109,8 +121,11 @@ abstract contract PerChainCodeDeploySuites is MockCreate2DeploySuites { ) }); } + assembly ("memory-safe") { + mstore(networks, recorded) + } return DeploySuite({ - networks: LibMockCreate2Mechanism.networkNames(networks), + networks: names, suite: PER_CHAIN_CODE_SUITE, creationCode: type(MockImmutableBeaconBound).creationCode, storedDeployedAddress: address(0), diff --git a/test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol b/test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol index 5a218cbd..6cbff012 100644 --- a/test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol +++ b/test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol @@ -17,7 +17,7 @@ import { import {LibRainDeployDeclaration} from "../../../src/lib/LibRainDeployDeclaration.sol"; import {LibMockCreate2Mechanism} from "../../lib/LibMockCreate2Mechanism.sol"; import {MockImmutableBeaconBound} from "../../concrete/MockImmutableBeaconBound.sol"; -import {PerChainCodeDeploySuites} from "../../abstract/PerChainCodeDeploySuites.sol"; +import {PER_CHAIN_CODE_SUITE, PerChainCodeDeploySuites} from "../../abstract/PerChainCodeDeploySuites.sol"; /// @title RainDeployVerifySnapshotBasePerChainCodeTest /// @notice A suite whose deploy step data and runtime code differ per chain, derived and held to each chain's own @@ -86,7 +86,7 @@ contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuite return expectedBytecodeHash(declaration(), suite, chainId); } - function suite() internal view returns (DeploySuite memory) { + function perChainSuite() internal view returns (DeploySuite memory) { return perChainCodeSuite(perChainCodeChainIds()); } @@ -99,7 +99,7 @@ contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuite /// the stored code or another chain's. function testDerivesEachChainsOwnAddressAndCode() external { uint256[] memory chainIds = perChainCodeChainIds(); - DerivedDeploy memory derived = this.externalDeriveDeployment(suite()); + DerivedDeploy memory derived = this.externalDeriveDeployment(perChainSuite()); assertEq(derived.chainIds, chainIds); assertEq(derived.deployedAddresses.length, chainIds.length); @@ -109,14 +109,14 @@ contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuite assertEq( derived.deployedAddresses[i], LibMockCreate2Mechanism.create2Address( - LibMockCreate2Mechanism.decode(suite()).factory, - LibMockCreate2Mechanism.salt(suite(), chainIds[i]), + LibMockCreate2Mechanism.decode(perChainSuite()).factory, + LibMockCreate2Mechanism.salt(perChainSuite(), chainIds[i]), abi.encodePacked(type(MockImmutableBeaconBound).creationCode, abi.encode(perChainBeacon(chainIds[i]))) ) ); assertEq(derived.bytecodeHashes[i], expected); assertEq(this.externalDerivedBytecodeHash(derived, chainIds[i]), expected); - assertNotEq(expected, suite().storedBytecodeHash); + assertNotEq(expected, perChainSuite().storedBytecodeHash); for (uint256 j = 0; j < i; j++) { assertNotEq(derived.bytecodeHashes[i], derived.bytecodeHashes[j]); assertNotEq(derived.deployedAddresses[i], derived.deployedAddresses[j]); @@ -127,7 +127,7 @@ contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuite /// Every chain held to its own expected code hash is consistent. function testInternallyConsistentOnEveryChain() external { - this.externalCheckInternallyConsistent(suite()); + this.externalCheckInternallyConsistent(perChainSuite()); } /// The declaration's candidate passes the group's own test. @@ -149,7 +149,7 @@ contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuite vm.expectRevert( abi.encodeWithSelector(StoredCodeHashMismatch.selector, PER_CHAIN_CODE_SUITE, other, newCodeHash(chainIds[b])) ); - this.externalCheckInternallyConsistent(suite()); + this.externalCheckInternallyConsistent(perChainSuite()); } /// A chain with no expected code hash is refused rather than compared against zero. @@ -160,7 +160,7 @@ contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuite this.setExpectedBytecodeHash(chainIds[index], bytes32(0)); vm.expectRevert(abi.encodeWithSelector(NoExpectedBytecodeHash.selector, PER_CHAIN_CODE_SUITE, chainIds[index])); - this.externalCheckInternallyConsistent(suite()); + this.externalCheckInternallyConsistent(perChainSuite()); } /// A chain whose `deployedAddress` is not where its data lands is refused naming both. @@ -169,7 +169,7 @@ contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuite uint256[] memory chainIds = perChainCodeChainIds(); index = bound(index, 0, chainIds.length - 1); address misdeclared = address(0xdead); - address landing = perChainLandingAddress(suite(), chainIds[index]); + address landing = perChainLandingAddress(perChainSuite(), chainIds[index]); this.setMisdeclaredAddress(chainIds[index], misdeclared); vm.expectRevert( @@ -177,32 +177,58 @@ contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuite DeployStepAddressMismatch.selector, PER_CHAIN_CODE_SUITE, chainIds[index], misdeclared, landing ) ); - this.externalDeriveDeployment(suite()); + this.externalDeriveDeployment(perChainSuite()); } - /// A chain the suite deploys nothing on derives no code, and asking for it refuses. - /// @param index The chain deploying nothing. - function testDerivedHashRefusesAChainDeployingNothing(uint256 index) external { + /// A recorded chain whose `deployedAddress` answers `address(0)` is refused, not skipped. + /// @param index The chain answering `address(0)`. + function testRefusesARecordedChainWhoseDeployedAddressIsZero(uint256 index) external { uint256[] memory chainIds = perChainCodeChainIds(); index = bound(index, 0, chainIds.length - 1); + address landing = perChainLandingAddress(perChainSuite(), chainIds[index]); this.setUndeployed(chainIds[index]); - DerivedDeploy memory derived = this.externalDeriveDeployment(suite()); - assertEq(derived.deployedAddresses[index], address(0)); - assertEq(derived.bytecodeHashes[index], bytes32(0)); + vm.expectRevert( + abi.encodeWithSelector( + DeployStepAddressMismatch.selector, PER_CHAIN_CODE_SUITE, chainIds[index], address(0), landing + ) + ); + this.externalDeriveDeployment(perChainSuite()); + } + + /// A chain among the suite's networks that its mechanism records nothing on is never addressed: it derives no + /// code, asking for its code refuses, and every other chain derives its own. + /// @param index The unrecorded chain. + function testDerivesNothingOnAChainItRecordsNothingOn(uint256 index) external { + uint256[] memory chainIds = perChainCodeChainIds(); + index = bound(index, 0, chainIds.length - 1); + this.setUnrecorded(chainIds[index]); + DerivedDeploy memory derived = this.externalDeriveDeployment(perChainSuite()); + + assertEq(derived.chainIds, chainIds); + for (uint256 i = 0; i < chainIds.length; i++) { + if (i == index) { + assertEq(derived.deployedAddresses[i], address(0)); + assertEq(derived.bytecodeHashes[i], bytes32(0)); + } else { + assertEq(derived.deployedAddresses[i], perChainLandingAddress(perChainSuite(), chainIds[i])); + assertEq(derived.bytecodeHashes[i], newCodeHash(chainIds[i])); + } + } + this.externalCheckInternallyConsistent(perChainSuite()); vm.expectRevert(abi.encodeWithSelector(NotDerivedOnChain.selector, PER_CHAIN_CODE_SUITE, chainIds[index])); this.externalDerivedBytecodeHash(derived, chainIds[index]); } - /// A suite deploying nothing on any chain derives nothing. - function testRefusesASuiteDeployingNothingOnAnyChain() external { + /// A suite its mechanism records on no chain derives nothing. + function testRefusesASuiteRecordedOnNoChain() external { uint256[] memory chainIds = perChainCodeChainIds(); for (uint256 i = 0; i < chainIds.length; i++) { - this.setUndeployed(chainIds[i]); + this.setUnrecorded(chainIds[i]); } vm.expectRevert(abi.encodeWithSelector(NoDerivedDeployment.selector, PER_CHAIN_CODE_SUITE)); - this.externalDeriveDeployment(suite()); + this.externalDeriveDeployment(perChainSuite()); } /// A suite that does not override expects its stored code hash on every chain. From cb4b9ccc51b9cd3711ca2d7de80733ebb2fbd64b Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 13:01:16 +0000 Subject: [PATCH 14/17] Test per-chain code on the chain, dependency and broadcast paths, and the per-network deploy key seat Co-Authored-By: Claude Opus 5.5 --- test/concrete/MockBoundOwner.sol | 21 +++ test/concrete/PerChainCodeDeploy.sol | 74 ++++++++ test/concrete/PerNetworkOwnerDeploy.sol | 63 +++++++ .../RainDeployBroadcast.perChainCode.t.sol | 92 ++++++++++ ...loyBroadcast.perNetworkDeployKeySeat.t.sol | 135 +++++++++++++++ ...DeployDeclarationChecks.perChainCode.t.sol | 161 ++++++++++++++++++ .../RainDeployVerifyChain.perChainCode.t.sol | 143 ++++++++++++++++ 7 files changed, 689 insertions(+) create mode 100644 test/concrete/MockBoundOwner.sol create mode 100644 test/concrete/PerChainCodeDeploy.sol create mode 100644 test/concrete/PerNetworkOwnerDeploy.sol create mode 100644 test/src/abstract/RainDeployBroadcast.perChainCode.t.sol create mode 100644 test/src/abstract/RainDeployBroadcast.perNetworkDeployKeySeat.t.sol create mode 100644 test/src/abstract/RainDeployDeclarationChecks.perChainCode.t.sol create mode 100644 test/src/abstract/RainDeployVerifyChain.perChainCode.t.sol diff --git a/test/concrete/MockBoundOwner.sol b/test/concrete/MockBoundOwner.sol new file mode 100644 index 00000000..104059a5 --- /dev/null +++ b/test/concrete/MockBoundOwner.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +/// @title MockBoundOwner +/// @notice Answers `owner()` with the address its constructor is given. +contract MockBoundOwner { + /// The owner. + address public sOwner; + + /// @param owner_ The owner. + //forge-lint: disable-next-line(missing-zero-check) + constructor(address owner_) { + sOwner = owner_; + } + + /// @return The owner. + function owner() external view returns (address) { + return sOwner; + } +} diff --git a/test/concrete/PerChainCodeDeploy.sol b/test/concrete/PerChainCodeDeploy.sol new file mode 100644 index 00000000..ac912897 --- /dev/null +++ b/test/concrete/PerChainCodeDeploy.sol @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +import {DeployCandidate, DeployDeclaration, DeploySuite} from "../../src/abstract/RainDeploySuitesBase.sol"; +import {LibRainDeployDeclaration} from "../../src/lib/LibRainDeployDeclaration.sol"; +import {ExternalDeployBroadcast} from "../abstract/ExternalDeployBroadcast.sol"; +import {PerChainCodeDeploySuites} from "../abstract/PerChainCodeDeploySuites.sol"; +import {LibMockCreate2Mechanism} from "../lib/LibMockCreate2Mechanism.sol"; + +/// @title PerChainCodeDeploy +/// @notice Broadcasts `PER_CHAIN_CODE_SUITE` as its candidate, deploying each chain's own data and expecting each +/// chain's own code. +contract PerChainCodeDeploy is PerChainCodeDeploySuites, ExternalDeployBroadcast { + function declaration() internal view override returns (DeployDeclaration memory) { + DeployDeclaration memory d; + LibRainDeployDeclaration.extend(d); + LibRainDeployDeclaration.setNetworks(d, perChainCodeNetworks()); + LibMockCreate2Mechanism.extend(d); + DeployCandidate[] memory candidates = new DeployCandidate[](1); + candidates[0] = DeployCandidate({snapshot: perChainCodeSuite(perChainCodeChainIds()), unanchorableReason: ""}); + LibRainDeployDeclaration.addCandidates(d, candidates); + return d; + } + + function deployStepData(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (bytes memory) + { + return isPerChainCode(suite) ? perChainDeployStepData(suite, chainId) : super.deployStepData(d, suite, chainId); + } + + function deployedAddress(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (address) + { + return isPerChainCode(suite) ? perChainDeployedAddress(suite, chainId) : super.deployedAddress(d, suite, chainId); + } + + function expectedBytecodeHash(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (bytes32) + { + return isPerChainCode(suite) + ? perChainExpectedBytecodeHash(chainId) + : super.expectedBytecodeHash(d, suite, chainId); + } + + function externalPerChainCodeSuite() external view returns (DeploySuite memory) { + return perChainCodeSuite(perChainCodeChainIds()); + } + + function externalPerChainBeacon(uint256 chainId) external pure returns (address) { + return perChainBeacon(chainId); + } + + function externalPerChainLandingAddress(uint256 chainId) external view returns (address) { + return perChainLandingAddress(perChainCodeSuite(perChainCodeChainIds()), chainId); + } + + function externalPerChainCodeNetworks() external pure returns (string[] memory) { + return perChainCodeNetworks(); + } + + function externalPerChainCodeChainIds() external pure returns (uint256[] memory) { + return perChainCodeChainIds(); + } +} diff --git a/test/concrete/PerNetworkOwnerDeploy.sol b/test/concrete/PerNetworkOwnerDeploy.sol new file mode 100644 index 00000000..8066ef5b --- /dev/null +++ b/test/concrete/PerNetworkOwnerDeploy.sol @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +import {DeployDeclaration, DeploySuite} from "../../src/abstract/RainDeploySuitesBase.sol"; +import {LibMockCreate2Mechanism} from "../lib/LibMockCreate2Mechanism.sol"; +import {MockBoundOwner} from "./MockBoundOwner.sol"; +import {MockCreate2Deploy} from "./MockCreate2Deploy.sol"; + +/// @dev The key of the suite `PerNetworkOwnerDeploy` binds to each network's owner. +string constant OWNER_BOUND_SUITE = "owner-bound"; + +/// @title PerNetworkOwnerDeploy +/// @notice `MockCreate2Deploy` overriding `deployStepData` and `deployedAddress` so `OWNER_BOUND_SUITE` deploys +/// `MockBoundOwner` bound to the owner set for each chain id, at that network's salt, whatever creation code the +/// suite carries. +contract PerNetworkOwnerDeploy is MockCreate2Deploy { + mapping(uint256 => address) internal sOwners; + + function setOwner(uint256 chainId, address owner) external { + sOwners[chainId] = owner; + } + + function isOwnerBound(DeploySuite memory suite) internal pure returns (bool) { + return keccak256(bytes(suite.suite)) == keccak256(bytes(OWNER_BOUND_SUITE)); + } + + function ownerBoundCreationCode(uint256 chainId) internal view returns (bytes memory) { + return abi.encodePacked(type(MockBoundOwner).creationCode, abi.encode(sOwners[chainId])); + } + + function deployStepData(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (bytes memory) + { + if (!isOwnerBound(suite)) { + return super.deployStepData(d, suite, chainId); + } + return abi.encode( + LibMockCreate2Mechanism.decode(suite).factory, + LibMockCreate2Mechanism.salt(suite, chainId), + ownerBoundCreationCode(chainId) + ); + } + + function deployedAddress(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (address) + { + if (!isOwnerBound(suite)) { + return super.deployedAddress(d, suite, chainId); + } + return LibMockCreate2Mechanism.create2Address( + LibMockCreate2Mechanism.decode(suite).factory, + LibMockCreate2Mechanism.salt(suite, chainId), + ownerBoundCreationCode(chainId) + ); + } +} diff --git a/test/src/abstract/RainDeployBroadcast.perChainCode.t.sol b/test/src/abstract/RainDeployBroadcast.perChainCode.t.sol new file mode 100644 index 00000000..c03bb4b4 --- /dev/null +++ b/test/src/abstract/RainDeployBroadcast.perChainCode.t.sol @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +import {Test} from "forge-std-1.17.0/src/Test.sol"; +import {Vm} from "forge-std-1.17.0/src/Vm.sol"; +import {DeploySuite, NoExpectedBytecodeHash} from "../../../src/abstract/RainDeploySuitesBase.sol"; +import {LibRainDeploy} from "../../../src/lib/LibRainDeploy.sol"; +import {MOCK_CREATE2_FACTORY} from "../../lib/LibMockCreate2Mechanism.sol"; +import {LocalForkVm} from "../../concrete/LocalForkVm.sol"; +import {MockCreate2Factory} from "../../concrete/MockCreate2Factory.sol"; +import {MockImmutableBeaconBound} from "../../concrete/MockImmutableBeaconBound.sol"; +import {PerChainCodeDeploy} from "../../concrete/PerChainCodeDeploy.sol"; +import {PER_CHAIN_CODE_SUITE} from "../../abstract/PerChainCodeDeploySuites.sol"; + +/// @title RainDeployBroadcastPerChainCodeTest +/// @notice One broadcast run of a suite whose runtime code differs per chain holds each network to that chain's own +/// expected code hash. +contract RainDeployBroadcastPerChainCodeTest is Test { + PerChainCodeDeploy internal sDeploy; + LocalForkVm internal sForkVm; + + function setUp() external { + sDeploy = new PerChainCodeDeploy(); + sForkVm = new LocalForkVm(); + vm.etch(MOCK_CREATE2_FACTORY, type(MockCreate2Factory).runtimeCode); + sDeploy.bindPerChainCode(); + } + + /// The runtime code `new` leaves for `chainId`'s beacon. + function newCode(uint256 chainId) internal returns (bytes memory) { + return address(new MockImmutableBeaconBound(sDeploy.externalPerChainBeacon(chainId))).code; + } + + function broadcast() external returns (address[] memory) { + DeploySuite memory suite = sDeploy.externalPerChainCodeSuite(); + (address[] memory deployed,) = sDeploy.externalDeployAndBroadcast( + Vm(address(sForkVm)), sDeploy.externalPerChainCodeNetworks(), 1, suite, suite + ); + return deployed; + } + + /// Each network gets its own chain's code at its own address, none of which is another's. + function testOneRunDeploysEachChainsOwnCode() external { + uint256[] memory chainIds = sDeploy.externalPerChainCodeChainIds(); + address[] memory deployed = this.broadcast(); + + assertEq(deployed.length, chainIds.length); + for (uint256 i = 0; i < chainIds.length; i++) { + assertEq(deployed[i], sDeploy.externalPerChainLandingAddress(chainIds[i])); + assertEq(deployed[i].code, newCode(chainIds[i])); + assertEq(MockImmutableBeaconBound(deployed[i]).iBeacon(), sDeploy.externalPerChainBeacon(chainIds[i])); + for (uint256 j = 0; j < i; j++) { + assertNotEq(deployed[i].codehash, deployed[j].codehash); + } + } + } + + /// A network expecting another chain's code is refused once its own code lands, naming both. + /// @param a The network expecting the other chain's code. + /// @param b The chain whose code it expects. + function testRefusesANetworkExpectingAnotherChainsCode(uint256 a, uint256 b) external { + uint256[] memory chainIds = sDeploy.externalPerChainCodeChainIds(); + a = bound(a, 0, chainIds.length - 1); + b = bound(b, 0, chainIds.length - 1); + vm.assume(a != b); + bytes32 other = keccak256(newCode(chainIds[b])); + sDeploy.setExpectedBytecodeHash(chainIds[a], other); + + vm.expectRevert( + abi.encodeWithSelector( + LibRainDeploy.CodeHashMismatchOnNetwork.selector, + sDeploy.externalPerChainCodeNetworks()[a], + sDeploy.externalPerChainLandingAddress(chainIds[a]), + other, + keccak256(newCode(chainIds[a])) + ) + ); + this.broadcast(); + } + + /// A network with no expected code hash is refused rather than compared against zero. + /// @param a The network with none. + function testRefusesANetworkWithNoExpectedCodeHash(uint256 a) external { + uint256[] memory chainIds = sDeploy.externalPerChainCodeChainIds(); + a = bound(a, 0, chainIds.length - 1); + sDeploy.setExpectedBytecodeHash(chainIds[a], bytes32(0)); + + vm.expectRevert(abi.encodeWithSelector(NoExpectedBytecodeHash.selector, PER_CHAIN_CODE_SUITE, chainIds[a])); + this.broadcast(); + } +} diff --git a/test/src/abstract/RainDeployBroadcast.perNetworkDeployKeySeat.t.sol b/test/src/abstract/RainDeployBroadcast.perNetworkDeployKeySeat.t.sol new file mode 100644 index 00000000..fa615c56 --- /dev/null +++ b/test/src/abstract/RainDeployBroadcast.perNetworkDeployKeySeat.t.sol @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +import {Test} from "forge-std-1.17.0/src/Test.sol"; +import {DeployDependency, DeploySuite} from "../../../src/abstract/RainDeploySuitesBase.sol"; +import {SuiteSeatsDeployKey} from "../../../src/abstract/RainDeployBroadcast.sol"; +import {LibRainDeploy} from "../../../src/lib/LibRainDeploy.sol"; +import {MockNetworkDeploy} from "../../lib/LibMockNetworkRecord.sol"; +import { + LibMockCreate2Mechanism, + MOCK_CREATE2_FACTORY, + MOCK_CREATE2_SALT, + MockCreate2Mechanism +} from "../../lib/LibMockCreate2Mechanism.sol"; +import {MockBoundOwner} from "../../concrete/MockBoundOwner.sol"; +import {OWNER_BOUND_SUITE, PerNetworkOwnerDeploy} from "../../concrete/PerNetworkOwnerDeploy.sol"; + +/// @title RainDeployBroadcastPerNetworkDeployKeySeatTest +/// @notice A consumer whose per-network deploy step data seats the deploy key on one network is refused, though the +/// suite's own creation code seats it nowhere. +contract RainDeployBroadcastPerNetworkDeployKeySeatTest is Test { + address constant OTHER_OWNER = address(0xB0B); + uint256 constant DEPLOYER_KEY = 1; + + PerNetworkOwnerDeploy internal sDeploy; + + function setUp() external { + sDeploy = new PerNetworkOwnerDeploy(); + } + + function chainIds() internal pure returns (uint256[] memory) { + uint256[] memory ids = new uint256[](2); + ids[0] = 42161; + ids[1] = 137; + return ids; + } + + function networks() internal pure returns (string[] memory) { + string[] memory names = new string[](2); + names[0] = LibRainDeploy.ARBITRUM_ONE; + names[1] = LibRainDeploy.POLYGON; + return names; + } + + function boundCreationCode(address owner) internal pure returns (bytes memory) { + return abi.encodePacked(type(MockBoundOwner).creationCode, abi.encode(owner)); + } + + /// Where `MockBoundOwner` bound to `owner` lands at `chainId`'s salt. + function boundAddress(uint256 chainId, address owner) internal pure returns (address) { + return LibMockCreate2Mechanism.create2Address( + MOCK_CREATE2_FACTORY, keccak256(abi.encode(MOCK_CREATE2_SALT, abi.encode(chainId))), boundCreationCode(owner) + ); + } + + /// Sets each network's owner on the deploy and returns `OWNER_BOUND_SUITE` recording where each network's data + /// lands. Its own creation code is bound to `OTHER_OWNER`, so deploying it seats the deploy key nowhere. + function ownerBoundSuite(address[] memory owners) internal returns (DeploySuite memory) { + uint256[] memory ids = chainIds(); + MockNetworkDeploy[] memory recorded = new MockNetworkDeploy[](ids.length); + for (uint256 i = 0; i < ids.length; i++) { + sDeploy.setOwner(ids[i], owners[i]); + recorded[i] = MockNetworkDeploy({ + chainId: ids[i], data: abi.encode(ids[i]), deployedAddress: boundAddress(ids[i], owners[i]) + }); + } + return DeploySuite({ + networks: LibMockCreate2Mechanism.networkNames(recorded), + suite: OWNER_BOUND_SUITE, + creationCode: boundCreationCode(OTHER_OWNER), + storedDeployedAddress: address(0), + storedBytecodeHash: keccak256(type(MockBoundOwner).runtimeCode), + storedRuntimeCode: type(MockBoundOwner).runtimeCode, + artifactPath: "test/concrete/MockBoundOwner.sol:MockBoundOwner", + dependencies: new DeployDependency[](0), + mechanismData: LibMockCreate2Mechanism.encode( + MockCreate2Mechanism({ + factory: MOCK_CREATE2_FACTORY, salt: MOCK_CREATE2_SALT, perNetwork: true, networks: recorded, root: "" + }) + ), + describedByMeta: "" + }); + } + + /// The owners with the deploy key on network `seated` and `OTHER_OWNER` elsewhere. + function ownersSeating(uint256 seated) internal pure returns (address[] memory) { + address[] memory owners = new address[](2); + owners[0] = OTHER_OWNER; + owners[1] = OTHER_OWNER; + owners[seated] = vm.addr(DEPLOYER_KEY); + return owners; + } + + /// The seat check refuses the network whose own data seats the deploy key, naming that network's address. + /// @param seated The network seating the deploy key. + function testSeatCheckRefusesANetworkWhoseOwnDataSeatsTheDeployKey(uint256 seated) external { + seated = bound(seated, 0, 1); + address deployer = vm.addr(DEPLOYER_KEY); + DeploySuite memory suite = ownerBoundSuite(ownersSeating(seated)); + + vm.expectRevert( + abi.encodeWithSelector( + SuiteSeatsDeployKey.selector, OWNER_BOUND_SUITE, boundAddress(chainIds()[seated], deployer) + ) + ); + sDeploy.externalCheckSeatsNoDeployKey(suite, chainIds(), deployer); + } + + /// The broadcast refuses before forking when one network's own data seats the deploy key. + /// @param seated The network seating the deploy key. + function testBroadcastRefusesANetworkWhoseOwnDataSeatsTheDeployKey(uint256 seated) external { + seated = bound(seated, 0, 1); + DeploySuite memory suite = ownerBoundSuite(ownersSeating(seated)); + + vm.expectRevert( + abi.encodeWithSelector( + SuiteSeatsDeployKey.selector, OWNER_BOUND_SUITE, boundAddress(chainIds()[seated], vm.addr(DEPLOYER_KEY)) + ) + ); + sDeploy.externalBroadcastSuite(suite, networks(), DEPLOYER_KEY); + } + + /// No network's own data seating the deploy key passes the seat check. + /// @param owner The owner another network's data seats. + function testSeatCheckPassesWhenNoNetworksOwnDataSeatsTheDeployKey(address owner) external { + address deployer = vm.addr(DEPLOYER_KEY); + vm.assume(owner != deployer); + address[] memory owners = new address[](2); + owners[0] = OTHER_OWNER; + owners[1] = owner; + + sDeploy.externalCheckSeatsNoDeployKey(ownerBoundSuite(owners), chainIds(), deployer); + } +} diff --git a/test/src/abstract/RainDeployDeclarationChecks.perChainCode.t.sol b/test/src/abstract/RainDeployDeclarationChecks.perChainCode.t.sol new file mode 100644 index 00000000..3d743fcc --- /dev/null +++ b/test/src/abstract/RainDeployDeclarationChecks.perChainCode.t.sol @@ -0,0 +1,161 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +import { + DeployCandidate, + DeployDeclaration, + DeployDependency, + DeploySuite, + NoExpectedBytecodeHash +} from "../../../src/abstract/RainDeploySuitesBase.sol"; +import { + DependencyRuntimeCodeMismatch, + RainDeployDeclarationChecks +} from "../../../src/abstract/RainDeployDeclarationChecks.sol"; +import {LibRainDeployDeclaration} from "../../../src/lib/LibRainDeployDeclaration.sol"; +import {LibMockCreate2Mechanism} from "../../lib/LibMockCreate2Mechanism.sol"; +import {MockImmutableBeaconBound} from "../../concrete/MockImmutableBeaconBound.sol"; +import {PER_CHAIN_CODE_SUITE, PerChainCodeDeploySuites} from "../../abstract/PerChainCodeDeploySuites.sol"; + +/// @title RainDeployDeclarationChecksPerChainCodeTest +/// @notice A dependency on a sibling whose runtime code differs per chain is held to the code that sibling is +/// expected to have on the chain it is recorded at the dependency's address. +contract RainDeployDeclarationChecksPerChainCodeTest is PerChainCodeDeploySuites, RainDeployDeclarationChecks { + string constant DEPENDENT_SUITE = "per-chain-code-dependent"; + + function setUp() external { + this.bindPerChainCode(); + } + + function declaration() internal view override returns (DeployDeclaration memory) { + return declarationWith(new DeployDependency[](0)); + } + + function declarationWith(DeployDependency[] memory dependencies) + internal + view + returns (DeployDeclaration memory) + { + DeployDeclaration memory d; + LibRainDeployDeclaration.extend(d); + LibRainDeployDeclaration.setNetworks(d, perChainCodeNetworks()); + LibMockCreate2Mechanism.extend(d); + DeploySuite memory dependent = mockSingleSuite(DEPENDENT_SUITE); + dependent.dependencies = dependencies; + DeployCandidate[] memory candidates = new DeployCandidate[](2); + candidates[0] = DeployCandidate({snapshot: perChainCodeSuite(perChainCodeChainIds()), unanchorableReason: ""}); + candidates[1] = DeployCandidate({snapshot: dependent, unanchorableReason: ""}); + LibRainDeployDeclaration.addCandidates(d, candidates); + return d; + } + + function expectedBytecodeHash(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (bytes32) + { + return isPerChainCode(suite) + ? perChainExpectedBytecodeHash(chainId) + : super.expectedBytecodeHash(d, suite, chainId); + } + + function externalCheckDependingOn(address dependency, bytes memory runtimeCode) external view { + DeployDependency[] memory dependencies = new DeployDependency[](1); + dependencies[0] = DeployDependency({deployedAddress: dependency, runtimeCode: runtimeCode}); + checkDependencyRuntimeCodeIsKnown(declarationWith(dependencies)); + } + + /// Where `chainId`'s data lands. + function landing(uint256 chainId) internal view returns (address) { + return perChainLandingAddress(perChainCodeSuite(perChainCodeChainIds()), chainId); + } + + /// The runtime code `new` leaves for `chainId`'s beacon. + function newCode(uint256 chainId) internal returns (bytes memory) { + return address(new MockImmutableBeaconBound(perChainBeacon(chainId))).code; + } + + /// A dependency on a chain's address declaring that chain's own code passes, though it is not the stored code. + /// @param a The chain depended on. + function testAcceptsADependencyDeclaringItsChainsOwnCode(uint256 a) external { + uint256[] memory chainIds = perChainCodeChainIds(); + a = bound(a, 0, chainIds.length - 1); + bytes memory code = newCode(chainIds[a]); + assertNotEq(keccak256(code), perChainCodeSuite(chainIds).storedBytecodeHash); + + this.externalCheckDependingOn(landing(chainIds[a]), code); + } + + /// A dependency on a chain's address declaring another chain's code is refused, naming the code expected there. + /// @param a The chain depended on. + /// @param b The chain whose code is declared. + function testRefusesADependencyDeclaringAnotherChainsCode(uint256 a, uint256 b) external { + uint256[] memory chainIds = perChainCodeChainIds(); + a = bound(a, 0, chainIds.length - 1); + b = bound(b, 0, chainIds.length - 1); + vm.assume(a != b); + address dependency = landing(chainIds[a]); + bytes memory other = newCode(chainIds[b]); + + vm.expectRevert( + abi.encodeWithSelector( + DependencyRuntimeCodeMismatch.selector, + DEPENDENT_SUITE, + dependency, + keccak256(other), + keccak256(newCode(chainIds[a])) + ) + ); + this.externalCheckDependingOn(dependency, other); + } + + /// A dependency on a chain's address declaring the stored code, which no chain's data deploys, is refused. + /// @param a The chain depended on. + function testRefusesADependencyDeclaringTheStoredCode(uint256 a) external { + uint256[] memory chainIds = perChainCodeChainIds(); + a = bound(a, 0, chainIds.length - 1); + address dependency = landing(chainIds[a]); + bytes memory stored = perChainCodeSuite(chainIds).storedRuntimeCode; + + vm.expectRevert( + abi.encodeWithSelector( + DependencyRuntimeCodeMismatch.selector, + DEPENDENT_SUITE, + dependency, + keccak256(stored), + keccak256(newCode(chainIds[a])) + ) + ); + this.externalCheckDependingOn(dependency, stored); + } + + /// A dependency on a chain's address where the sibling has no expected code hash is refused rather than compared + /// against zero. + /// @param a The chain depended on. + function testRefusesADependencyOnAChainWithNoExpectedCodeHash(uint256 a) external { + uint256[] memory chainIds = perChainCodeChainIds(); + a = bound(a, 0, chainIds.length - 1); + bytes memory code = newCode(chainIds[a]); + this.setExpectedBytecodeHash(chainIds[a], bytes32(0)); + + vm.expectRevert(abi.encodeWithSelector(NoExpectedBytecodeHash.selector, PER_CHAIN_CODE_SUITE, chainIds[a])); + this.externalCheckDependingOn(landing(chainIds[a]), code); + } + + /// Only the chain recorded at the dependency's address is asked for its expected code hash: another chain with + /// none does not refuse. + /// @param a The chain depended on. + /// @param b A chain with no expected code hash. + function testAsksOnlyTheChainRecordedAtTheDependency(uint256 a, uint256 b) external { + uint256[] memory chainIds = perChainCodeChainIds(); + a = bound(a, 0, chainIds.length - 1); + b = bound(b, 0, chainIds.length - 1); + vm.assume(a != b); + bytes memory code = newCode(chainIds[a]); + this.setExpectedBytecodeHash(chainIds[b], bytes32(0)); + + this.externalCheckDependingOn(landing(chainIds[a]), code); + } +} diff --git a/test/src/abstract/RainDeployVerifyChain.perChainCode.t.sol b/test/src/abstract/RainDeployVerifyChain.perChainCode.t.sol new file mode 100644 index 00000000..4d251f31 --- /dev/null +++ b/test/src/abstract/RainDeployVerifyChain.perChainCode.t.sol @@ -0,0 +1,143 @@ +// SPDX-License-Identifier: LicenseRef-DCL-1.0 +// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd +pragma solidity =0.8.25; + +import {Vm} from "forge-std-1.17.0/src/Vm.sol"; +import {DeployCandidate, DeployDeclaration, DeploySuite} from "../../../src/abstract/RainDeploySuitesBase.sol"; +import {RainDeployVerifyChain} from "../../../src/abstract/RainDeployVerifyChain.sol"; +import {LibRainDeploy} from "../../../src/lib/LibRainDeploy.sol"; +import {LibRainDeployDeclaration} from "../../../src/lib/LibRainDeployDeclaration.sol"; +import {LibMockCreate2Mechanism} from "../../lib/LibMockCreate2Mechanism.sol"; +import {LocalForkVm} from "../../concrete/LocalForkVm.sol"; +import {MockImmutableBeaconBound} from "../../concrete/MockImmutableBeaconBound.sol"; +import {PerChainCodeDeploySuites} from "../../abstract/PerChainCodeDeploySuites.sol"; + +/// @title RainDeployVerifyChainPerChainCodeTest +/// @notice The chain group holds each network of a suite whose runtime code differs per chain to the code that +/// chain's own deploy step data derives. +contract RainDeployVerifyChainPerChainCodeTest is PerChainCodeDeploySuites, RainDeployVerifyChain { + LocalForkVm internal sForkVm; + + function setUp() external { + sForkVm = new LocalForkVm(); + this.bindPerChainCode(); + } + + function declaration() internal view override returns (DeployDeclaration memory) { + DeployDeclaration memory d; + LibRainDeployDeclaration.extend(d); + LibRainDeployDeclaration.setNetworks(d, perChainCodeNetworks()); + LibMockCreate2Mechanism.extend(d); + DeployCandidate[] memory candidates = new DeployCandidate[](1); + candidates[0] = DeployCandidate({snapshot: perChainSuite(), unanchorableReason: ""}); + LibRainDeployDeclaration.addCandidates(d, candidates); + return d; + } + + function deployStepData(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (bytes memory) + { + return isPerChainCode(suite) ? perChainDeployStepData(suite, chainId) : super.deployStepData(d, suite, chainId); + } + + function deployedAddress(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (address) + { + return isPerChainCode(suite) ? perChainDeployedAddress(suite, chainId) : super.deployedAddress(d, suite, chainId); + } + + function expectedBytecodeHash(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) + internal + view + override + returns (bytes32) + { + return isPerChainCode(suite) + ? perChainExpectedBytecodeHash(chainId) + : super.expectedBytecodeHash(d, suite, chainId); + } + + function perChainSuite() internal view returns (DeploySuite memory) { + return perChainCodeSuite(perChainCodeChainIds()); + } + + /// The runtime code `new` leaves for `chainId`'s beacon. + function newCode(uint256 chainId) internal returns (bytes memory) { + return address(new MockImmutableBeaconBound(perChainBeacon(chainId))).code; + } + + /// Etches each chain's own code at the address its data lands at. + function etchEachChainsOwnCode() internal { + uint256[] memory chainIds = perChainCodeChainIds(); + for (uint256 i = 0; i < chainIds.length; i++) { + vm.etch(perChainLandingAddress(perChainSuite(), chainIds[i]), newCode(chainIds[i])); + } + } + + function externalCheckOnEveryNetwork() external { + DeploySuite[] memory suites = new DeploySuite[](1); + suites[0] = perChainSuite(); + checkDeployedOnNetworks( + declaration(), Vm(address(sForkVm)), LibRainDeploy.declaredNetworkConfigs(perChainCodeNetworks()), suites + ); + } + + /// Every network holding its own chain's code passes, though no two chains' code is the same. + function testChecksEachNetworkAgainstItsOwnChainsCode() external { + etchEachChainsOwnCode(); + this.externalCheckOnEveryNetwork(); + } + + /// A network holding another chain's code at its own address is refused, naming the code its own data derives. + /// @param a The network holding the other chain's code. + /// @param b The chain whose code it holds. + function testRefusesANetworkHoldingAnotherChainsCode(uint256 a, uint256 b) external { + uint256[] memory chainIds = perChainCodeChainIds(); + a = bound(a, 0, chainIds.length - 1); + b = bound(b, 0, chainIds.length - 1); + vm.assume(a != b); + etchEachChainsOwnCode(); + address held = perChainLandingAddress(perChainSuite(), chainIds[a]); + bytes memory other = newCode(chainIds[b]); + vm.etch(held, other); + + vm.expectRevert( + abi.encodeWithSelector( + LibRainDeploy.CodeHashMismatchOnNetwork.selector, + perChainCodeNetworks()[a], + held, + keccak256(newCode(chainIds[a])), + keccak256(other) + ) + ); + this.externalCheckOnEveryNetwork(); + } + + /// A network holding the stored code, which no chain's data deploys, is refused. + /// @param a The network holding the stored code. + function testRefusesANetworkHoldingTheStoredCode(uint256 a) external { + uint256[] memory chainIds = perChainCodeChainIds(); + a = bound(a, 0, chainIds.length - 1); + etchEachChainsOwnCode(); + address held = perChainLandingAddress(perChainSuite(), chainIds[a]); + bytes memory stored = perChainSuite().storedRuntimeCode; + vm.etch(held, stored); + + vm.expectRevert( + abi.encodeWithSelector( + LibRainDeploy.CodeHashMismatchOnNetwork.selector, + perChainCodeNetworks()[a], + held, + keccak256(newCode(chainIds[a])), + keccak256(stored) + ) + ); + this.externalCheckOnEveryNetwork(); + } +} From 95b8840d2d1fbe0e50f83379a5060e47377bd1ab Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 13:02:08 +0000 Subject: [PATCH 15/17] Format per-chain code tests Co-Authored-By: Claude Opus 5.5 --- test/abstract/PerChainCodeDeploySuites.sol | 5 ++++- test/concrete/PerChainCodeDeploy.sol | 3 ++- .../RainDeployBroadcast.perNetworkDeployKeySeat.t.sol | 10 ++++++++-- .../RainDeployDeclarationChecks.perChainCode.t.sol | 6 +----- .../RainDeployVerifyBase.dependencyClosure.t.sol | 3 ++- .../abstract/RainDeployVerifyChain.perChainCode.t.sol | 3 ++- .../RainDeployVerifySnapshotBase.perChainCode.t.sol | 11 ++++++++--- 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/test/abstract/PerChainCodeDeploySuites.sol b/test/abstract/PerChainCodeDeploySuites.sol index 033cf724..6b8d7e93 100644 --- a/test/abstract/PerChainCodeDeploySuites.sol +++ b/test/abstract/PerChainCodeDeploySuites.sol @@ -76,7 +76,10 @@ abstract contract PerChainCodeDeploySuites is MockCreate2DeploySuites { } function perChainDeployStepData(DeploySuite memory suite, uint256 chainId) internal view returns (bytes memory) { - return abi.encode(MOCK_CREATE2_FACTORY, LibMockCreate2Mechanism.salt(suite, chainId), perChainCreationCode(chainId)); + return + abi.encode( + MOCK_CREATE2_FACTORY, LibMockCreate2Mechanism.salt(suite, chainId), perChainCreationCode(chainId) + ); } function perChainLandingAddress(DeploySuite memory suite, uint256 chainId) internal view returns (address) { diff --git a/test/concrete/PerChainCodeDeploy.sol b/test/concrete/PerChainCodeDeploy.sol index ac912897..2391a15c 100644 --- a/test/concrete/PerChainCodeDeploy.sol +++ b/test/concrete/PerChainCodeDeploy.sol @@ -38,7 +38,8 @@ contract PerChainCodeDeploy is PerChainCodeDeploySuites, ExternalDeployBroadcast override returns (address) { - return isPerChainCode(suite) ? perChainDeployedAddress(suite, chainId) : super.deployedAddress(d, suite, chainId); + return + isPerChainCode(suite) ? perChainDeployedAddress(suite, chainId) : super.deployedAddress(d, suite, chainId); } function expectedBytecodeHash(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) diff --git a/test/src/abstract/RainDeployBroadcast.perNetworkDeployKeySeat.t.sol b/test/src/abstract/RainDeployBroadcast.perNetworkDeployKeySeat.t.sol index fa615c56..13c2e155 100644 --- a/test/src/abstract/RainDeployBroadcast.perNetworkDeployKeySeat.t.sol +++ b/test/src/abstract/RainDeployBroadcast.perNetworkDeployKeySeat.t.sol @@ -50,7 +50,9 @@ contract RainDeployBroadcastPerNetworkDeployKeySeatTest is Test { /// Where `MockBoundOwner` bound to `owner` lands at `chainId`'s salt. function boundAddress(uint256 chainId, address owner) internal pure returns (address) { return LibMockCreate2Mechanism.create2Address( - MOCK_CREATE2_FACTORY, keccak256(abi.encode(MOCK_CREATE2_SALT, abi.encode(chainId))), boundCreationCode(owner) + MOCK_CREATE2_FACTORY, + keccak256(abi.encode(MOCK_CREATE2_SALT, abi.encode(chainId))), + boundCreationCode(owner) ); } @@ -76,7 +78,11 @@ contract RainDeployBroadcastPerNetworkDeployKeySeatTest is Test { dependencies: new DeployDependency[](0), mechanismData: LibMockCreate2Mechanism.encode( MockCreate2Mechanism({ - factory: MOCK_CREATE2_FACTORY, salt: MOCK_CREATE2_SALT, perNetwork: true, networks: recorded, root: "" + factory: MOCK_CREATE2_FACTORY, + salt: MOCK_CREATE2_SALT, + perNetwork: true, + networks: recorded, + root: "" }) ), describedByMeta: "" diff --git a/test/src/abstract/RainDeployDeclarationChecks.perChainCode.t.sol b/test/src/abstract/RainDeployDeclarationChecks.perChainCode.t.sol index 3d743fcc..8d7756e8 100644 --- a/test/src/abstract/RainDeployDeclarationChecks.perChainCode.t.sol +++ b/test/src/abstract/RainDeployDeclarationChecks.perChainCode.t.sol @@ -32,11 +32,7 @@ contract RainDeployDeclarationChecksPerChainCodeTest is PerChainCodeDeploySuites return declarationWith(new DeployDependency[](0)); } - function declarationWith(DeployDependency[] memory dependencies) - internal - view - returns (DeployDeclaration memory) - { + function declarationWith(DeployDependency[] memory dependencies) internal view returns (DeployDeclaration memory) { DeployDeclaration memory d; LibRainDeployDeclaration.extend(d); LibRainDeployDeclaration.setNetworks(d, perChainCodeNetworks()); diff --git a/test/src/abstract/RainDeployVerifyBase.dependencyClosure.t.sol b/test/src/abstract/RainDeployVerifyBase.dependencyClosure.t.sol index 76e329ab..7a7b3275 100644 --- a/test/src/abstract/RainDeployVerifyBase.dependencyClosure.t.sol +++ b/test/src/abstract/RainDeployVerifyBase.dependencyClosure.t.sol @@ -23,7 +23,8 @@ contract RainDeployVerifyBaseDependencyClosureTest is TransitiveDependencyDeploy assertEq(derived.deployedAddresses[0], suite.storedDeployedAddress); for (uint256 i = 0; i < derived.chainIds.length; i++) { assertEq( - derivedBytecodeHash(derived, derived.chainIds[i]), keccak256(type(MockDependencyReaderCaller).runtimeCode) + derivedBytecodeHash(derived, derived.chainIds[i]), + keccak256(type(MockDependencyReaderCaller).runtimeCode) ); } assertEq(sibling.code.length, 0); diff --git a/test/src/abstract/RainDeployVerifyChain.perChainCode.t.sol b/test/src/abstract/RainDeployVerifyChain.perChainCode.t.sol index 4d251f31..f44e3988 100644 --- a/test/src/abstract/RainDeployVerifyChain.perChainCode.t.sol +++ b/test/src/abstract/RainDeployVerifyChain.perChainCode.t.sol @@ -49,7 +49,8 @@ contract RainDeployVerifyChainPerChainCodeTest is PerChainCodeDeploySuites, Rain override returns (address) { - return isPerChainCode(suite) ? perChainDeployedAddress(suite, chainId) : super.deployedAddress(d, suite, chainId); + return + isPerChainCode(suite) ? perChainDeployedAddress(suite, chainId) : super.deployedAddress(d, suite, chainId); } function expectedBytecodeHash(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) diff --git a/test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol b/test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol index 6cbff012..59750a26 100644 --- a/test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol +++ b/test/src/abstract/RainDeployVerifySnapshotBase.perChainCode.t.sol @@ -52,7 +52,8 @@ contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuite override returns (address) { - return isPerChainCode(suite) ? perChainDeployedAddress(suite, chainId) : super.deployedAddress(d, suite, chainId); + return + isPerChainCode(suite) ? perChainDeployedAddress(suite, chainId) : super.deployedAddress(d, suite, chainId); } function expectedBytecodeHash(DeployDeclaration memory d, DeploySuite memory suite, uint256 chainId) @@ -111,7 +112,9 @@ contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuite LibMockCreate2Mechanism.create2Address( LibMockCreate2Mechanism.decode(perChainSuite()).factory, LibMockCreate2Mechanism.salt(perChainSuite(), chainIds[i]), - abi.encodePacked(type(MockImmutableBeaconBound).creationCode, abi.encode(perChainBeacon(chainIds[i]))) + abi.encodePacked( + type(MockImmutableBeaconBound).creationCode, abi.encode(perChainBeacon(chainIds[i])) + ) ) ); assertEq(derived.bytecodeHashes[i], expected); @@ -147,7 +150,9 @@ contract RainDeployVerifySnapshotBasePerChainCodeTest is PerChainCodeDeploySuite this.setExpectedBytecodeHash(chainIds[b], other); vm.expectRevert( - abi.encodeWithSelector(StoredCodeHashMismatch.selector, PER_CHAIN_CODE_SUITE, other, newCodeHash(chainIds[b])) + abi.encodeWithSelector( + StoredCodeHashMismatch.selector, PER_CHAIN_CODE_SUITE, other, newCodeHash(chainIds[b]) + ) ); this.externalCheckInternallyConsistent(perChainSuite()); } From b9d7d8830ef98bc702fa093f769f9a8ea0ef783f Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 13:15:42 +0000 Subject: [PATCH 16/17] Hold main-era tests to the per-network derivation and fail-closed owner read A short owner() answer is refused SuiteOwnerUnreadable; a Zoltu formula/factory disagreement is refused DeployStepAddressMismatch on the first derived chain; the fork-through-vm case keeps the suite on catalogue networks so derivation resolves them before the bad name is forked. Co-Authored-By: Claude Opus 5.5 --- test/src/abstract/RainDeployBroadcast.t.sol | 17 ++++++++++++++--- test/src/abstract/RainDeployVerifyChain.t.sol | 8 ++++---- .../abstract/RainDeployVerifySnapshotBase.t.sol | 8 +++++--- .../RainDeployVerifySnapshotBaseCandidate.t.sol | 5 +++-- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/test/src/abstract/RainDeployBroadcast.t.sol b/test/src/abstract/RainDeployBroadcast.t.sol index 9a0038aa..b31b54da 100644 --- a/test/src/abstract/RainDeployBroadcast.t.sol +++ b/test/src/abstract/RainDeployBroadcast.t.sol @@ -23,7 +23,11 @@ import {UnanchorableDeploy} from "../../concrete/UnanchorableDeploy.sol"; import {MockDeployable} from "../../concrete/MockDeployable.sol"; import {MockDeployableV2} from "../../concrete/MockDeployableV2.sol"; import {ZoltuDeployOrAdopt} from "../../abstract/ZoltuDeployOrAdopt.sol"; -import {DeployNetworkUndeclared, SuiteSeatsDeployKey} from "../../../src/abstract/RainDeployBroadcast.sol"; +import { + DeployNetworkUndeclared, + SuiteOwnerUnreadable, + SuiteSeatsDeployKey +} from "../../../src/abstract/RainDeployBroadcast.sol"; import {UndeclaredDeployNetworkDeploy} from "../../concrete/UndeclaredDeployNetworkDeploy.sol"; import {ExternalDeployBroadcast} from "../../abstract/ExternalDeployBroadcast.sol"; import {ExampleDeployArbitrumNetworks} from "../../concrete/ExampleDeployArbitrumNetworks.sol"; @@ -717,8 +721,15 @@ contract RainDeployBroadcastTest is ZoltuDeployOrAdopt { expectRawOwnerRefused(abi.encodePacked(uint256(uint160(vm.addr(1))) | (uint256(1) << 160))); } - function testBroadcastOfAnOwnerAnswerShorterThanAWordReachesTheNetworkRefusal() external { - expectRawOwnerReachesTheNetworkRefusal(abi.encodePacked(vm.addr(1))); + function testBroadcastRefusesAnOwnerAnswerShorterThanAWordAsUnreadable() external { + ExampleDeploy deploy = new ExampleDeploy(); + DeploySuite memory suite = rawOwnerSuite(deploy, abi.encodePacked(vm.addr(1))); + vm.expectRevert( + abi.encodeWithSelector( + SuiteOwnerUnreadable.selector, suite.suite, suite.storedDeployedAddress, declaredChainIds(deploy)[0] + ) + ); + deploy.externalBroadcastSuite(suite, new string[](0), 1); } function testBroadcastOfAnOwnerAnswerNamingTheDeployKeyInItsSecondWordReachesTheNetworkRefusal() external { diff --git a/test/src/abstract/RainDeployVerifyChain.t.sol b/test/src/abstract/RainDeployVerifyChain.t.sol index 7a67457f..0ea0b22f 100644 --- a/test/src/abstract/RainDeployVerifyChain.t.sol +++ b/test/src/abstract/RainDeployVerifyChain.t.sol @@ -416,12 +416,12 @@ contract RainDeployVerifyChainTest is ExampleDeploySuites, RainDeployVerifyChain /// The chain group forks through `vm`: a network whose name is neither an alias nor a URL is refused by the /// `createFork` cheatcode itself. function testChainGroupForksThroughTheVm() external { - SupportedNetwork[] memory networks = new SupportedNetwork[](1); - networks[0] = SupportedNetwork({name: "no-such-alias", chainId: 1, explorerUrl: "", defaultRpcUrl: ""}); DeploySuite[] memory suites = new DeploySuite[](1); suites[0] = declaration().released[0]; - suites[0].networks = new string[](1); - suites[0].networks[0] = "no-such-alias"; + // Derivation resolves the suite's own networks before forking, so only the forked roster holds the bad name. + SupportedNetwork[] memory networks = new SupportedNetwork[](2); + networks[0] = SupportedNetwork({name: "no-such-alias", chainId: 1, explorerUrl: "", defaultRpcUrl: ""}); + networks[1] = LibRainDeploy.declaredNetworkConfigs(suites[0].networks)[0]; vm.expectRevert( abi.encodeWithSignature("CheatcodeError(string)", "vm.createFork: invalid rpc url: no-such-alias") diff --git a/test/src/abstract/RainDeployVerifySnapshotBase.t.sol b/test/src/abstract/RainDeployVerifySnapshotBase.t.sol index a7f5c0cf..74d493ef 100644 --- a/test/src/abstract/RainDeployVerifySnapshotBase.t.sol +++ b/test/src/abstract/RainDeployVerifySnapshotBase.t.sol @@ -2,12 +2,12 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {ZoltuDerivationMismatch} from "../../../src/abstract/RainDeployVerifyBase.sol"; import { CandidateSourceMismatch, DeployCandidate, DeployDeclaration, DeployDependency, + DeployStepAddressMismatch, DeploySuite } from "../../../src/abstract/RainDeploySuitesBase.sol"; import { @@ -812,8 +812,9 @@ contract RainDeployVerifySnapshotBaseTest is ExampleDeploySuites, RainDeployVeri vm.expectRevert( abi.encodeWithSelector( - ZoltuDerivationMismatch.selector, + DeployStepAddressMismatch.selector, "config-registry@0_0_1", + LibRainDeploy.declaredNetworkConfigs(suite.networks)[0].chainId, CONFIG_REGISTRY_DEPLOYED_ADDRESS, LibRainDeploy.ZOLTU_FACTORY ) @@ -873,8 +874,9 @@ contract RainDeployVerifySnapshotBaseTest is ExampleDeploySuites, RainDeployVeri vm.expectRevert( abi.encodeWithSelector( - ZoltuDerivationMismatch.selector, + DeployStepAddressMismatch.selector, "second-address", + LibRainDeploy.declaredNetworkConfigs(suites[1].networks)[0].chainId, suites[1].storedDeployedAddress, LibRainDeploy.ZOLTU_FACTORY ) diff --git a/test/src/abstract/RainDeployVerifySnapshotBaseCandidate.t.sol b/test/src/abstract/RainDeployVerifySnapshotBaseCandidate.t.sol index 1d4d7481..2b9882d1 100644 --- a/test/src/abstract/RainDeployVerifySnapshotBaseCandidate.t.sol +++ b/test/src/abstract/RainDeployVerifySnapshotBaseCandidate.t.sol @@ -2,11 +2,11 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd pragma solidity =0.8.25; -import {ZoltuDerivationMismatch} from "../../../src/abstract/RainDeployVerifyBase.sol"; import { DeployCandidate, DeployDependency, DeployDeclaration, + DeployStepAddressMismatch, DeploySuite, RainDeploySuitesBase } from "../../../src/abstract/RainDeploySuitesBase.sol"; @@ -101,8 +101,9 @@ contract RainDeployVerifySnapshotBaseCandidateTest is RainDeployVerifySnapshotBa vm.expectRevert( abi.encodeWithSelector( - ZoltuDerivationMismatch.selector, + DeployStepAddressMismatch.selector, "mock-deployable-candidate", + LibRainDeploy.declaredNetworkConfigs(allSuites(declaration())[0].networks)[0].chainId, LibRainDeploy.zoltuAddress(type(MockDeployable).creationCode), LibRainDeploy.ZOLTU_FACTORY ) From 1ae4dcd0c357748fa3b3eaa8c6abf80cca099c33 Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 30 Nov 2026 13:35:12 +0000 Subject: [PATCH 17/17] Test the seat check refusing a deploy step that leaves no code Co-Authored-By: Claude Opus 5.5 --- .../RainDeployBroadcast.mockMechanism.t.sol | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/src/abstract/RainDeployBroadcast.mockMechanism.t.sol b/test/src/abstract/RainDeployBroadcast.mockMechanism.t.sol index 73315e92..6cd002bc 100644 --- a/test/src/abstract/RainDeployBroadcast.mockMechanism.t.sol +++ b/test/src/abstract/RainDeployBroadcast.mockMechanism.t.sol @@ -4,7 +4,8 @@ pragma solidity =0.8.25; import {Test} from "forge-std-1.17.0/src/Test.sol"; import {Vm} from "forge-std-1.17.0/src/Vm.sol"; -import {SuiteSeatsDeployKey} from "../../../src/abstract/RainDeployBroadcast.sol"; +import {IERC5313} from "@openzeppelin-contracts-5.7.0/interfaces/IERC5313.sol"; +import {SuiteOwnerUnreadable, SuiteSeatsDeployKey} from "../../../src/abstract/RainDeployBroadcast.sol"; import {DeployDependency, DeploySuite, UnrecordedOnNetwork} from "../../../src/abstract/RainDeploySuitesBase.sol"; import {LibRainDeploy} from "../../../src/lib/LibRainDeploy.sol"; import {LibMockNetworkRecord, MockNetworkDeploy} from "../../lib/LibMockNetworkRecord.sol"; @@ -30,6 +31,9 @@ import {UnrecordedMockCreate2Deploy} from "../../concrete/UnrecordedMockCreate2D contract RainDeployBroadcastMockMechanismTest is Test { event MockCreate2Verification(string[] networks, string suite, address[] deployed); + /// PUSH1 0 PUSH1 0 RETURN. + bytes internal constant NO_RUNTIME_CREATION_CODE = hex"60006000f3"; + MockCreate2Deploy internal sDeploy; LocalForkVm internal sForkVm; @@ -217,7 +221,10 @@ contract RainDeployBroadcastMockMechanismTest is Test { } function originOwnedOnSuite(uint256 ownedOn) internal view returns (DeploySuite memory) { - bytes memory creationCode = abi.encodePacked(type(MockChainOriginOwned).creationCode, abi.encode(ownedOn)); + return arbitrumAndPolygonSuite(abi.encodePacked(type(MockChainOriginOwned).creationCode, abi.encode(ownedOn))); + } + + function arbitrumAndPolygonSuite(bytes memory creationCode) internal view returns (DeploySuite memory) { MockNetworkDeploy[] memory networks = new MockNetworkDeploy[](2); networks[0] = MockNetworkDeploy({ chainId: 42161, data: abi.encode(uint256(42161)), deployedAddress: networkAddress(42161, creationCode) @@ -248,6 +255,21 @@ contract RainDeployBroadcastMockMechanismTest is Test { sDeploy.externalCheckSeatsNoDeployKey(suite, arbitrumAndPolygonIds(), deployer); } + /// The codeless address answers `owner()` with a whole word naming someone else, so only its missing code refuses + /// it. + function testBroadcastRefusesADeployStepLeavingNoCodeAsUnreadable() external { + DeploySuite memory suite = arbitrumAndPolygonSuite(NO_RUNTIME_CREATION_CODE); + suite.suite = "no-code@0_0_1"; + address deployed = networkAddress(42161, suite.creationCode); + vm.mockCall(deployed, abi.encodeCall(IERC5313.owner, ()), abi.encode(address(0xB0B))); + bytes memory refusal = + abi.encodeWithSelector(SuiteOwnerUnreadable.selector, suite.suite, deployed, uint256(42161)); + vm.expectRevert(refusal); + sDeploy.externalCheckSeatsNoDeployKey(suite, arbitrumAndPolygonIds(), vm.addr(1)); + vm.expectRevert(refusal); + sDeploy.externalBroadcastSuite(suite, new string[](0), 1); + } + function testSeatCheckLeavesNothingDeployed() external { DeploySuite memory suite = originOwnedOnSuite(1); sDeploy.externalCheckSeatsNoDeployKey(suite, arbitrumAndPolygonIds(), vm.addr(1));