Skip to content
Verified contractExactMIT

BytecodeArtStore

Address0x8a906569c9a409f5bc47920ac3fdabc8e70915e4
Balance

0 ETH

 

Transactions

21

 

Compiler

solc 0.8.24

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,278,171
Creation transaction
0xf8add7a4d0…2043dfebd0

src/europoor/BytecodeArtStore.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';

/// @dev Runtime is exactly STOP || payload: inert, immutable and EIP-170 bounded.
contract ArtDataChunk {
    constructor(bytes memory payload) {
        require(payload.length > 0 && payload.length <= 24575, 'chunk size');
        bytes memory runtime = bytes.concat(hex'00', payload);
        assembly ('memory-safe') { return(add(runtime, 32), mload(runtime)) }
    }
}

/// @notice Onchain store for artwork bytes: the owner appends the files of a fixed manifest, then
/// seals it. After the seal the catalog is immutable and every read is re-hashed against the manifest.
contract BytecodeArtStore is Ownable {
    uint256 public constant MAX_PAYLOAD = 24575;
    bytes32 public immutable manifestSha256;
    bool public isSealed;
    uint256 public totalBytes;
    struct Chunk { address pointer; bytes32 codeHash; }
    struct File { uint256 offset; uint256 length; bytes32 sha256Hash; }
    Chunk[] public chunks;
    File[] public files;
    event ChunkAdded(uint256 indexed index, address pointer, bytes32 runtimeSha256);
    event FileAdded(uint256 indexed index, uint256 offset, uint256 length, bytes32 sha256Hash);
    event Sealed(bytes32 manifestSha256);

    constructor(address publisher, bytes32 manifest) Ownable(publisher) {
        require(block.chainid == 1 || block.chainid == 11155111 || block.chainid == 31337, 'unsupported chain');
        require(manifest != 0, 'manifest required');
        manifestSha256 = manifest;
    }
    modifier unsealed() { require(!isSealed, 'sealed'); _; }
    function chunkCount() external view returns (uint256) { return chunks.length; }
    function fileCount() external view returns (uint256) { return files.length; }

    function appendChunk(bytes memory payload) external onlyOwner unsealed returns (address pointer) {
        require(totalBytes % MAX_PAYLOAD == 0, 'previous chunk short');
        pointer = address(new ArtDataChunk(payload));
        chunks.push(Chunk(pointer, pointer.codehash));
        totalBytes += payload.length;
        emit ChunkAdded(chunks.length - 1, pointer, sha256(pointer.code));
    }
    function addFile(uint256 offset, uint256 length, bytes32 expectedHash)
        external onlyOwner unsealed returns (uint256 id)
    {
        bytes memory data = _read(offset, length);
        require(sha256(data) == expectedHash, 'file hash');
        id = files.length;
        files.push(File(offset, length, expectedHash));
        emit FileAdded(id, offset, length, expectedHash);
    }
    function seal() external onlyOwner unsealed {
        require(files.length > 0, 'empty catalog');
        isSealed = true;
        emit Sealed(manifestSha256);
    }
    function read(uint256 id) external view returns (bytes memory data) {
        require(id < files.length, 'unknown file');
        File memory file = files[id];
        data = _read(file.offset, file.length);
        require(sha256(data) == file.sha256Hash, 'file hash');
    }
    function _read(uint256 offset, uint256 length) private view returns (bytes memory out) {
        require(length > 0 && length <= 65536 && offset <= totalBytes && length <= totalBytes - offset, 'file bounds');
        out = new bytes(length);
        uint256 copied;
        while (copied < length) {
            uint256 at = offset + copied;
            Chunk memory chunk = chunks[at / MAX_PAYLOAD];
            address pointer = chunk.pointer;
            require(pointer.codehash == chunk.codeHash, 'changed bytecode');
            uint256 start = at % MAX_PAYLOAD;
            uint256 take = pointer.code.length - 1 - start;
            if (take > length - copied) take = length - copied;
            require(take > 0, 'truncated chunk');
            assembly ('memory-safe') { extcodecopy(pointer, add(add(out, 32), copied), add(start, 1), take) }
            copied += take;
        }
    }
}

../node_modules/@openzeppelin/contracts/access/Ownable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

../node_modules/@openzeppelin/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts/=../node_modules/@openzeppelin/contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.