Skip to content

Commit

Permalink
ctb: cleanup L2 genesis comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tynes committed Apr 23, 2024
1 parent 07ac0d5 commit 1d9bc3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
8 changes: 8 additions & 0 deletions packages/contracts-bedrock/scripts/ForgeArtifacts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ library ForgeArtifacts {
slot_ = abi.decode(rawSlot, (StorageSlot));
}

/// @notice Returns whether or not a contract is initialized.
/// Needs the name to get the storage layout.
function isInitialized(string memory _name, address _address) internal returns (bool initialized_) {
StorageSlot memory slot = ForgeArtifacts.getInitializedSlot(_name);
bytes32 slotVal = vm.load(_address, bytes32(vm.parseUint(slot.slot)));
initialized_ = uint8((uint256(slotVal) >> (slot.offset * 8)) & 0xFF) != 0;
}

/// @notice Returns the function ABIs of all L1 contracts.
function getContractFunctionAbis(
string memory path,
Expand Down
23 changes: 3 additions & 20 deletions packages/contracts-bedrock/test/Predeploys.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity 0.8.15;

import { CommonTest } from "test/setup/CommonTest.sol";
import { ForgeArtifacts } from "scripts/ForgeArtifacts.sol";
import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol";
import { console2 as console } from "forge-std/console2.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";

/// @title PredeploysTest
Expand Down Expand Up @@ -76,7 +76,6 @@ contract PredeploysTest is CommonTest {
bytes memory proxyCode = vm.getDeployedCode("Proxy.sol:Proxy");

for (uint256 i = 0; i < count; i++) {
console.log("asserting predeploy %d", i);
address addr = address(prefix | uint160(i));
bytes memory code = addr.code;
assertTrue(code.length > 0);
Expand All @@ -85,7 +84,6 @@ contract PredeploysTest is CommonTest {

if (_isOmitted(addr)) {
assertEq(implAddr.code.length, 0, "must have no code");
console.log("predeploy %d is intentionally not in genesis", i);
continue;
}
bool isPredeploy = _isPredeploy(addr);
Expand All @@ -100,22 +98,17 @@ contract PredeploysTest is CommonTest {
string memory cname = Predeploys.getName(addr);
assertNotEq(cname, "", "must have a name");

console.log("finding supposed code");
bytes memory supposedCode = vm.getDeployedCode(string.concat(cname, ".sol:", cname));
assertNotEq(supposedCode.length, 0, "must have supposed code");

if (proxied == false) {
// can't check bytecode if it's modified with immutables in genesis.
if (!_usesImmutables(addr)) {
// can't check bytecode if it's modified with immutables in genesis.
assertEq(code, supposedCode, "non-proxy contract should be deployed in-place");
}
console.log("predeploy %d is not a proxy", i);
// TODO: should we still test the "initialized" slot?
continue;
}

console.log("checking proxy properties of active predeploy");

// The code is a proxy
assertEq(code, proxyCode);

Expand All @@ -131,17 +124,7 @@ contract PredeploysTest is CommonTest {
}

if (_isInitializable(addr)) {
console.log("loading initialized slot of %s", cname);
uint8 initializedSlot = l2Genesis.loadInitializedSlot(cname);
bytes32 implInitialized = vm.load(implAddr, bytes32(uint256(initializedSlot)));
bytes32 proxyInitialized = vm.load(addr, bytes32(uint256(initializedSlot)));
console.log("loaded initialized slot of %s: slot=%s, impl=%s, proxy=%s", cname, initializedSlot);
console.log("slot values: impl=%s, proxy=%s", uint256(implInitialized), uint256(proxyInitialized));
// TODO: should we be asserting a global initialized value as constant? Or can they differ?
// Storage packing causes some edge cases in this assertion
// assertNotEq(bytes32(0), implInitialized, "implementation must be initialized, even
// though behind a proxy");
// assertNotEq(bytes32(0), proxyInitialized , "proxy must be initialized");
assertEq(l2Genesis.loadInitializedSlot(cname), uint8(1));
}
}
}
Expand Down

0 comments on commit 1d9bc3c

Please sign in to comment.