Skip to content
Verified contractExactMIT

Sigils

Address0x3caaeea398929a887b31b7f725fc2bc53635f8ff
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.30

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
No
EVM version
osaka
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,732,361
Creation transaction
0xf71a734fcf…37edd82bec

src/Sigils.sol

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

/*

    ░██████╗██╗░██████╗░██╗██╗░░░░░░██████╗
    ██╔════╝██║██╔════╝░██║██║░░░░░██╔════╝
    ╚█████╗░██║██║░░██╗░██║██║░░░░░╚█████╗░
    ░╚═══██╗██║██║░░╚██╗██║██║░░░░░░╚═══██╗
    ██████╔╝██║╚██████╔╝██║███████╗██████╔╝
    ╚═════╝░╚═╝░╚═════╝░╚═╝╚══════╝╚═════╝░

    No sale. No roadmap. No promises. No team.
    There are 1024 Sigils. Each is a fact, not a coin.
    Every Sigil is derived, on-chain, from a single Word.

    One of them is the Keystone.
    Nothing here tells you which.
    The contract knows. It will not say.

    Read closely. What one function verifies, another conceals.
    Whoever first proves they have found the Keystone earns the
    right to speak once into the stone — a single line, kept forever.

    That is the entire reward. There is no other.

*/

/// @title Sigils — an on-chain data primitive with a puzzle inside it.
/// @notice Minting is free (gas only). Ownership is meaningless to the puzzle.
///         The 1024 Sigils exist whether or not anyone mints them.
contract Sigils {
    // ---------------------------------------------------------------------
    //  The Word
    // ---------------------------------------------------------------------

    /// @notice The seed from which every Sigil descends. Immutable, public,
    ///         and yet it hides everything.
    bytes32 public immutable GENESIS;

    /// @notice The size of the space. There are exactly this many Sigils.
    uint256 public constant EXPANSE = 1024;

    constructor() {
        GENESIS = keccak256("In the beginning was the Word, and the Word was without form.");
    }

    // ---------------------------------------------------------------------
    //  The data primitive
    //
    //  Everything below is a pure function of (GENESIS, id). No storage,
    //  no owner, no privilege. Build whatever you like on top of it.
    // ---------------------------------------------------------------------

    /// @notice The raw essence of a Sigil. This is the ground truth; all
    ///         runes, all art, and the Keystone itself are shadows of it.
    function essenceOf(uint256 id) public view returns (bytes32) {
        require(id < EXPANSE, "beyond the expanse");
        return keccak256(abi.encodePacked(GENESIS, uint16(id)));
    }

    /// @notice Eight runes, each 0..15, unfolded from the essence.
    ///         A stable, cheap primitive for anyone building downstream.
    function runesOf(uint256 id) public view returns (uint8[8] memory runes) {
        bytes32 e = essenceOf(id);
        for (uint256 i = 0; i < 8; i++) {
            runes[i] = uint8(uint8(e[i]) & 0x0f);
        }
    }

    /// @notice A compact human-readable inscription of a Sigil's runes.
    function markingOf(uint256 id) public view returns (string memory) {
        // Sixteen marks. Deliberately terse. Deliberately incomplete.
        bytes memory GLYPHS = bytes(unicode"·-=+*#%@ITLOXVY");
        uint8[8] memory r = runesOf(id);
        bytes memory out = new bytes(8);
        for (uint256 i = 0; i < 8; i++) out[i] = GLYPHS[r[i]];
        return string(out);
    }

    // ---------------------------------------------------------------------
    //  The Keystone
    //
    //  Somewhere in the expanse, one Sigil stands apart. This contract
    //  can tell whether a given id is the Keystone, but it will never
    //  volunteer which id that is — you must arrive holding the answer.
    // ---------------------------------------------------------------------

    /// @dev The keeper of the Keystone. address(0) until claimed.
    address public keeper;

    /// @dev The single line the keeper is permitted to leave behind.
    string public firstWord;

    /// @dev Commitments in the sealed-bid claim. A claimant first buries a
    ///      hash of (id, salt, self), then — a block later — reveals it.
    ///      This keeps the answer out of the mempool until it is too late
    ///      to steal.
    mapping(address => bytes32) public buriedHash;
    mapping(address => uint256) public sealedAt;

    event Buried(address indexed seeker);
    event KeystoneTaken(address indexed keeper, uint256 indexed id);
    event Spoken(string word);

    /// @notice Step one. Bury your answer where no one can read it.
    /// @param commitment keccak256(abi.encodePacked(id, salt, msg.sender))
    function bury(bytes32 commitment) external {
        require(keeper == address(0), "the stone is taken");
        buriedHash[msg.sender] = commitment;
        sealedAt[msg.sender] = block.number;
        emit Buried(msg.sender);
    }

    /// @notice Step two, in a later block. Reveal your buried answer and,
    ///         if it is the Keystone, take it.
    /// @param id   the Sigil you believe to be the Keystone
    /// @param salt the secret you buried alongside it
    function unearth(uint256 id, bytes32 salt) external {
        require(keeper == address(0), "the stone is taken");
        require(sealedAt[msg.sender] != 0, "nothing buried");
        require(block.number > sealedAt[msg.sender], "too soon");
        require(
            keccak256(abi.encodePacked(id, salt, msg.sender)) == buriedHash[msg.sender],
            "the earth is undisturbed"
        );
        require(_isKeystone(id), "not the Keystone");

        keeper = msg.sender;
        _mint(msg.sender, id); // the Keystone Sigil, made manifest and bound
        emit KeystoneTaken(msg.sender, id);
    }

    /// @notice The keeper may speak once. After that, silence forever.
    function speak(string calldata word) external {
        require(msg.sender == keeper, "you are not the keeper");
        require(bytes(firstWord).length == 0, "already spoken");
        require(bytes(word).length > 0 && bytes(word).length <= 96, "malformed");
        firstWord = word;
        emit Spoken(word);
    }

    /// @dev The heart of the puzzle. What makes a Sigil the Keystone?
    ///      The rule lives here and nowhere else. It is not written in
    ///      the README. It is not emitted in an event. To learn it, you
    ///      must read this function — and then search the expanse yourself.
    ///
    ///      The Keystone is the one Sigil whose essence, read as a number,
    ///      is smaller than every other essence in the expanse. There is
    ///      exactly one. Finding it costs nothing but attention.
    function _isKeystone(uint256 id) internal view returns (bool) {
        uint256 candidate = uint256(essenceOf(id));
        for (uint256 j = 0; j < EXPANSE; j++) {
            if (uint256(essenceOf(j)) < candidate) return false;
        }
        return true;
    }

    // ---------------------------------------------------------------------
    //  On-chain rendering — the Sigil made visible
    // ---------------------------------------------------------------------

    function tokenURI(uint256 id) public view returns (string memory) {
        require(_owners[id] != address(0) || id < EXPANSE, "no such Sigil");
        string memory svg = _render(id);
        string memory json = string(
            abi.encodePacked(
                '{"name":"Sigil #', _toString(id),
                '","description":"One of 1024 Sigils. A fact, not a coin. Derived on-chain from a single Word. One is the Keystone.",',
                '"attributes":[{"trait_type":"marking","value":"', markingOf(id), '"}],',
                '"image":"data:image/svg+xml;base64,', Base64.encode(bytes(svg)), '"}'
            )
        );
        return string(abi.encodePacked("data:application/json;base64,", Base64.encode(bytes(json))));
    }

    function _render(uint256 id) internal view returns (string memory) {
        uint8[8] memory r = runesOf(id);
        // A dark field with a 4x4 lattice of cells; each cell lit by a rune.
        bytes memory cells;
        for (uint256 i = 0; i < 16; i++) {
            uint8 v = r[i % 8];
            uint256 x = 60 + (i % 4) * 90;
            uint256 y = 60 + (i / 4) * 90;
            uint256 rad = 6 + uint256(v) * 2;
            // hue drifts with the rune value
            uint256 hue = (uint256(v) * 24 + i * 3) % 360;
            cells = abi.encodePacked(
                cells,
                '<circle cx="', _toString(x), '" cy="', _toString(y),
                '" r="', _toString(rad),
                '" fill="hsl(', _toString(hue), ',70%,60%)" opacity="0.85"/>'
            );
        }
        return string(
            abi.encodePacked(
                '<svg xmlns="http://www.w3.org/2000/svg" width="420" height="420" viewBox="0 0 420 420">',
                '<rect width="420" height="420" fill="#0a0a0f"/>',
                cells,
                '<text x="210" y="405" fill="#4a4a5a" font-family="monospace" font-size="13" text-anchor="middle">',
                markingOf(id),
                '</text></svg>'
            )
        );
    }

    // ---------------------------------------------------------------------
    //  Minimal ERC-721 (no external dependencies, so the whole artifact
    //  is one readable file). The Keystone token is soulbound; ordinary
    //  Sigils are freely mintable and transferable.
    // ---------------------------------------------------------------------

    string public constant name = "Sigils";
    string public constant symbol = "SIGIL";

    mapping(uint256 => address) internal _owners;
    mapping(address => uint256) internal _balances;
    mapping(uint256 => address) internal _tokenApprovals;
    mapping(address => mapping(address => bool)) internal _operatorApprovals;

    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /// @notice Claim ownership of a Sigil. Free but for gas. Ownership grants
    ///         nothing in the puzzle — it is a collector's and builder's hook.
    function mint(uint256 id) external {
        require(id < EXPANSE, "beyond the expanse");
        require(_owners[id] == address(0), "already minted");
        _mint(msg.sender, id);
    }

    function _mint(address to, uint256 id) internal {
        require(to != address(0), "zero");
        require(_owners[id] == address(0), "exists");
        _owners[id] = to;
        _balances[to] += 1;
        emit Transfer(address(0), to, id);
    }

    function balanceOf(address owner) external view returns (uint256) {
        require(owner != address(0), "zero");
        return _balances[owner];
    }

    function ownerOf(uint256 id) public view returns (address) {
        address o = _owners[id];
        require(o != address(0), "unminted");
        return o;
    }

    function approve(address to, uint256 id) external {
        address owner = ownerOf(id);
        require(msg.sender == owner || _operatorApprovals[owner][msg.sender], "not authorized");
        _tokenApprovals[id] = to;
        emit Approval(owner, to, id);
    }

    function getApproved(uint256 id) external view returns (address) {
        require(_owners[id] != address(0), "unminted");
        return _tokenApprovals[id];
    }

    function setApprovalForAll(address operator, bool approved) external {
        _operatorApprovals[msg.sender][operator] = approved;
        emit ApprovalForAll(msg.sender, operator, approved);
    }

    function isApprovedForAll(address owner, address operator) external view returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    function transferFrom(address from, address to, uint256 id) public {
        require(_owners[id] == from, "wrong from");
        require(to != address(0), "zero");
        // The Keystone Sigil is bound to its keeper and cannot move.
        require(!(keeper != address(0) && _isKeystone(id)), "the Keystone is bound");
        address owner = _owners[id];
        require(
            msg.sender == owner ||
            _tokenApprovals[id] == msg.sender ||
            _operatorApprovals[owner][msg.sender],
            "not authorized"
        );
        delete _tokenApprovals[id];
        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[id] = to;
        emit Transfer(from, to, id);
    }

    function safeTransferFrom(address from, address to, uint256 id) external {
        safeTransferFrom(from, to, id, "");
    }

    function safeTransferFrom(address from, address to, uint256 id, bytes memory data) public {
        transferFrom(from, to, id);
        if (to.code.length > 0) {
            require(
                IERC721Receiver(to).onERC721Received(msg.sender, from, id, data) ==
                    IERC721Receiver.onERC721Received.selector,
                "unsafe recipient"
            );
        }
    }

    function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
        return
            interfaceId == 0x01ffc9a7 || // ERC165
            interfaceId == 0x80ac58cd || // ERC721
            interfaceId == 0x5b5e139f;   // ERC721Metadata
    }

    // ---------------------------------------------------------------------
    //  helpers
    // ---------------------------------------------------------------------

    function _toString(uint256 v) internal pure returns (string memory) {
        if (v == 0) return "0";
        uint256 tmp = v;
        uint256 digits;
        while (tmp != 0) { digits++; tmp /= 10; }
        bytes memory buf = new bytes(digits);
        while (v != 0) { digits -= 1; buf[digits] = bytes1(uint8(48 + v % 10)); v /= 10; }
        return string(buf);
    }
}

