Skip to content
Verified contractPartialMIT

ScriptStore

Address0x9e76a1108f693ba5e4549a3693a93cd6838ea0be
Balance

0 ETH

 

Transactions

229

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 10 runs
EVM version
paris
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,212,662
Creation transaction
0x571bb2a220…e06f64d9d7

src/ScriptStore.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

// a file store, the way the script track keeps a work: every file is written as
// the code of its own small contract (SSTORE2 style), in chunks under the 24 KB
// limit, and read back with extcodecopy. a file is named, so a page can be built
// from the chain by asking for each file by name.
contract ScriptStore {
    struct File { address[] chunks; uint32 size; bool brotli; }
    mapping(bytes32 => File) private files;
    string[] public names;
    address public immutable owner;
    bool public isSealed;

    constructor() { owner = msg.sender; }

    function addChunk(string calldata name, bytes calldata data, bool brotli) external {
        require(msg.sender == owner && !isSealed, "no");
        bytes32 k = keccak256(bytes(name));
        File storage f = files[k];
        if (f.chunks.length == 0) { names.push(name); f.brotli = brotli; }
        // the chunk becomes the runtime code of a new contract: 0x00 + data
        bytes memory code = abi.encodePacked(hex"00", data);
        bytes memory init = abi.encodePacked(
            hex"63", uint32(code.length), hex"80600E6000396000F3", code
        );
        address a;
        assembly { a := create(0, add(init, 32), mload(init)) }
        require(a != address(0), "create");
        f.chunks.push(a);
        f.size += uint32(data.length);
    }

    function seal() external { require(msg.sender == owner, "no"); isSealed = true; }
    // a file's chunk contracts and size, for a contract that builds a page from them in place
    function meta(string calldata name) external view returns (address[] memory chunks, uint32 size, bool brotli) {
        File storage f = files[keccak256(bytes(name))];
        return (f.chunks, f.size, f.brotli);
    }
    function count() external view returns (uint256) { return names.length; }

    function read(string calldata name) external view returns (bytes memory out, bool brotli) {
        File storage f = files[keccak256(bytes(name))];
        out = new bytes(f.size);
        uint256 p;
        for (uint256 i = 0; i < f.chunks.length; i++) {
            address a = f.chunks[i];
            uint256 n = a.code.length - 1;
            assembly { extcodecopy(a, add(add(out, 32), p), 1, n) }
            p += n;
        }
        brotli = f.brotli;
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": false,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 10,
    "enabled": true
  },
  "evmVersion": "paris",
  "remappings": [
    "@openzeppelin/=../../001_kaoforms/contracts/lib/openzeppelin-contracts/",
    "forge-std/=../../001_kaoforms/contracts/lib/forge-std/src/",
    "openzeppelin-contracts/=../../001_kaoforms/contracts/lib/openzeppelin-contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.