Skip to content
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cbor_metadata = false
ffi = true

fs_permissions = [
{ access = "read", path = "foundry.toml" },
{ access = "read-write", path = "./src/generated" },
{ access = "read", path = "./out" },
{ access = "read-write", path = "./crates/float/abi" },
Expand Down
117 changes: 116 additions & 1 deletion script/BuildPointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,33 @@ pragma solidity =0.8.25;
import {Script} from "forge-std-1.16.1/src/Script.sol";
import {LibCodeGen} from "rain-sol-codegen-0.1.0/src/lib/LibCodeGen.sol";
import {LibFs} from "rain-sol-codegen-0.1.0/src/lib/LibFs.sol";
import {LibDataContract} from "rain-datacontract-0.1.0/src/lib/LibDataContract.sol";
import {LibRainDeploy} from "rain-deploy-0.1.3/src/lib/LibRainDeploy.sol";
import {LibLogTable} from "../src/lib/table/LibLogTable.sol";
import {LibDecimalFloatDeploy} from "../src/lib/deploy/LibDecimalFloatDeploy.sol";
import {DecimalFloat} from "../src/concrete/DecimalFloat.sol";

contract BuildPointers is Script {
function run() external {
function addressConstantString(string memory comment, string memory name, address addr)
internal
pure
returns (string memory)
{
return string.concat("\n", comment, "\n", "address constant ", name, " = address(", vm.toString(addr), ");\n");
}

function bytes32ConstantString(string memory comment, string memory name, bytes32 value)
internal
pure
returns (string memory)
{
return string.concat("\n", comment, "\n", "bytes32 constant ", name, " = ", vm.toString(value), ";\n");
}

/// @notice The log/antilog lookup table data consumed by
/// `LibDecimalFloatDeploy.combinedTables()`. This is source data, not a
/// deployment record, so it is not part of the per-release snapshot.
function buildLogTablesData() internal {
LibFs.buildFileForContract(
vm,
address(0),
Expand Down Expand Up @@ -44,4 +67,96 @@ contract BuildPointers is Script {
)
);
}

/// @notice The deployment record for this release: the Zoltu-deterministic
/// address and runtime codehash of BOTH deployables — the log-tables data
/// contract and the `DecimalFloat` contract. Both addresses are a pure
/// function of their creation code, so this is computed offline by deploying
/// through a locally etched Zoltu factory. Frozen per release by
/// `freezeSnapshot()`.
function buildDeployPointers() internal {
// The log tables must exist at their deterministic address before
// DecimalFloat is deployed: its constructor calls
// `checkLogTablesDeployed()`, which reads the codehash there.
bytes memory logTablesCreationCode =
LibDataContract.contractCreationCode(LibDecimalFloatDeploy.combinedTables());
address logTables = LibRainDeploy.deployZoltu(logTablesCreationCode);

address decimalFloat = LibRainDeploy.deployZoltu(type(DecimalFloat).creationCode);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

LibFs.buildFileForContract(
vm,
address(0),
"DecimalFloatDeploy",
string.concat(
addressConstantString(
"/// @dev Address of the log tables data contract deployed via Zoltu's\n"
"/// deterministic deployment proxy. Identical across all EVM networks.",
"LOG_TABLES_DEPLOYED_ADDRESS",
logTables
),
bytes32ConstantString(
"/// @dev Runtime codehash of the deployed log tables data contract.",
"LOG_TABLES_DEPLOYED_CODEHASH",
logTables.codehash
),
addressConstantString(
"/// @dev Address of the DecimalFloat contract deployed via Zoltu's\n"
"/// deterministic deployment proxy. Identical across all EVM networks.",
"DECIMAL_FLOAT_DEPLOYED_ADDRESS",
decimalFloat
),
bytes32ConstantString(
"/// @dev Runtime codehash of the deployed DecimalFloat contract.",
"DECIMAL_FLOAT_DEPLOYED_CODEHASH",
decimalFloat.codehash
)
)
);
}

/// @notice The canonical release tag: `foundry.toml` `[package].version` with
/// dots converted to underscores (`0.1.7` -> `0_1_7`) for the Solidity dir
/// form — the single source of truth for the frozen-snapshot dir name.
function deployTag() internal view returns (string memory) {
string memory version = vm.parseTomlString(vm.readFile("foundry.toml"), ".package.version");
bytes memory b = bytes(version);
bytes memory out = new bytes(b.length);
for (uint256 i = 0; i < b.length; i++) {
out[i] = b[i] == "." ? bytes1("_") : b[i];
}
return string(out);
}

/// @notice Freeze the just-generated deploy pointers into a per-release
/// snapshot dir `src/generated/<tag>/` so each published release keeps its
/// own immutable deployment record. Only the CURRENT `deployTag()` dir is
/// ever written — older tags are never touched. An existing `<tag>/`
/// snapshot is treated as immutable: rewriting it with IDENTICAL content is
/// a harmless no-op, but a DIFFERENT payload reverts. That only happens when
/// the deployment changed without a `[package].version` bump — the change
/// must bump the version so a NEW `<tag>/` dir is written beside the frozen
/// ones, rather than corrupting the history consumers pin against.
function freezeSnapshot() internal {
string memory tag = deployTag();
vm.createDir(string.concat("src/generated/", tag), true);
string memory frozenPath = string.concat("src/generated/", tag, "/DecimalFloatDeploy.pointers.sol");
string memory content = vm.readFile("src/generated/DecimalFloatDeploy.pointers.sol");
if (vm.exists(frozenPath)) {
require(
keccak256(bytes(vm.readFile(frozenPath))) == keccak256(bytes(content)),
"BuildPointers: frozen snapshot would change; bump [package].version for a new release"
);
}
vm.writeFile(frozenPath, content);
}

function run() external {
LibRainDeploy.etchZoltuFactory(vm);

buildLogTablesData();
buildDeployPointers();

freezeSnapshot();
}
}
51 changes: 0 additions & 51 deletions script/check-published-deploy-constants.sh

This file was deleted.

27 changes: 27 additions & 0 deletions src/generated/0_1_1/DecimalFloatDeploy.pointers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

// THIS FILE IS AUTOGENERATED BY ./script/BuildPointers.sol

// This file is committed to the repository because there is a circular
// dependency between the contract and its pointers file. The contract
// needs the pointers file to exist so that it can compile, and the pointers
// file needs the contract to exist so that it can be compiled.

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0x0000000000000000000000000000000000000000000000000000000000000000);

/// @dev Address of the log tables data contract deployed via Zoltu's
/// deterministic deployment proxy. Identical across all EVM networks.
address constant LOG_TABLES_DEPLOYED_ADDRESS = address(0xc51a14251b0dcF0ae24A96b7153991378938f5F5);

/// @dev Runtime codehash of the deployed log tables data contract.
bytes32 constant LOG_TABLES_DEPLOYED_CODEHASH = 0x2573004ac3a9ee7fc8d73654d76386f1b6b99e34cdf86a689c4691e47143420f;

/// @dev Address of the DecimalFloat contract deployed via Zoltu's
/// deterministic deployment proxy. Identical across all EVM networks.
address constant DECIMAL_FLOAT_DEPLOYED_ADDRESS = address(0xBee0eEFaffD046c9602109eB30A858Be301CC926);

/// @dev Runtime codehash of the deployed DecimalFloat contract.
bytes32 constant DECIMAL_FLOAT_DEPLOYED_CODEHASH = 0x7a93d0311f7782b44157ba40e94ec936085ebe001c7893bdd74911c8351d3def;
27 changes: 27 additions & 0 deletions src/generated/0_1_7/DecimalFloatDeploy.pointers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

// THIS FILE IS AUTOGENERATED BY ./script/BuildPointers.sol

// This file is committed to the repository because there is a circular
// dependency between the contract and its pointers file. The contract
// needs the pointers file to exist so that it can compile, and the pointers
// file needs the contract to exist so that it can be compiled.

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0x0000000000000000000000000000000000000000000000000000000000000000);