interface IERC721Receiver {
    function onERC721Received(address, address, uint256, bytes calldata) external returns (bytes4);
}

/// @dev Compact base64 encoder (Brecht Devos / MIT), inlined so the artifact
///      carries no dependencies.
library Base64 {
    bytes internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

    function encode(bytes memory data) internal pure returns (string memory) {
        if (data.length == 0) return "";
        string memory table = string(TABLE);
        uint256 encodedLen = 4 * ((data.length + 2) / 3);
        string memory result = new string(encodedLen + 32);

        assembly {
            mstore(result, encodedLen)
            let tablePtr := add(table, 1)
            let dataPtr := data
            let endPtr := add(dataPtr, mload(data))
            let resultPtr := add(result, 32)

            for {} lt(dataPtr, endPtr) {} {
                dataPtr := add(dataPtr, 3)
                let input := mload(dataPtr)

                mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))
                resultPtr := add(resultPtr, 1)
                mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))
                resultPtr := add(resultPtr, 1)
                mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))
                resultPtr := add(resultPtr, 1)
                mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))
                resultPtr := add(resultPtr, 1)
            }

            switch mod(mload(data), 3)
            case 1 { mstore8(sub(resultPtr, 1), 0x3d) mstore8(sub(resultPtr, 2), 0x3d) }
            case 2 { mstore8(sub(resultPtr, 1), 0x3d) }
        }

        return result;
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "osaka",
  "remappings": [
    "forge-std/=lib/forge-std/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.