Verified contractPartialMIT
Tomorrows
Address0xe0fc0663e96a5774bcef522523be0790b6dcfc07
- Balance
0 ETH
- Transactions
1,834
- 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,229,350
- Creation transaction
- 0xaa873dc621…276a88df91
18 files
- src/Tomorrows.solmain32.58 KB
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC2981.sol872 B
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6.53 KB
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol17.7 KB
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol4.93 KB
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol995 B
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Metadata.sol792 B
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/token/common/ERC2981.sol5.13 KB
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/Base64.sol3.86 KB
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/Strings.sol3.1 KB
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/cryptography/MerkleProof.sol9.76 KB
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol911 B
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol869 B
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/math/Math.sol15.12 KB
- ../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol1.26 KB
- src/ScriptStore.sol2.34 KB
- src/TomorrowsViewer.sol11.73 KB
src/Tomorrows.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {ERC2981} from "@openzeppelin/contracts/token/common/ERC2981.sol";
import {Base64} from "@openzeppelin/contracts/utils/Base64.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {MerkleProof} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import {ScriptStore} from "./ScriptStore.sol";
import {TomorrowsViewer} from "./TomorrowsViewer.sol";
interface IViewerPage { function html(string calldata, string calldata, string calldata, string calldata, string calldata, string calldata) external pure returns (bytes memory); }
// THE CREATOR TOKEN STANDARD (Limit Break's ERC-721C), the way marketplaces recognise enforced
// royalties: the token names a transfer validator, and every transfer between two holders is asked
// of it first. the validator applies the collection's policy (by default: marketplaces that pay the
// creator's royalty may move pieces, wallet-to-wallet transfers by the holder are fine). the
// interfaces below are Limit Break's, copied exactly (github.com/limitbreakinc/creator-token-standards,
// src/interfaces, commit 980a63b); the library itself is built on OpenZeppelin 4's hooks, so its
// logic is carried over by hand onto OpenZeppelin 5's _update below.
interface ICreatorToken {
event TransferValidatorUpdated(address oldValidator, address newValidator);
function getTransferValidator() external view returns (address validator);
function setTransferValidator(address validator) external;
function getTransferValidationFunction() external view returns (bytes4 functionSignature, bool isViewFunction);
}
interface ICreatorTokenLegacy {
event TransferValidatorUpdated(address oldValidator, address newValidator);
function getTransferValidator() external view returns (address validator);
function setTransferValidator(address validator) external;
}
interface ITransferValidator { function validateTransfer(address caller, address from, address to, uint256 tokenId) external view; }
interface ITransferValidatorSetTokenType { function setTokenTypeOfCollection(address collection, uint16 tokenType) external; }
// the mint contract for the sepolia rehearsal: the shape of the real one, named like the test
// tokens so it stays low-key. the door has the terms agreed with Pronoia on 2026-10-08: 3,333
// pieces, ten per wallet, 0.05 to the public and 0.035 to holders; for every Kaoform held, three
// at the holder price of which one is reserved for the first five minutes (1,111 reserved, one
// per Kaoform); for every Argonaut held, one at the holder price, nothing reserved; a holder's
// pieces beyond that at the public price, in the same transaction. the holders are a merkle
// list whose leaves carry the counts, the way Kaoforms carried its holders
// (drops/S1/001_kaoforms/contracts/src/Kaoforms.sol, whose words are kept below). the hash set
// one block after the mint; tokenURI pointing at the previews a renderer makes from the
// contract's own page; tokenHTML(id), the token's complete page assembled from the store.
contract Tomorrows is ERC721, ERC2981, ICreatorToken {
using Strings for uint256;
uint256 public constant MAX = 3333;
uint256 public constant PER_TX = 33; // per order (one mint call), no wallet limit (the final rules, 2026-10-16; was 10 per wallet).
// a contract wallet may place several orders in one transaction, which is no different from
// several transactions, since nothing is counted per wallet (review v17 L-01)
uint256 public constant KAO_RESERVE = 1111; // one per Kaoform, held back for the window
uint256 public constant PER_KAO = 3; // at the holder price, per Kaoform held (one of them reserved)
uint256 public constant PER_ARGO = 1; // at the holder price, per Argonaut held
uint256 public constant SETTLED_PER_MINT = 8; // how many waiting runs a mint looks at on its way
/// THE OWNER can hand over, in two steps (review v4 H-03): the deployer's key sets the collection up,
/// then names the wallet that keeps it (a multisig if the founder decides so), which must accept. a
/// wrong address cannot take it; a sender that is not the pending owner cannot take it either
address public owner;
address public pendingOwner;
address public immutable store; // the ScriptStore holding the work's files, gzip + base64
/// THE MONEY, AS THE SITE PROMISES IT (docs: 90% of every mint to the artist, 10% to ArtMachine):
/// withdraw pays both in the same call, so nobody has to remember to pass the artist's part on.
/// the artist's part goes to his business wallet; the royalty on every resale is his alone
address public immutable artistPayout; // Pronoia's KVK wallet: his 90% and his royalties
address public immutable artistWallet; // Pronoia's artist wallet: the 51 pieces made before the open
uint256 public constant ARTIST_SHARE = 90; // percent of the mint
uint256 public constant ARTIST_PIECES = 51; // 33 until 2026-10-14; 51 is the artist's word, through the founder
uint256 public artistMinted;
/// ROYALTIES ENFORCED (the founder, 2026-10-11: "5% royalties to him, enforced in contract"): OpenSea's
/// StrictAuthorizedTransferSecurityRegistry, the validator OpenSea's docs name for collections that
/// enforce creator earnings. its default list lets through an OpenSea sale (its SignedZone opens the
/// door for that one piece inside the sale) and Limit Break's Payment Processor (Magic Eden and the
/// markets built on it); a holder moving their own piece is always free. Limit Break's own V5
/// validator (0x721C008fdff27BF06E7E123956E2Fe03B63342e3) was tried first and blocks OpenSea, which
/// is where the collectors are. proven on a mainnet fork in test/OpenSeaValidator.t.sol
address public constant DEFAULT_TRANSFER_VALIDATOR = 0xA000027A9B2802E1ddf7000061001e5c005A0000;
uint16 private constant TOKEN_TYPE_ERC721 = 721;
bool private validatorSet;
address private validator_;
string public base; // where the previews live: base + "<id>.jpg", "<id>.gif", "waiting.png"
/// the piece's own page on our site: viewer + "<id>". his October-12 package reads it as window.viewerUrl
/// (the "copy full viewer link" button in a marketplace frame), and marketplaces show it as the token's
/// outside link (external_url, OpenSea's globe). settable, so the site may move; empty means none
string public viewer;
/// the public nodes the marketplace live view asks for the page, tried in order (src/TomorrowsViewer.sol).
/// a plain list, comma between addresses, no spaces or quotes: https://a,https://b. settable, so a node
/// that goes away can be replaced
string public rpcs;
/// THE WORK IS CONTENT-ADDRESSED (review finding TMRW-01). the body of every token's page, the stored
/// files as tokenHTML emits them, has one SHA-256, fixed at deploy. the marketplace viewer takes the
/// body from a public node, hashes it in the browser and refuses anything that does not match; the
/// head (id, hash, viewer) it writes itself from the token's own metadata. so no node, and no owner
/// pointing the viewer at another node, can show anything but the work. verifyBody() recomputes the
/// digest on the chain for anyone to check (a free call)
bytes32 public immutable bodyDigest;
/// the viewer page's bytes live in a contract of their own (src/TomorrowsViewer.sol, pure), named here for good
address public immutable viewerPage;
/// the renderer: the one other key allowed to write traits, so the owner's key never sits in a
/// running service (finding TMRW-05). the owner may name or replace it until the lock
address public renderer;
/// ONE-WAY LOCK (review TMRW-03, M-03): after lock(), the terms (configure) and the viewer are fixed for
/// good. traits are written once per settled token (setTraits) and need no lock. what stays: the
/// renderer (a service key, replaceable and revocable at any time, see setRenderer), rpcs (availability
/// only, the digest guards the content), the royalty rate and the transfer validator (the artist's, and
/// the way out if a marketplace changes policy), close() and withdraw(), and the hand-over above.
/// THE PREVIEWS' ADDRESS (base) has a lock of its own (review v4 M-07): the stills and gifs are made after
/// each mint and move to permanent storage once the edition is complete; then lockBase(), one way
bool public locked;
bool public baseLocked;
bool private paying;
uint256 public totalSupply; // ids run from 1 to this
// the door's terms, set by configure until the door opens
bytes32 public root; // the holders: leaf = keccak(address, uint8 kaoforms, uint8 argonauts)
uint64 public openAt; // 0: not open
uint64 public reserveWindow = 5 minutes;
uint256 public publicPrice;
uint256 public holderPrice;
bool public closed;
uint256 public reservedMinted; // of KAO_RESERVE, during the window
mapping(address => uint256) public discountUsed; // holder-priced pieces taken
mapping(address => uint256) public reservedUsed; // reserved pieces taken
/// THE HASH IS SET ONE BLOCK AFTER THE MINT, NOT INSIDE IT. a hash set inside the transaction
/// can be read by whoever sent it, and a contract that mints, looks, and reverts unless the
/// piece is rare pays only gas for every try. so a mint records the block it was born in and
/// nothing else, and the piece is drawn from the blockhash of that block, which does not exist
/// until the next one begins. nobody who pays can know what they paid for.
///
/// A PIECE IS NOT SHOWN UNTIL IT CANNOT CHANGE. the chain forgets a blockhash after 256 blocks,
/// so it is written down: once per block, for every piece born in it, by the next mint, the
/// next transfer, or anyone calling settle(). until then hashOf() is zero. a block nobody wrote
/// down in time is gone: its pieces are moved, blind, to the block in which that was noticed,
/// and wait again.
struct Run { uint64 blockNo; uint32 firstId; uint32 lastId; }
Run[] private _runs;
uint256 public looked;
mapping(uint256 => uint64) public born;
mapping(uint64 => uint64) public movedTo;
mapping(uint64 => bytes32) public entropy;
mapping(uint256 => string) private traits; // written by the renderer once the piece exists: a json array
/// whether the piece moves. a moving piece's image is its GIF, so a marketplace's grid shows it
/// moving, as Kaoforms did; a still piece's image is its JPG. the renderer knows which once the
/// piece exists and writes it with the traits.
mapping(uint256 => bool) public moving;
event Minted(uint256 indexed id, address indexed to);
event Configured(bytes32 root, uint64 openAt, uint64 reserveWindow, uint256 holderPrice, uint256 publicPrice);
event Drawn(uint256 fromId, uint256 toId, uint64 blockNo);
event Moved(uint256 fromId, uint256 toId, uint64 fromBlock, uint64 toBlock);
event MetadataUpdate(uint256 _tokenId);
event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);
constructor(address store_, bytes32 bodyDigest_, address viewerPage_, string memory base_, address artistPayout_, address artistWallet_, uint96 royaltyBps_) ERC721("Tomorrows", "TMRW") {
require(artistPayout_ != address(0) && artistWallet_ != address(0), "artist");
// the store must be a contract, sealed, and hold the two files the page is built with (finding TMRW-02)
require(store_.code.length != 0 && ScriptStore(store_).isSealed(), "store not sealed");
{ (, uint32 msz,) = ScriptStore(store_).meta("_manifest.js"); (, uint32 lsz,) = ScriptStore(store_).meta("_loader.js"); require(msz != 0 && lsz != 0, "store incomplete"); }
require(bodyDigest_ != 0, "digest");
// the viewer page must be exactly the one compiled with this collection, byte for byte (review M-02):
// a page with the same interface but without the digest check could not be passed off as it
require(viewerPage_.codehash == keccak256(type(TomorrowsViewer).runtimeCode), "viewer page");
_checkUrl(base_);
owner = msg.sender; store = store_; bodyDigest = bodyDigest_; viewerPage = viewerPage_; base = base_; artistPayout = artistPayout_; artistWallet = artistWallet_;
_setDefaultRoyalty(artistPayout_, royaltyBps_);
rpcs = block.chainid == 1
? "https://ethereum-rpc.publicnode.com,https://eth.drpc.org,https://eth.llamarpc.com"
: "https://ethereum-sepolia-rpc.publicnode.com,https://sepolia.drpc.org";
emit TransferValidatorUpdated(address(0), DEFAULT_TRANSFER_VALIDATOR);
_registerTokenType(DEFAULT_TRANSFER_VALIDATOR);
}
// ---------------------------------------------------------------- the creator token
function getTransferValidator() public view returns (address v) { v = validator_; if (v == address(0) && !validatorSet) v = DEFAULT_TRANSFER_VALIDATOR; }
function getTransferValidationFunction() external pure returns (bytes4 functionSignature, bool isViewFunction) {
functionSignature = bytes4(keccak256("validateTransfer(address,address,address,uint256)")); isViewFunction = true;
}
/// the owner may point at another validator, or at none (address 0), which ends the enforcement
function setTransferValidator(address v) external onlyOwner {
require(v == address(0) || v.code.length > 0, "not a validator");
emit TransferValidatorUpdated(getTransferValidator(), v);
validatorSet = true; validator_ = v;
_registerTokenType(v);
}
function _registerTokenType(address v) private {
if (v != address(0) && v.code.length > 0) { try ITransferValidatorSetTokenType(v).setTokenTypeOfCollection(address(this), TOKEN_TYPE_ERC721) {} catch {} }
}
modifier onlyOwner() { require(msg.sender == owner, "no"); _; }
event OwnershipTransferred(address indexed from, address indexed to);
function transferOwnership(address to) external onlyOwner { pendingOwner = to; }
function acceptOwnership() external { require(msg.sender == pendingOwner && msg.sender != address(0), "no"); emit OwnershipTransferred(owner, msg.sender); owner = msg.sender; pendingOwner = address(0); }
modifier open() { require(!locked, "locked"); _; }
/// the door's terms. settable until the moment it opens, then fixed; and not after the lock (review v3 M-03)
function configure(bytes32 root_, uint64 openAt_, uint64 reserveWindow_, uint256 holderPrice_, uint256 publicPrice_, string calldata base_) external onlyOwner open {
require(phase() == 0 && !closed, "open");
require(openAt_ == 0 || openAt_ > block.timestamp - 1, "past");
// once base is locked, configure leaves it where it is (review 2026-10-13 T-07)
if (!baseLocked) { _checkUrl(base_); base = base_; }
root = root_; openAt = openAt_; reserveWindow = reserveWindow_; holderPrice = holderPrice_; publicPrice = publicPrice_;
emit Configured(root_, openAt_, reserveWindow_, holderPrice_, publicPrice_);
}
function setBase(string calldata base_) external onlyOwner { require(!baseLocked, "base locked"); _checkUrl(base_); base = base_; emit BatchMetadataUpdate(1, type(uint256).max); }
function lockBase() external onlyOwner { baseLocked = true; }
function setViewer(string calldata viewer_) external onlyOwner open { if (bytes(viewer_).length != 0) _checkUrl(viewer_); viewer = viewer_; emit BatchMetadataUpdate(1, type(uint256).max); }
/// the renderer's key can be replaced or revoked (address 0) at any time, lock or no lock (review 2026-10-13
/// T-03): a service key must be revocable the moment it misbehaves; the owner's key is the authority
event RendererSet(address indexed from, address indexed to);
function setRenderer(address renderer_) external onlyOwner { emit RendererSet(renderer, renderer_); renderer = renderer_; }
function lock() external onlyOwner { locked = true; }
function setRpcs(string calldata rpcs_) external onlyOwner { _checkUrl(rpcs_); rpcs = rpcs_; emit BatchMetadataUpdate(1, type(uint256).max); }
/// an https address (or a comma list of them): nothing that could end a string or open a tag in the json or
/// the page it is written into (finding TMRW-06)
function _checkUrl(string memory u) private pure {
bytes memory b = bytes(u);
require(b.length > 8 && b[0] == "h" && b[1] == "t" && b[2] == "t" && b[3] == "p" && b[4] == "s" && b[5] == ":" && b[6] == "/" && b[7] == "/", "https only");
for (uint256 i; i < b.length; i++) { bytes1 c = b[i]; require(c > 0x20 && c < 0x7f && c != '"' && c != "'" && c != "\\" && c != "<" && c != ">", "bad char"); }
}
/// shuts the door for good. what is minted is the collection
function close() external onlyOwner { closed = true; }
/// 90% to the artist, the rest to ArtMachine, in one call. anyone may call it: it only pays where it must
function withdraw() external {
require(!paying, "busy"); paying = true;
uint256 all = address(this).balance;
uint256 toArtist = all * ARTIST_SHARE / 100;
(bool a,) = artistPayout.call{value: toArtist}(""); require(a, "artist");
(bool b,) = owner.call{value: all - toArtist}(""); require(b, "platform");
paying = false;
}
/// the royalty the artist sets, paid to his business wallet (ERC-2981). the rate is his to change
function setRoyalty(uint96 bps) external onlyOwner { require(bps <= 1000, "at most 10%"); _setDefaultRoyalty(artistPayout, bps); }
// ---------------------------------------------------------------- the door
/// 0 before the open, 1 while the reserve is held for Kaoform holders, 2 once it is one pool,
/// 3 when it is over. both doors open at the same moment: the public one simply cannot reach
/// the reserve during the window.
function phase() public view returns (uint8) {
if (closed || totalSupply == MAX) return 3;
if (openAt == 0 || block.timestamp < openAt) return 0;
if (block.timestamp < openAt + reserveWindow) return 1;
return 2;
}
/// what the reserve still holds back from everyone else
function held() public view returns (uint256) {
return phase() == 1 ? KAO_RESERVE - reservedMinted : 0;
}
/// what a holder may still take: at the holder price, and of the reserve (only in the window)
function allowance(address holder, uint8 kaos, uint8 argos) public view returns (uint256 discounted, uint256 reserved_) {
uint256 d = uint256(kaos) * PER_KAO + uint256(argos) * PER_ARGO;
discounted = d > discountUsed[holder] ? d - discountUsed[holder] : 0;
uint256 r = phase() == 1 ? uint256(kaos) : 0;
reserved_ = r > reservedUsed[holder] ? r - reservedUsed[holder] : 0;
}
/// what qty pieces cost a holder with that many discounted left: the first at the holder price, the rest public
function quote(uint256 qty, uint256 discounted) public view returns (uint256) {
uint256 d = qty < discounted ? qty : discounted;
return d * holderPrice + (qty - d) * publicPrice;
}
function mint(uint256 qty) external payable {
uint8 ph = phase();
require(ph == 1 || ph == 2, "not open");
require(msg.value == publicPrice * qty, "price");
require(totalSupply + qty + held() <= MAX, "held for holders");
_mintTo(msg.sender, qty, true);
}
function mintHolder(uint256 qty, uint8 kaos, uint8 argos, bytes32[] calldata proof) external payable {
_mintHolder(msg.sender, qty, kaos, argos, proof);
}
/// a holder mints from the wallet that holds (review 2026-10-13 T-04): a mint sent for another wallet
/// would spend that wallet's discount and reserved piece without its consent and make its own pending
/// mint fail on the price. so there is no mintHolderTo; a wallet kept cold comes out to mint
function _mintHolder(address holder, uint256 qty, uint8 kaos, uint8 argos, bytes32[] calldata proof) private {
uint8 ph = phase();
require(ph == 1 || ph == 2, "not open");
require(MerkleProof.verifyCalldata(proof, root, keccak256(abi.encodePacked(holder, kaos, argos))), "not a holder");
(uint256 discounted, uint256 reserved_) = allowance(holder, kaos, argos);
require(msg.value == quote(qty, discounted), "price");
uint256 d = qty < discounted ? qty : discounted;
discountUsed[holder] += d;
// in the window a holder's reserved pieces come out of the reserve; the rest of the order
// must fit beside what is still held for the others
uint256 r = qty < reserved_ ? qty : reserved_;
if (r != 0) { reservedUsed[holder] += r; reservedMinted += r; }
require(totalSupply + qty + held() <= MAX, "held for holders");
_mintTo(holder, qty, true);
}
/// the artist's 51, made before the door opens and outside every limit, straight to his artist
/// wallet: his part of the edition, and the first test of the contract on the chain. one at a time
/// is allowed, so the first can be checked before the rest are made
function mintArtist(uint256 qty) external onlyOwner {
require(phase() == 0, "before the open");
require(artistMinted + qty <= ARTIST_PIECES, "fifty-one");
artistMinted += qty;
_mintTo(artistWallet, qty, false);
}
function _mintTo(address to, uint256 qty, bool limited) private {
require(qty != 0, "nothing");
if (limited) require(qty <= PER_TX, "33 per order");
require(totalSupply + qty <= MAX, "sold out");
settle(SETTLED_PER_MINT);
uint256 first = totalSupply + 1;
uint64 here = uint64(block.number);
for (uint256 k; k < qty; ++k) {
uint256 id = ++totalSupply;
born[id] = here;
_mint(to, id);
emit Minted(id, to);
}
uint256 n = _runs.length;
if (n != 0 && _runs[n - 1].blockNo == here && _runs[n - 1].lastId + 1 == first) _runs[n - 1].lastId = uint32(totalSupply);
else _runs.push(Run(here, uint32(first), uint32(totalSupply)));
}
// ---------------------------------------------------------------- the hash
function hashOf(uint256 id) public view returns (bytes32) {
uint64 b = born[id];
if (b == 0) return 0;
for (uint64 to = movedTo[b]; to != 0; to = movedTo[b]) b = to;
bytes32 e = entropy[b];
return e == 0 ? bytes32(0) : keccak256(abi.encodePacked(e, id, address(this)));
}
function waiting() external view returns (uint256 runs, uint64 oldest) {
runs = _runs.length - looked;
oldest = runs == 0 ? 0 : _runs[looked].blockNo;
}
/// looks at up to max waiting runs, in order, and writes down the hash of every block among
/// them that has ended. anyone may call it; it decides nothing, it only records what the
/// chain already says.
function settle(uint256 max) public returns (uint256 seen) {
uint256 i = looked;
uint256 n = _runs.length;
uint64 here = uint64(block.number);
while (seen < max && i < n) {
Run memory r = _runs[i];
if (r.blockNo >= here) break;
bytes32 e = entropy[r.blockNo];
if (e == 0) { e = blockhash(r.blockNo); if (e != 0) entropy[r.blockNo] = e; }
if (e != 0) { emit Drawn(r.firstId, r.lastId, r.blockNo); emit BatchMetadataUpdate(r.firstId, r.lastId); }
else {
uint64 to = movedTo[r.blockNo];
if (to == 0) { to = here; movedTo[r.blockNo] = to; }
_runs.push(Run(to, r.firstId, r.lastId));
emit Moved(r.firstId, r.lastId, r.blockNo, to);
}
++i; ++seen;
}
looked = i;
}
function _update(address to, uint256 tokenId, address auth) internal override returns (address) {
address from = _ownerOf(tokenId);
if (from != address(0)) {
settle(2);
// a transfer between two holders is asked of the validator first (mints and burns are not)
if (to != address(0)) {
address v = getTransferValidator();
if (v != address(0) && msg.sender != v) ITransferValidator(v).validateTransfer(_msgSender(), from, to, tokenId);
}
}
return super._update(to, tokenId, auth);
}
// ---------------------------------------------------------------- the token
/// TRAITS, TYPED AND WRITTEN ONCE (review M-03, L-02): names and values as separate strings, the json
/// built here, so it cannot be malformed; each string plain (no quote, backslash, tag or control byte);
/// a token's traits can be written once, by the owner or the renderer, and never changed. so the
/// renderer's key can do one narrow thing per token, and the lock below need not touch traits
function setTraits(uint256 id, string[] calldata names, string[] calldata values, bool moving_) external {
require(msg.sender == owner || msg.sender == renderer, "no");
require(hashOf(id) != 0, "not settled"); // traits describe the piece, and the piece exists only once its hash does
require(bytes(traits[id]).length == 0, "written");
require(names.length == values.length && names.length != 0 && names.length <= 32, "count");
bytes memory j = "[";
for (uint256 i; i < names.length; i++) {
_plain(names[i]); _plain(values[i]);
j = abi.encodePacked(j, i == 0 ? '{"trait_type":"' : ',{"trait_type":"', names[i], '","value":"', values[i], '"}');
}
traits[id] = string(abi.encodePacked(j, "]")); moving[id] = moving_; emit MetadataUpdate(id);
}
function _plain(string calldata t) private pure {
bytes calldata b = bytes(t);
require(b.length != 0 && b.length <= 64, "length");
for (uint256 i; i < b.length; i++) { bytes1 c = b[i]; require(c >= 0x20 && c != '"' && c != "\\" && c != "<" && c != ">", "bad char"); }
}
function supportsInterface(bytes4 id) public view override(ERC721, ERC2981) returns (bool) {
return id == 0x49064906 || id == type(ICreatorToken).interfaceId || id == type(ICreatorTokenLegacy).interfaceId || super.supportsInterface(id);
}
function tokenURI(uint256 id) public view override returns (string memory) {
_requireOwned(id);
bytes32 h = hashOf(id);
string memory json;
if (h == 0) {
json = string.concat('{"name":"Tomorrows #', id.toString(), '","description":"A terminal left running a billion years from now. Minted; its hash is written down a block later, and the piece appears then.","image":"', base, 'waiting.png"}');
} else {
string memory hs = uint256(h).toHexString(32);
json = string.concat(
'{"name":"Tomorrows #', id.toString(),
'","description":"A terminal left running a billion years from now.","hash":"', hs,
// the waiting image until the renderer has written the traits (it publishes the picture first), so a
// marketplace is never pointed at a picture that is not there yet (2026-10-18)
'","image":"', base, bytes(traits[id]).length == 0 ? "waiting.png" : string.concat(id.toString(), moving[id] ? ".gif" : ".jpg"),
'","animation_url":"data:text/html;base64,', Base64.encode(IViewerPage(viewerPage).html(rpcs, Strings.toHexString(address(this)), id.toString(), hs, viewer, uint256(bodyDigest).toHexString(32))), '"',
bytes(viewer).length == 0 ? "" : string.concat(',"external_url":"', viewer, id.toString(), '"'),
bytes(traits[id]).length == 0 ? "" : string.concat(',"attributes":', traits[id]),
"}"
);
}
return string.concat("data:application/json;base64,", Base64.encode(bytes(json)));
}
// ---------------------------------------------------------------- the page
bytes constant HEAD_A = '<!doctype html><html><head><meta charset="utf-8"><title>Tomorrows</title><style>html,body{margin:0;background:#000}</style></head><body><script>var TOKEN={id:';
bytes constant HEAD_B = ',hash:"';
bytes constant HEAD_B2 = '",viewer:"';
bytes constant HEAD_C = '"};</script><script>';
bytes constant MID_1 = '</script><script type="text/plain" id="d">';
bytes constant MID_2 = '</script><script>';
bytes constant TAIL = '</script></body></html>';
/// the token's complete page: head (id, hash, viewer), then the body: file list, every file of the
/// work and the loader. written into one buffer in place and returned from assembly, so a 3 MB page
/// stays within a public node's gas cap for a free call
function tokenHTML(uint256 id) external view returns (string memory) {
require(born[id] != 0, "no token");
bytes32 h = hashOf(id);
require(h != 0, "not drawn yet");
(bytes memory out, uint256 total) = _build(abi.encodePacked(HEAD_A, id.toString(), HEAD_B, uint256(h).toHexString(32), HEAD_B2, viewer, HEAD_C));
assembly {
let p := add(out, 32)
mstore(p, 0x20)
mstore(add(p, 32), total)
return(p, add(64, mul(div(add(total, 31), 32), 32)))
}
}
/// the body alone, the same for every token: what the digest is of, and what the viewer fetches
function body() external view returns (string memory) {
(bytes memory out, uint256 total) = _build("");
assembly {
let p := add(out, 32)
mstore(p, 0x20)
mstore(add(p, 32), total)
return(p, add(64, mul(div(add(total, 31), 32), 32)))
}
}
/// does the store, as this contract emits it, still hash to the digest fixed at deploy. anyone, any time, free
function verifyBody() external view returns (bool) {
(bytes memory out, uint256 total) = _build("");
bytes32 d;
assembly { pop(staticcall(gas(), 2, add(out, 96), total, 0, 32)) d := mload(0) }
return d == bodyDigest;
}
function _build(bytes memory head) private view returns (bytes memory out, uint256 total) {
ScriptStore s = ScriptStore(store);
uint256 n = s.count();
total = head.length + MID_1.length + MID_2.length + TAIL.length;
{ (, uint32 msz,) = s.meta("_manifest.js"); (, uint32 lsz,) = s.meta("_loader.js"); total += msz + lsz; }
for (uint256 i = 0; i < n; i++) {
string memory nm = s.names(i);
if (bytes(nm)[0] == bytes1("_")) continue;
(, uint32 sz,) = s.meta(nm);
total += sz;
}
out = new bytes(total + 64 + 32);
uint256 pos = 64;
pos = put(out, pos, head);
{ (address[] memory c,,) = s.meta("_manifest.js"); pos = putFile(out, pos, c); }
pos = put(out, pos, MID_1);
for (uint256 i = 0; i < n; i++) {
string memory nm = s.names(i);
if (bytes(nm)[0] == bytes1("_")) continue;
(address[] memory c,,) = s.meta(nm);
pos = putFile(out, pos, c);
}
pos = put(out, pos, MID_2);
{ (address[] memory c,,) = s.meta("_loader.js"); pos = putFile(out, pos, c); }
pos = put(out, pos, TAIL);
require(pos == total + 64, "size");
}
function put(bytes memory out, uint256 pos, bytes memory src) private view returns (uint256) {
assembly { pop(staticcall(gas(), 4, add(src, 32), mload(src), add(add(out, 32), pos), mload(src))) }
return pos + src.length;
}
function putFile(bytes memory out, uint256 pos, address[] memory chunks) private view returns (uint256) {
for (uint256 i = 0; i < chunks.length; i++) {
address a = chunks[i];
uint256 len = a.code.length - 1;
assembly { extcodecopy(a, add(add(out, 32), pos), 1, len) }
pos += len;
}
return pos;
}
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC2981.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC2981.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
/**
* @dev Interface for the NFT Royalty Standard.
*
* A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal
* support for royalty payments across all NFT marketplaces and ecosystem participants.
*/
interface IERC2981 is IERC165 {
/**
* @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
* exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
*/
function royaltyInfo(
uint256 tokenId,
uint256 salePrice
) external view returns (address receiver, uint256 royaltyAmount);
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.20;
import {IERC721} from "./IERC721.sol";
import {IERC721Receiver} from "./IERC721Receiver.sol";
import {IERC721Metadata} from "./extensions/IERC721Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {Strings} from "../../utils/Strings.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
import {IERC721Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
mapping(uint256 tokenId => address) private _owners;
mapping(address owner => uint256) private _balances;
mapping(uint256 tokenId => address) private _tokenApprovals;
mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual returns (uint256) {
if (owner == address(0)) {
revert ERC721InvalidOwner(address(0));
}
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual returns (address) {
return _requireOwned(tokenId);
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
_requireOwned(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual {
_approve(to, tokenId, _msgSender());
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual returns (address) {
_requireOwned(tokenId);
return _getApproved(tokenId);
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
// Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists
// (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.
address previousOwner = _update(to, tokenId, _msgSender());
if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
transferFrom(from, to, tokenId);
_checkOnERC721Received(from, to, tokenId, data);
}
/**
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
*
* IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the
* core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances
* consistent with ownership. The invariant to preserve is that for any address `a` the value returned by
* `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
/**
* @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.
*/
function _getApproved(uint256 tokenId) internal view virtual returns (address) {
return _tokenApprovals[tokenId];
}
/**
* @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in
* particular (ignoring whether it is owned by `owner`).
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {
return
spender != address(0) &&
(owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);
}
/**
* @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.
* Reverts if `spender` does not have approval from the provided `owner` for the given token or for all its assets
* the `spender` for the specific `tokenId`.
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
if (!_isAuthorized(owner, spender, tokenId)) {
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else {
revert ERC721InsufficientApproval(spender, tokenId);
}
}
}
/**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
*
* NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that
* a uint256 would ever overflow from increments when these increments are bounded to uint128 values.
*
* WARNING: Increasing an account's balance using this function tends to be paired with an override of the
* {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership
* remain consistent with one another.
*/
function _increaseBalance(address account, uint128 value) internal virtual {
unchecked {
_balances[account] += value;
}
}
/**
* @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner
* (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that
* `auth` is either the owner of the token, or approved to operate on the token (by the owner).
*
* Emits a {Transfer} event.
*
* NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
*/
function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
address from = _ownerOf(tokenId);
// Perform (optional) operator check
if (auth != address(0)) {
_checkAuthorized(from, auth, tokenId);
}
// Execute the update
if (from != address(0)) {
// Clear approval. No need to re-authorize or emit the Approval event
_approve(address(0), tokenId, address(0), false);
unchecked {
_balances[from] -= 1;
}
}
if (to != address(0)) {
unchecked {
_balances[to] += 1;
}
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
return from;
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner != address(0)) {
revert ERC721InvalidSender(address(0));
}
}
/**
* @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
_mint(to, tokenId);
_checkOnERC721Received(address(0), to, tokenId, data);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
* This is an internal function that does not check if the sender is authorized to operate on the token.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal {
address previousOwner = _update(address(0), tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(tokenId);
}
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients
* are aware of the ERC721 standard to prevent tokens from being forever locked.
*
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is like {safeTransferFrom} in the sense that it invokes
* {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `tokenId` token must exist and be owned by `from`.
* - `to` cannot be the zero address.
* - `from` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId) internal {
_safeTransfer(from, to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
_transfer(from, to, tokenId);
_checkOnERC721Received(from, to, tokenId, data);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is
* either the owner of the token, or approved to operate on all tokens held by this owner.
*
* Emits an {Approval} event.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address to, uint256 tokenId, address auth) internal {
_approve(to, tokenId, auth, true);
}
/**
* @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not
* emitted in the context of transfers.
*/
function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {
// Avoid reading the owner unless necessary
if (emitEvent || auth != address(0)) {
address owner = _requireOwned(tokenId);
// We do not use _isAuthorized because single-token approvals should not be able to call approve
if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {
revert ERC721InvalidApprover(auth);
}
if (emitEvent) {
emit Approval(owner, to, tokenId);
}
}
_tokenApprovals[tokenId] = to;
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Requirements:
* - operator can't be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
if (operator == address(0)) {
revert ERC721InvalidOperator(operator);
}
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).
* Returns the owner.
*
* Overrides to ownership logic should be done to {_ownerOf}.
*/
function _requireOwned(uint256 tokenId) internal view returns (address) {
address owner = _ownerOf(tokenId);
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
}
return owner;
}
/**
* @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target address. This will revert if the
* recipient doesn't accept the token transfer. The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param data bytes optional data to send along with the call
*/
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private {
if (to.code.length > 0) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
if (retval != IERC721Receiver.onERC721Received.selector) {
revert ERC721InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
revert ERC721InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
* {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.20;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.20;
import {IERC721} from "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/token/common/ERC2981.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/common/ERC2981.sol)
pragma solidity ^0.8.20;
import {IERC2981} from "../../interfaces/IERC2981.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information.
*
* Royalty information can be specified globally for all token ids via {_setDefaultRoyalty}, and/or individually for
* specific token ids via {_setTokenRoyalty}. The latter takes precedence over the first.
*
* Royalty is specified as a fraction of sale price. {_feeDenominator} is overridable but defaults to 10000, meaning the
* fee is specified in basis points by default.
*
* IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See
* https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the EIP. Marketplaces are expected to
* voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
*/
abstract contract ERC2981 is IERC2981, ERC165 {
struct RoyaltyInfo {
address receiver;
uint96 royaltyFraction;
}
RoyaltyInfo private _defaultRoyaltyInfo;
mapping(uint256 tokenId => RoyaltyInfo) private _tokenRoyaltyInfo;
/**
* @dev The default royalty set is invalid (eg. (numerator / denominator) >= 1).
*/
error ERC2981InvalidDefaultRoyalty(uint256 numerator, uint256 denominator);
/**
* @dev The default royalty receiver is invalid.
*/
error ERC2981InvalidDefaultRoyaltyReceiver(address receiver);
/**
* @dev The royalty set for an specific `tokenId` is invalid (eg. (numerator / denominator) >= 1).
*/
error ERC2981InvalidTokenRoyalty(uint256 tokenId, uint256 numerator, uint256 denominator);
/**
* @dev The royalty receiver for `tokenId` is invalid.
*/
error ERC2981InvalidTokenRoyaltyReceiver(uint256 tokenId, address receiver);
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @inheritdoc IERC2981
*/
function royaltyInfo(uint256 tokenId, uint256 salePrice) public view virtual returns (address, uint256) {
RoyaltyInfo memory royalty = _tokenRoyaltyInfo[tokenId];
if (royalty.receiver == address(0)) {
royalty = _defaultRoyaltyInfo;
}
uint256 royaltyAmount = (salePrice * royalty.royaltyFraction) / _feeDenominator();
return (royalty.receiver, royaltyAmount);
}
/**
* @dev The denominator with which to interpret the fee set in {_setTokenRoyalty} and {_setDefaultRoyalty} as a
* fraction of the sale price. Defaults to 10000 so fees are expressed in basis points, but may be customized by an
* override.
*/
function _feeDenominator() internal pure virtual returns (uint96) {
return 10000;
}
/**
* @dev Sets the royalty information that all ids in this contract will default to.
*
* Requirements:
*
* - `receiver` cannot be the zero address.
* - `feeNumerator` cannot be greater than the fee denominator.
*/
function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual {
uint256 denominator = _feeDenominator();
if (feeNumerator > denominator) {
// Royalty fee will exceed the sale price
revert ERC2981InvalidDefaultRoyalty(feeNumerator, denominator);
}
if (receiver == address(0)) {
revert ERC2981InvalidDefaultRoyaltyReceiver(address(0));
}
_defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator);
}
/**
* @dev Removes default royalty information.
*/
function _deleteDefaultRoyalty() internal virtual {
delete _defaultRoyaltyInfo;
}
/**
* @dev Sets the royalty information for a specific token id, overriding the global default.
*
* Requirements:
*
* - `receiver` cannot be the zero address.
* - `feeNumerator` cannot be greater than the fee denominator.
*/
function _setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) internal virtual {
uint256 denominator = _feeDenominator();
if (feeNumerator > denominator) {
// Royalty fee will exceed the sale price
revert ERC2981InvalidTokenRoyalty(tokenId, feeNumerator, denominator);
}
if (receiver == address(0)) {
revert ERC2981InvalidTokenRoyaltyReceiver(tokenId, address(0));
}
_tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator);
}
/**
* @dev Resets royalty information for the token id back to the global default.
*/
function _resetTokenRoyalty(uint256 tokenId) internal virtual {
delete _tokenRoyaltyInfo[tokenId];
}
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/Base64.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.2) (utils/Base64.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides a set of functions to operate with Base64 strings.
*/
library Base64 {
/**
* @dev Base64 Encoding/Decoding Table
*/
string internal constant _TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**
* @dev Converts a `bytes` to its Bytes64 `string` representation.
*/
function encode(bytes memory data) internal pure returns (string memory) {
/**
* Inspired by Brecht Devos (Brechtpd) implementation - MIT licence
* https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol
*/
if (data.length == 0) return "";
// Loads the table into memory
string memory table = _TABLE;
// Encoding takes 3 bytes chunks of binary data from `bytes` data parameter
// and split into 4 numbers of 6 bits.
// The final Base64 length should be `bytes` data length multiplied by 4/3 rounded up
// - `data.length + 2` -> Round up
// - `/ 3` -> Number of 3-bytes chunks
// - `4 *` -> 4 characters for each chunk
string memory result = new string(4 * ((data.length + 2) / 3));
/// @solidity memory-safe-assembly
assembly {
// Prepare the lookup table (skip the first "length" byte)
let tablePtr := add(table, 1)
// Prepare result pointer, jump over length
let resultPtr := add(result, 0x20)
let dataPtr := data
let endPtr := add(data, mload(data))
// In some cases, the last iteration will read bytes after the end of the data. We cache the value, and
// set it to zero to make sure no dirty bytes are read in that section.
let afterPtr := add(endPtr, 0x20)
let afterCache := mload(afterPtr)
mstore(afterPtr, 0x00)
// Run over the input, 3 bytes at a time
for {
} lt(dataPtr, endPtr) {
} {
// Advance 3 bytes
dataPtr := add(dataPtr, 3)
let input := mload(dataPtr)
// To write each character, shift the 3 byte (24 bits) chunk
// 4 times in blocks of 6 bits for each character (18, 12, 6, 0)
// and apply logical AND with 0x3F to bitmask the least significant 6 bits.
// Use this as an index into the lookup table, mload an entire word
// so the desired character is in the least significant byte, and
// mstore8 this least significant byte into the result and continue.
mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
}
// Reset the value that was cached
mstore(afterPtr, afterCache)
// When data `bytes` is not exactly 3 bytes long
// it is padded with `=` characters at the end
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;
}
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/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;
}
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/cryptography/MerkleProof.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MerkleProof.sol)
pragma solidity ^0.8.20;
/**
* @dev These functions deal with verification of Merkle Tree proofs.
*
* The tree and the proofs can be generated using our
* https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
* You will find a quickstart guide in the readme.
*
* WARNING: You should avoid using leaf values that are 64 bytes long prior to
* hashing, or use a hash function other than keccak256 for hashing leaves.
* This is because the concatenation of a sorted pair of internal nodes in
* the Merkle tree could be reinterpreted as a leaf value.
* OpenZeppelin's JavaScript library generates Merkle trees that are safe
* against this attack out of the box.
*/
library MerkleProof {
/**
*@dev The multiproof provided is not valid.
*/
error MerkleProofInvalidMultiproof();
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
/**
* @dev Calldata version of {verify}
*/
function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
return processProofCalldata(proof, leaf) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leafs & pre-images are assumed to be sorted.
*/
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Calldata version of {processProof}
*/
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
* `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*/
function multiProofVerify(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProof(proof, proofFlags, leaves) == root;
}
/**
* @dev Calldata version of {multiProofVerify}
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*/
function multiProofVerifyCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves) == root;
}
/**
* @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
* proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
* leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
* respectively.
*
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*/
function processMultiProof(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the Merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.
if (leavesLen + proofLen != totalHashes + 1) {
revert MerkleProofInvalidMultiproof();
}
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
if (proofPos != proofLen) {
revert MerkleProofInvalidMultiproof();
}
unchecked {
return hashes[totalHashes - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
/**
* @dev Calldata version of {processMultiProof}.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*/
function processMultiProofCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the Merkle tree.
uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.
if (leavesLen + proofLen != totalHashes + 1) {
revert MerkleProofInvalidMultiproof();
}
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
if (proofPos != proofLen) {
revert MerkleProofInvalidMultiproof();
}
unchecked {
return hashes[totalHashes - 1];
}
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
/**
* @dev Sorts the pair (a, b) and hashes the result.
*/
function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
}
/**
* @dev Implementation of keccak256(abi.encode(a, b)) that doesn't allocate or expand memory.
*/
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/math/Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
../../001_kaoforms/contracts/lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
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;
}
}
src/TomorrowsViewer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
// GENERATED by viewer/build.mjs from viewer/viewer.html. do not edit by hand.
//
// a contract of its own, deployed once before the collection and named in its constructor, because the
// collection is at Ethereum's size limit. pure: it only writes these bytes around the values it is given.
//
// the token's live view as marketplaces show it. OpenSea does not open a token's animation_url where
// it lives: it downloads the page once, keeps its own copy (raw2.seadn.io) and shows that copy in a
// frame that only allows scripts, without the original address or its query string (checked on
// Terraforms #1, 2026-10-13). so the page carries its contract and token inside it: it asks the
// chain for body() through the public nodes listed, checks its SHA-256 against the digest the contract
// fixed at deploy (so no node can show anything but the work), writes the head itself from the token's
// id, hash and viewer link, and runs the page with Pronoia's key menu hidden. nothing is hosted.
contract TomorrowsViewer {
bytes internal constant P0 = hex"3c21646f63747970652068746d6c3e3c68746d6c3e3c686561643e3c6d65746120636861727365743d227574662d38223e3c6d657461206e616d653d2276696577706f72742220636f6e74656e743d2277696474683d6465766963652d77696474682c696e697469616c2d7363616c653d31223e3c7469746c653e546f6d6f72726f77733c2f7469746c653e3c7374796c653e68746d6c2c626f64797b6d617267696e3a303b6865696768743a313030253b6261636b67726f756e643a233030303b636f6c6f723a233737373b666f6e743a31327078206d6f6e6f73706163657d696672616d657b77696474683a313030253b6865696768743a313030253b626f726465723a303b646973706c61793a626c6f636b7d3c2f7374796c653e3c2f686561643e3c626f64793e3c696672616d652069643d2266223e3c2f696672616d653e3c7363726970743e0a286173796e6328293d3e7b636f6e737420523d22";
bytes internal constant P1 = hex"222e73706c697428222c22292c543d22";
bytes internal constant P2 = hex"222c493d";
bytes internal constant P3 = hex"2c483d22";
bytes internal constant P4 = hex"222c563d22";
bytes internal constant P5 = hex"222c443d22";
bytes internal constant P6 = hex"223b0a2f2f20612073747269637420616269206465636f64657220287265766965772076313220544d52572d5631322d3031293a2077686f6c65206865782062797465732c206120626f756e646564206f666673657420616e64206c656e6774682c2074686520626f647920696e736964652074686520616e7377657220616e6420756e6465722038204d69422c206265666f726520616e797468696e6720697320616c6c6f63617465642e0a2f2f207468652068657820636865636b206973206120706c61696e20636c61737320706c757320616e206576656e206c656e6774683a20612067726f75706564207175616e746966696572206f766572206120626f64792d73697a656420737472696e67206d616b657320536166617269277320656e67696e65206769766520757020616e6420616e737765722066616c736520286576657279206950686f6e652c20666f756e6420323032362d31302d3230290a636f6e737420423d28782c6d293d3e7b696628747970656f662078213d22737472696e67227c7c782e6c656e67746825327c7c212f5e30785b302d39612d66412d465d2a242f2e746573742878297c7c782e6c656e6774683c313330297468726f7720313b636f6e737420683d782e736c6963652832292c6f3d7061727365496e7428682e736c69636528302c3634292c3136293b69662821286f3e3d3332297c7c6f2533327c7c6f2a322b36343e682e6c656e677468297468726f7720313b636f6e7374206e3d7061727365496e7428682e736c696365286f2a322c6f2a322b3634292c3136293b69662821286e3e3d30297c7c6e3e6d7c7c286f2b33322b4d6174682e6365696c286e2f3332292a3332292a32213d682e6c656e677468297468726f7720313b636f6e737420623d6e65772055696e74384172726179286e293b666f72286c657420693d303b693c6e3b692b2b29625b695d3d7061727365496e7428682e73756273747228286f2b3332292a322b692a322c32292c3136293b72657475726e20627d3b0a2f2f2074686520616e737765722069732073747265616d6564207769746820612062756467657420283137204d69423a2074686520626f647920696e2068657820616e6420746865206a736f6e2061726f756e642069742920616e64206120646561646c696e65202833302073292c207468656e207061727365643b2061206e6f6465206f76657220656974686572206973206c65667420666f7220746865206e65787420287265766965772076313320544d52572d5631332d3031290a636f6e7374204a3d6173796e6328752c712c6d2c74293d3e7b636f6e737420613d6e65772041626f7274436f6e74726f6c6c657228292c6b3d73657454696d656f75742828293d3e612e61626f727428292c74293b7472797b636f6e737420723d617761697420666574636828752c7b6d6574686f643a22504f5354222c686561646572733a7b22636f6e74656e742d74797065223a226170706c69636174696f6e2f6a736f6e227d2c626f64793a712c7369676e616c3a612e7369676e616c7d292c643d722e626f64792e67657452656164657228292c703d5b5d3b6c6574206e3d303b666f72283b3b297b636f6e73747b646f6e652c76616c75657d3d617761697420642e7265616428293b696628646f6e6529627265616b3b6e2b3d76616c75652e6c656e6774683b6966286e3e6d297b642e63616e63656c28292e63617463682828293d3e7b7d293b7468726f7720317d702e707573682876616c7565297d636f6e737420623d6e65772055696e74384172726179286e293b6c6574206f3d303b666f7228636f6e73742078206f662070297b622e73657428782c6f293b6f2b3d782e6c656e6774687d72657475726e204a534f4e2e7061727365286e657720546578744465636f64657228292e6465636f6465286229297d66696e616c6c797b636c65617254696d656f7574286b297d7d3b0a2f2f2074686520706167652072756e732061732074686520617274697374206275696c742069743a20686973206f776e20626f786564206d6f646520646563696465732077686174206120736d616c6c206672616d652073686f7773202874686520636f70792d6c696e6b20627574746f6e2920616e6420776861740a2f2f20612066756c6c20766965772073686f77732028686973206b6579206d656e75292e2074686520766965776572206869646573206e6f7468696e67202850726f6e6f69612c20323032362d31302d31383b20756e74696c207468656e2061206c696e6520686572652068696420746865206d656e75290a636f6e737420686561643d273c21646f63747970652068746d6c3e3c68746d6c3e3c686561643e3c6d65746120636861727365743d227574662d38223e3c73637269707420646174612d6672616d652d7368696d3e2866756e6374696f6e28297b76617220423d22223b766172206162733d66756e6374696f6e2875297b7472797b6e65772055524c2875293b72657475726e20757d63617463682865297b72657475726e20423f6e65772055524c28537472696e672875292c42292e687265663a757d7d3b69662842297b766172206f3d584d4c48747470526571756573742e70726f746f747970652e6f70656e3b584d4c48747470526571756573742e70726f746f747970652e6f70656e3d66756e6374696f6e286d2c75297b76617220613d41727261792e70726f746f747970652e736c6963652e63616c6c28617267756d656e7473293b615b315d3d6162732875293b72657475726e206f2e6170706c7928746869732c61297d3b76617220663d77696e646f772e66657463683b77696e646f772e66657463683d66756e6374696f6e2875297b76617220613d41727261792e70726f746f747970652e736c6963652e63616c6c28617267756d656e7473293b696628747970656f6620753d3d3d22737472696e672229615b305d3d6162732875293b72657475726e20662e6170706c7928746869732c61297d7d76617220503d6c6f636174696f6e2e687265663b7472797b69662877696e646f772e706172656e74262677696e646f772e706172656e74213d3d77696e646f7729503d77696e646f772e706172656e742e6c6f636174696f6e2e687265667d63617463682865297b7d76617220544f503d66616c73653b7472797b544f503d77696e646f772e746f703d3d3d77696e646f772e706172656e747d63617463682865297b7d766172206f776e3d66756e6374696f6e28297b7472797b76617220743d77696e646f772e544f4b454e2c753d6e65772055524c2850293b696628742626742e69642626752e736561726368506172616d732e686173282269642229297b752e736561726368506172616d732e73657428226964222c537472696e6728742e696429293b72657475726e20752e687265667d696628742626742e7669657765722626742e69642972657475726e20742e7669657765722b742e69647d63617463682865297b7d72657475726e20507d3b7472797b7661722073703d4944424f626a65637453746f72652e70726f746f747970652e7075743b4944424f626a65637453746f72652e70726f746f747970652e7075743d66756e6374696f6e2876297b7472797b696628746869732e6e616d653d3d3d2273686f7473222626762626747970656f6620762e75726c3d3d3d22737472696e67222626762e6861736829762e75726c3d6f776e28297d63617463682865297b7d72657475726e2073702e6170706c7928746869732c617267756d656e7473297d7d63617463682865297b7d7472797b76617220643d4f626a6563742e6765744f776e50726f706572747944657363726970746f722848544d4c416e63686f72456c656d656e742e70726f746f747970652c226872656622293b696628642626642e736574294f626a6563742e646566696e6550726f70657274792848544d4c416e63686f72456c656d656e742e70726f746f747970652c2268726566222c7b636f6e666967757261626c653a747275652c656e756d657261626c653a642e656e756d657261626c652c6765743a642e6765742c7365743a66756e6374696f6e2876297b76617220733d537472696e672876293b7472797b6966282f5e68747470733f3a2f2e74657374287329297b6966282f5b3f265d686173683d2f2e74657374287329297b746869732e7461726765743d225f73656c66223b72657475726e20642e7365742e63616c6c28746869732c6c6f636174696f6e2e68726566297d76617220753d6e65772055524c2873292c703d6e65772055524c2850292c74763d77696e646f772e544f4b454e262677696e646f772e544f4b454e2e7669657765727c7c22223b696628752e736561726368506172616d732e6861732822696422292626752e686f73743d3d3d702e686f73742626752e706174686e616d653d3d3d702e706174686e616d65297b746869732e7461726765743d544f503f225f746f70223a225f626c616e6b223b69662821544f5029746869732e72656c3d226e6f6f70656e6572223b72657475726e20642e7365742e63616c6c28746869732c73297d69662874762626732e696e6465784f66287476293d3d3d30297b746869732e7461726765743d225f626c616e6b223b746869732e72656c3d226e6f6f70656e6572223b72657475726e20642e7365742e63616c6c28746869732c73297d7d656c736520696628422626732626732e636861724174283029213d3d2223222626212f5e5b612d7a412d5a5d5b612d7a412d5a302d392b2e2d5d2a3a2f2e74657374287329297b746869732e7461726765743d225f626c616e6b223b746869732e72656c3d226e6f6f70656e6572223b72657475726e20642e7365742e63616c6c28746869732c6e65772055524c28732c42292e68726566297d7d63617463682865297b7d72657475726e20642e7365742e63616c6c28746869732c76297d7d297d63617463682865297b7d7d2928293b3c5c2f7363726970743e3c7469746c653e546f6d6f72726f77733c2f7469746c653e3c7374796c653e68746d6c2c626f64797b6d617267696e3a303b6261636b67726f756e643a233030307d3c2f7374796c653e3c2f686561643e3c626f64793e3c7363726970743e76617220544f4b454e3d7b69643a272b492b272c686173683a22272b482b27222c7669657765723a22272b562b27227d3b3c5c2f7363726970743e3c7363726970743e273b0a6c6574207768793d2274686520636861696e20646964206e6f7420616e73776572223b0a666f7228636f6e73742075206f662052297b7472797b636f6e737420723d6177616974204a28752c4a534f4e2e737472696e67696679287b6a736f6e7270633a22322e30222c69643a312c6d6574686f643a226574685f63616c6c222c706172616d733a5b7b746f3a542c646174613a2230783336343439376534227d2c226c6174657374225d7d292c31373832353739322c3330303030293b6c657420623b7472797b623d4228722e726573756c742c38333838363038297d63617463682865297b7768793d2261206e6f64652073656e7420736f6d657468696e672074686174206973206e6f742074686520776f726b223b636f6e74696e75657d0a636f6e737420643d223078222b5b2e2e2e6e65772055696e743841727261792861776169742063727970746f2e737562746c652e64696765737428225348412d323536222c6229295d2e6d617028783d3e782e746f537472696e67283136292e706164537461727428322c22302229292e6a6f696e282222293b69662864213d3d44297b7768793d2261206e6f64652073656e7420736f6d657468696e672074686174206973206e6f742074686520776f726b223b636f6e74696e75657d0a646f63756d656e742e676574456c656d656e744279496428226622292e7372633d55524c2e6372656174654f626a65637455524c286e657720426c6f62285b686561642c625d2c7b747970653a22746578742f68746d6c227d29293b72657475726e7d63617463682865297b7d7d646f63756d656e742e626f64792e74657874436f6e74656e743d7768792b223b2074727920616761696e227d2928293b0a3c2f7363726970743e3c2f626f64793e3c2f68746d6c3e";
/// rpcs: a comma list of https addresses; nft: this contract, hex; id; hash: 0x…; viewer: an https
/// address or empty; digest: the sha-256 of body(), 0x…. the page fetches body() from the nodes,
/// hashes it and refuses anything but the digest, then writes the head itself from id, hash and viewer
function html(string calldata rpcs, string calldata nft, string calldata id, string calldata hash, string calldata viewer, string calldata digest) external pure returns (bytes memory) {
return abi.encodePacked(P0, rpcs, P1, nft, P2, id, P3, hash, P4, viewer, P5, digest, P6);
}
}
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.