/// @dev Address of the log tables data contract deployed via Zoltu's
/// deterministic deployment proxy. Identical across all EVM networks.
address constant LOG_TABLES_DEPLOYED_ADDRESS = address(0xc51a14251b0dcF0ae24A96b7153991378938f5F5);

/// @dev Runtime codehash of the deployed log tables data contract.
bytes32 constant LOG_TABLES_DEPLOYED_CODEHASH = 0x2573004ac3a9ee7fc8d73654d76386f1b6b99e34cdf86a689c4691e47143420f;

/// @dev Address of the DecimalFloat contract deployed via Zoltu's
/// deterministic deployment proxy. Identical across all EVM networks.
address constant DECIMAL_FLOAT_DEPLOYED_ADDRESS = address(0x799632d282178e770C7465cad54aDA1021A913D6);

/// @dev Runtime codehash of the deployed DecimalFloat contract.
bytes32 constant DECIMAL_FLOAT_DEPLOYED_CODEHASH = 0xdc468883c345d41c0abd98ef2fd933c370bd1682522d37e6f6b729793301f55e;
27 changes: 27 additions & 0 deletions src/generated/DecimalFloatDeploy.pointers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

// THIS FILE IS AUTOGENERATED BY ./script/BuildPointers.sol

// This file is committed to the repository because there is a circular
// dependency between the contract and its pointers file. The contract
// needs the pointers file to exist so that it can compile, and the pointers
// file needs the contract to exist so that it can be compiled.

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0x0000000000000000000000000000000000000000000000000000000000000000);

