Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e22edfd
Make deployStepData and deployedAddress virtual for per-network deplo…
thedavidmeister Nov 30, 2026
7266557
Test per-network deploy step data overrides in one broadcast run
thedavidmeister Nov 30, 2026
b9257ff
Format per-network deploy step data test
thedavidmeister Nov 30, 2026
88b41a2
Refuse the deploy-key seat check when the deployed address has no cod…
thedavidmeister Nov 30, 2026
a41ab21
Seat check deploys each network's deploy step data through a local tw…
thedavidmeister Nov 30, 2026
b13cd1d
Derive each suite's code per chain through its deploy step data
thedavidmeister Nov 30, 2026
e050d9f
Compare each chain's code against that chain's expected code hash
thedavidmeister Nov 30, 2026
4bf6301
Give the mock mechanisms a local twin of their deploy step
thedavidmeister Nov 30, 2026
64c4c8a
Check each chain's derived code hash where tests read the derivation
thedavidmeister Nov 30, 2026
5124971
Per-chain code test harness and snapshot-base tests (WIP, needs src c…
thedavidmeister Nov 30, 2026
f45f0fb
Split deployStepDataLocally past stack too deep; derive only recorded…
thedavidmeister Nov 30, 2026
2b45c03
Split deployToConfigs per network past stack too deep
thedavidmeister Nov 30, 2026
3664c9d
Finish per-chain code snapshot-base tests against recorded-chain deri…
thedavidmeister Nov 30, 2026
cb4b9cc
Test per-chain code on the chain, dependency and broadcast paths, and…
thedavidmeister Nov 30, 2026
95b8840
Format per-chain code tests
thedavidmeister Nov 30, 2026
b9d7d88
Hold main-era tests to the per-network derivation and fail-closed own…
thedavidmeister Nov 30, 2026
1ae4dcd
Test the seat check refusing a deploy step that leaves no code
thedavidmeister Nov 30, 2026
dba5010
Merge origin/main into 2026-11-30-per-network-deploy-step-data
thedavidmeister Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions src/abstract/RainDeployBroadcast.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -218,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],
suite.storedBytecodeHash
);
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.
Expand Down Expand Up @@ -303,7 +318,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
Expand All @@ -322,16 +338,20 @@ 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;
// 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);
}
}
Expand Down
24 changes: 23 additions & 1 deletion src/abstract/RainDeployDeclarationChecks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand Down
87 changes: 87 additions & 0 deletions src/abstract/RainDeploySuitesBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -174,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
Expand Down Expand Up @@ -317,6 +325,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;
Expand Down Expand Up @@ -463,6 +474,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);
Expand All @@ -476,9 +488,39 @@ 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
virtual
returns (bytes memory)
{
return mechanismOf(d, suite).deployStepData(d, suite, chainId);
Expand All @@ -499,6 +541,51 @@ 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);
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);
}

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(
DeployDeclaration memory d,
DeploySuiteIndex memory index,
Expand Down
78 changes: 53 additions & 25 deletions src/abstract/RainDeployVerifyBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,80 @@ 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[] memory recorded,) = recordedAddresses(d, suite);
bool anyDerived = false;
for (uint256 i = 0; i < chainIds.length; i++) {
// Mechanisms refuse to address a network they record nothing on.
if (!recorded[i]) {
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
Expand Down
14 changes: 7 additions & 7 deletions src/abstract/RainDeployVerifyChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading