Verified contractExactMIT
ScriptRegistry
Address0xbdda9d2e13d35b5cf658e83c8d657837fa455bb3
- Balance
0 ETH
- Transactions
11
- Compiler
solc 0.8.38
- Same code
Only this contract
Details
- Compiler
- solc 0.8.38+commit.1835d247
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- osaka
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,361,939
- Creation transaction
- 0x55595d4301…ecc3edf8ca
ScriptRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.38;
/// @title Write-once script registry with an IDependencyRegistryV0 read facade.
/// @notice Stores the gzip bytes of an unmodified upstream library file as a
/// fixed sequence of SSTORE2 pages. The ABX resolver reads dependencies through
/// the two Art Blocks `IDependencyRegistryV0` views used by its serving lane:
/// `getDependencyDetails(bytes32)` and `getDependencyScript(bytes32, index)`,
/// where the concatenated script chunks form one base64(gzip(script)) stream.
/// Pages are stored raw (the gzip bytes themselves) and base64-encoded per read,
/// so the verifiable on-chain artifact is exactly `gzip(upstream file)`; a page
/// may alternatively be stored already encoded for the pre-encoded comparison.
/// Once frozen, a dependency can never change.
contract ScriptRegistry {
struct Dependency {
string licenseType;
string repository;
string website;
bytes32 gzipSha256; // sha256 of the concatenated raw gzip bytes
address[] pages;
bool preEncoded; // pages hold base64 text instead of gzip bytes
bool frozen;
}
address public owner;
address public pendingOwner;
mapping(bytes32 => Dependency) private deps;
bytes32[] public refs;
/// Raw page size is a multiple of 3 so per-page base64 strings concatenate
/// into one valid stream without mid-stream padding. Pre-encoded pages hold
/// a multiple of 4 characters for the same reason.
uint256 public constant RAW_PAGE = 24573;
uint256 public constant ENCODED_PAGE = 24572;
event PageStored(
bytes32 indexed ref,
uint256 index,
address page,
uint256 size
);
event Frozen(bytes32 indexed ref, uint256 pages, bytes32 gzipSha256);
error NotOwner();
error AlreadyFrozen();
error NotFrozen();
error BadPage();
error ModeMismatch();
error NotPendingOwner();
event OwnershipTransferStarted(address indexed from, address indexed to);
event OwnershipTransferred(address indexed from, address indexed to);
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
if (msg.sender != owner) revert NotOwner();
_;
}
// ---- ownership (two-step, so the owner can move to a multisig) ---------
function transferOwnership(address to) external onlyOwner {
pendingOwner = to;
emit OwnershipTransferStarted(owner, to);
}
function acceptOwnership() external {
if (msg.sender != pendingOwner) revert NotPendingOwner();
emit OwnershipTransferred(owner, msg.sender);
owner = msg.sender;
pendingOwner = address(0);
}
// ---- write once --------------------------------------------------------
function addPage(
bytes32 ref,
bytes calldata data,
bool preEncoded
) external onlyOwner returns (address page) {
Dependency storage d = deps[ref];
if (d.frozen) revert AlreadyFrozen();
if (d.pages.length == 0) {
d.preEncoded = preEncoded;
refs.push(ref);
} else if (d.preEncoded != preEncoded) {
revert ModeMismatch();
}
uint256 limit = preEncoded ? ENCODED_PAGE : RAW_PAGE;
if (data.length == 0 || data.length > limit) revert BadPage();
page = _sstore2(data);
d.pages.push(page);
emit PageStored(ref, d.pages.length - 1, page, data.length);
}
function freeze(
bytes32 ref,
string calldata licenseType,
string calldata repository,
string calldata website,
bytes32 gzipSha256
) external onlyOwner {
Dependency storage d = deps[ref];
if (d.frozen) revert AlreadyFrozen();
if (d.pages.length == 0) revert BadPage();
d.licenseType = licenseType;
d.repository = repository;
d.website = website;
d.gzipSha256 = gzipSha256;
d.frozen = true;
emit Frozen(ref, d.pages.length, gzipSha256);
}
// ---- IDependencyRegistryV0 read facade ---------------------------------
/// @dev `preferredCDN` is intentionally empty: the resolver must inline the
/// on-chain bytes and never fall back to an external script URL.
function getDependencyDetails(
bytes32 ref
)
external
view
returns (
string memory nameAndVersion,
string memory licenseType,
string memory preferredCDN,
uint24 additionalCDNCount,
string memory preferredRepository,
uint24 additionalRepositoryCount,
string memory dependencyWebsite,
bool availableOnChain,
uint24 scriptCount
)
{
Dependency storage d = deps[ref];
nameAndVersion = _tagString(ref);
if (!d.frozen) return (nameAndVersion, "", "", 0, "", 0, "", false, 0);
return (
nameAndVersion,
d.licenseType,
"",
0,
d.repository,
0,
d.website,
true,
uint24(d.pages.length)
);
}
function getDependencyScript(
bytes32 ref,
uint256 index
) external view returns (string memory) {
Dependency storage d = deps[ref];
if (!d.frozen) revert NotFrozen();
bytes memory page = _read(d.pages[index]);
return d.preEncoded ? string(page) : _base64(page);
}
function getDependencyScriptCount(
bytes32 ref
) external view returns (uint256) {
return deps[ref].pages.length;
}
// ---- raw lane for verifiers and other consumers ------------------------
function pageAddress(
bytes32 ref,
uint256 index
) external view returns (address) {
return deps[ref].pages[index];
}
function pageBytes(
bytes32 ref,
uint256 index
) external view returns (bytes memory) {
return _read(deps[ref].pages[index]);
}
function dependency(
bytes32 ref
)
external
view
returns (
bool frozen,
bool preEncoded,
uint256 pages,
bytes32 gzipSha256
)
{
Dependency storage d = deps[ref];
return (d.frozen, d.preEncoded, d.pages.length, d.gzipSha256);
}
function refCount() external view returns (uint256) {
return refs.length;
}
// ---- internals ---------------------------------------------------------
/// SSTORE2: deploy `0x00 || data` as runtime code (the STOP prefix keeps the
/// data contract from ever executing).
function _sstore2(bytes calldata data) internal returns (address page) {
bytes memory init = abi.encodePacked(
hex"61",
uint16(data.length + 1),
hex"80600a3d393df300",
data
);
assembly ("memory-safe") {
page := create(0, add(init, 0x20), mload(init))
}
if (page == address(0)) revert BadPage();
}
function _read(address page) internal view returns (bytes memory data) {
assembly ("memory-safe") {
let size := sub(extcodesize(page), 1)
data := mload(0x40)
mstore(0x40, add(data, and(add(add(size, 0x20), 0x1f), not(0x1f))))
mstore(data, size)
extcodecopy(page, add(data, 0x20), 1, size)
}
}
function _tagString(bytes32 ref) internal pure returns (string memory s) {
uint256 n;
while (n < 32 && ref[n] != 0) n++;
if (n == 0) return "";
s = new string(n);
assembly ("memory-safe") {
mstore(add(s, 0x20), ref)
}
}
/// Standard base64 (RFC 4648, padded). Loop structure after Solady's
/// Base64.encode (MIT, Vectorized): the lookup table lives in scratch
/// space and each 3-byte group is written as one word.
function _base64(
bytes memory data
) internal pure returns (string memory result) {
assembly ("memory-safe") {
let dataLength := mload(data)
if dataLength {
let encodedLength := mul(4, div(add(dataLength, 2), 3))
result := mload(0x40)
// Table at 0x1f..0x5e so that mload(idx) places table[idx] in
// the low byte of the loaded word.
mstore(0x1f, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef")
mstore(0x3f, "ghijklmnopqrstuvwxyz0123456789+/")
let ptr := add(result, 0x20)
let end := add(ptr, encodedLength)
// Zero the bytes past the input so a short final group reads
// zero bits; restore the word afterwards.
let dataEnd := add(add(0x20, data), dataLength)
let dataEndValue := mload(dataEnd)
mstore(dataEnd, 0x00)
for {} 1 {} {
data := add(data, 3)
let input := mload(data)
mstore8(0, mload(and(shr(18, input), 0x3F)))
mstore8(1, mload(and(shr(12, input), 0x3F)))
mstore8(2, mload(and(shr(6, input), 0x3F)))
mstore8(3, mload(and(input, 0x3F)))
mstore(ptr, mload(0x00))
ptr := add(ptr, 4)
if iszero(lt(ptr, end)) {
break
}
}
mstore(dataEnd, dataEndValue)
mstore(result, encodedLength)
// Padding: `o = [0, 2, 1][dataLength % 3]` (div by zero is 0).
let o := div(2, mod(dataLength, 3))
mstore(sub(end, o), shl(240, 0x3d3d))
// Finalize the allocation, zero the word after the string
// (which also clears any padding written past `end`) and
// restore the zero slot.
mstore(0x40, add(end, 0x20))
mstore(end, 0)
mstore(0x60, 0)
}
}
}
}
Compiler settingsShow
{
"viaIR": true,
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "osaka"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.