/// @dev Address of the log tables data contract deployed via Zoltu's
/// deterministic deployment proxy. Identical across all EVM networks.
address constant LOG_TABLES_DEPLOYED_ADDRESS = address(0xc51a14251b0dcF0ae24A96b7153991378938f5F5);

/// @dev Runtime codehash of the deployed log tables data contract.
bytes32 constant LOG_TABLES_DEPLOYED_CODEHASH = 0x2573004ac3a9ee7fc8d73654d76386f1b6b99e34cdf86a689c4691e47143420f;

/// @dev Address of the DecimalFloat contract deployed via Zoltu's
/// deterministic deployment proxy. Identical across all EVM networks.
address constant DECIMAL_FLOAT_DEPLOYED_ADDRESS = address(0x799632d282178e770C7465cad54aDA1021A913D6);

/// @dev Runtime codehash of the deployed DecimalFloat contract.
bytes32 constant DECIMAL_FLOAT_DEPLOYED_CODEHASH = 0xdc468883c345d41c0abd98ef2fd933c370bd1682522d37e6f6b729793301f55e;
46 changes: 19 additions & 27 deletions src/lib/deploy/LibDecimalFloatDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,42 @@ import {
ANTI_LOG_TABLES,
ANTI_LOG_TABLES_SMALL
} from "../../generated/LogTables.pointers.sol";
import {
LOG_TABLES_DEPLOYED_ADDRESS,
LOG_TABLES_DEPLOYED_CODEHASH,
DECIMAL_FLOAT_DEPLOYED_ADDRESS,
DECIMAL_FLOAT_DEPLOYED_CODEHASH
} from "../../generated/DecimalFloatDeploy.pointers.sol";
import {LOG_TABLE_DISAMBIGUATOR} from "../table/LibLogTable.sol";
import {LogTablesNotDeployed} from "../../error/ErrDecimalFloat.sol";

/// @dev The deployment record for each release lives in its own frozen snapshot
/// under `src/generated/<tag>/DecimalFloatDeploy.pointers.sol` (tag =
/// `[package].version` with dots as underscores), written by
/// `script/BuildPointers.sol`. The constants below alias the CURRENT release's
/// generated record; a consumer that needs an older release's addresses reads
/// that release's snapshot. Both deployables are placed by Zoltu's deterministic
/// proxy, so every address is a pure function of its creation code and the whole
/// record is reproducible offline — `LibDecimalFloatDeployTaggedConstantsTest`
/// regenerates it and asserts it matches, with no network and no skips.
library LibDecimalFloatDeploy {
/// @dev Address of the log tables deployed via Zoltu's deterministic
/// deployment proxy. This address is the same across all EVM-compatible
/// networks.
address constant ZOLTU_DEPLOYED_LOG_TABLES_ADDRESS = address(0xc51a14251b0dcF0ae24A96b7153991378938f5F5);
address constant ZOLTU_DEPLOYED_LOG_TABLES_ADDRESS = LOG_TABLES_DEPLOYED_ADDRESS;

/// @dev The expected codehash of the log tables deployed via Zoltu's
/// deterministic deployment proxy.
bytes32 constant LOG_TABLES_DATA_CONTRACT_HASH = 0x2573004ac3a9ee7fc8d73654d76386f1b6b99e34cdf86a689c4691e47143420f;
bytes32 constant LOG_TABLES_DATA_CONTRACT_HASH = LOG_TABLES_DEPLOYED_CODEHASH;

/// @dev Address of the DecimalFloat contract deployed via Zoltu's
/// deterministic deployment proxy.
/// This address is the same across all EVM-compatible networks.
address constant ZOLTU_DEPLOYED_DECIMAL_FLOAT_ADDRESS = address(0x799632d282178e770C7465cad54aDA1021A913D6);
address constant ZOLTU_DEPLOYED_DECIMAL_FLOAT_ADDRESS = DECIMAL_FLOAT_DEPLOYED_ADDRESS;

/// @dev The expected codehash of the DecimalFloat contract deployed via
/// Zoltu's deterministic deployment proxy.
bytes32 constant DECIMAL_FLOAT_CONTRACT_HASH = 0xdc468883c345d41c0abd98ef2fd933c370bd1682522d37e6f6b729793301f55e;

/// @dev Deploy constants pinned to each version published to the soldeer
/// registry. These are frozen literals — not aliases of the "current"
/// constants above — so each keeps referencing its own release's deployment
/// after the current constants advance to a newer version.
/// `script/check-published-deploy-constants.sh` (run by
/// `LibDecimalFloatDeployTaggedConstantsTest`) queries the registry and
/// fails if any published version is missing its suite, so publishing a new
/// tag forces pinning that tag's deploy constants here.

/// @dev Log tables address at the published `0.1.1` soldeer tag.
address constant ZOLTU_DEPLOYED_LOG_TABLES_ADDRESS_0_1_1 = address(0xc51a14251b0dcF0ae24A96b7153991378938f5F5);

/// @dev Log tables codehash at the published `0.1.1` soldeer tag.
bytes32 constant LOG_TABLES_DATA_CONTRACT_HASH_0_1_1 =
0x2573004ac3a9ee7fc8d73654d76386f1b6b99e34cdf86a689c4691e47143420f;

/// @dev DecimalFloat address at the published `0.1.1` soldeer tag.
address constant ZOLTU_DEPLOYED_DECIMAL_FLOAT_ADDRESS_0_1_1 = address(0xBee0eEFaffD046c9602109eB30A858Be301CC926);

/// @dev DecimalFloat codehash at the published `0.1.1` soldeer tag.
bytes32 constant DECIMAL_FLOAT_CONTRACT_HASH_0_1_1 =
0x7a93d0311f7782b44157ba40e94ec936085ebe001c7893bdd74911c8351d3def;
bytes32 constant DECIMAL_FLOAT_CONTRACT_HASH = DECIMAL_FLOAT_DEPLOYED_CODEHASH;

/// Combines all log and anti-log tables into a single bytes array for
/// deployment. These are using packed encoding to minimize size and remove
Expand Down
Loading
Loading