Verified contractExactMIT
PerceptionLauncher
Address0xd4b942e908d8cea08ebbf4466620773ea5644893
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 1,000 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,998,264
- Creation transaction
- 0x0d711e573c…05fcb00c8b
3 files
- src/PerceptionLauncher.solmain6.61 KB
- ../rehearsal/src/Codec.sol4.09 KB
- src/PerceptionCodec.sol7.53 KB
src/PerceptionLauncher.sol
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 CypherDAO
/*******************************************************************************
___ ___ ___ ___ ___ ___
/ /\ /__/\ / /\ /__/\ _____ / /\ / /\
/ /:/ \ \:\ / /::\ | |::\ / /::\ / /:/_ / /::\
/ /:/ \__\:\ / /:/\:\ | |:|:\ / /:/\:\ / /:/ /\ / /:/\:\
/ /:/ ___ ___ / /::\ / /:/~/::\ __|__|:|\:\ / /:/~/::\ / /:/ /:/_ / /:/~/:/
/__/:/ / /\ /__/\ /:/\:\ /__/:/ /:/\:\ /__/::::| \:\ /__/:/ /:/\:| /__/:/ /:/ /\ /__/:/ /:/___
\ \:\ / /:/ \ \:\/:/__\/ \ \:\/:/__\/ \ \:\~~\__\/ \ \:\/:/~/:/ \ \:\/:/ /:/ \ \:\/:::::/
\ \:\ /:/ \ \::/ \ \::/ \ \:\ \ \::/ /:/ \ \::/ /:/ \ \::/~~~~
\ \:\/:/ \ \:\ \ \:\ \ \:\ \ \:\/:/ \ \:\/:/ \ \:\
\ \::/ \ \:\ \ \:\ \ \:\ \ \::/ \ \::/ \ \:\
\__\/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/
P E R C E P T I O N . C A N A R Y . B R A I N 0 2 5
Perception Chamber: the page, deployed on its own and pinned by the token.
*******************************************************************************/
pragma solidity 0.8.30;
import {Codec} from "rehearsal/Codec.sol";
import {PerceptionCodec} from "./PerceptionCodec.sol";
/// @title PerceptionLauncher - the page, assembled from immutable parts around the PRG, the brain and the lineage
/// @notice Adapted from the Launcher the PoC token and the Chamber use (rehearsal/src/Launcher.sol): the page is
/// head parts (the page's own head, then nopsta's four 2022 emulator blobs, referenced by address)
/// ‖ one script of embedded state ‖ tail parts. Perception Chamber's seam carries the PRG (as base64,
/// study J §3: a third smaller than hex in the page and in tokenURI; the page decodes it with atob),
/// the head brain (hex, 834 bytes), a bounded lineage summary and the modes; it carries NO `patch_hex` and the page must carry
/// no general-purpose PRG loader (no drop, no hold-to-load, no hidden loader): that mechanic is the
/// Chamber's and stays there. `prg()` and `prgWithBrain(id)` on the token are the exports.
/// Two commitments, as before: `contentManifestHash` says WHAT the renderer is made of (the part
/// code hashes, in order; no addresses, no chain id; what the token asserts); `manifestHash` says
/// WHERE this instance gets them. Nothing changes after construction.
contract PerceptionLauncher {
address[] public headParts;
address[] public tailParts;
bytes32 public immutable contentManifestHash;
bytes32 public immutable manifestHash;
string internal constant CONTENT_DOMAIN = "PERCEPTION_LAUNCHER_CONTENT_V1";
string internal constant INSTANCE_DOMAIN = "PERCEPTION_LAUNCHER_INSTANCE_V1";
constructor(address[] memory head_, address[] memory tail_) {
require(head_.length > 0, "empty head");
require(tail_.length > 0, "empty tail");
bytes32[] memory headHashes = new bytes32[](head_.length);
bytes32[] memory tailHashes = new bytes32[](tail_.length);
for (uint256 i = 0; i < head_.length; i++) { requireDataPart(head_[i]); headHashes[i] = head_[i].codehash; }
for (uint256 i = 0; i < tail_.length; i++) { requireDataPart(tail_[i]); tailHashes[i] = tail_[i].codehash; }
contentManifestHash = keccak256(abi.encode(CONTENT_DOMAIN, headHashes, tailHashes));
manifestHash = keccak256(abi.encode(INSTANCE_DOMAIN, block.chainid, head_, headHashes, tail_, tailHashes));
headParts = head_;
tailParts = tail_;
}
function headPartCount() external view returns (uint256) { return headParts.length; }
function tailPartCount() external view returns (uint256) { return tailParts.length; }
/// A data part must exist and start with the STOP byte; anything else is a deployment mistake that
/// must revert here, not at render time.
function requireDataPart(address part) internal view {
require(part != address(0), "part: zero address");
require(part.code.length > 1, "part: no data");
bytes memory first = new bytes(1);
assembly ("memory-safe") { extcodecopy(part, add(first, 0x20), 0, 1) }
require(first[0] == 0x00, "part: missing STOP prefix");
}
/// @notice the full page: head ‖ the embedded state ‖ tail
/// @param prg the frozen program, raw PRG bytes (embedded as base64)
/// @param brain the head brain, 834 bytes
/// @param lineage the bounded lineage summary, JSON (the token builds it)
/// @param modes the page's mode bits
function page(bytes memory prg, bytes memory brain, bytes memory lineage, uint256 modes) public view returns (string memory) {
return string(abi.encodePacked(
concatParts(headParts),
'<script>var prg_b64 ="', PerceptionCodec.base64(prg),
'";var brain_hex ="', Codec.hexString(brain),
'";var lineage = ', lineage,
';var modes = ', decimalString(modes),
";</script>",
concatParts(tailParts)
));
}
/// @notice the page as a data: URI, the shape an animation_url takes
function dataURI(bytes memory prg, bytes memory brain, bytes memory lineage, uint256 modes) external view returns (string memory) {
return string(PerceptionCodec.dataURI("data:text/html;base64,", bytes(page(prg, brain, lineage, modes))));
}
function concatParts(address[] memory parts) internal view returns (bytes memory out) {
uint256 total = 0;
for (uint256 i = 0; i < parts.length; i++) total += parts[i].code.length - 1;
out = new bytes(total);
uint256 cursor = 0;
for (uint256 i = 0; i < parts.length; i++) {
address part = parts[i];
uint256 size = part.code.length - 1;
assembly ("memory-safe") { extcodecopy(part, add(add(out, 0x20), cursor), 1, size) }
cursor += size;
}
}
function decimalString(uint256 v) internal pure returns (bytes memory b) {
if (v == 0) return "0";
uint256 n = v; uint256 len;
while (n > 0) { len++; n /= 10; }
b = new bytes(len);
while (v > 0) { b[--len] = bytes1(uint8(48 + v % 10)); v /= 10; }
}
}
../rehearsal/src/Codec.sol
// SPDX-License-Identifier: MIT
// Written from scratch for this deployment.
pragma solidity 0.8.30;
/// @title Codec — hex and base64, written for the eth_call envelope
/// @notice The previous plain-Solidity encoders contributed heavily to a
/// ~362M-gas tokenURI; these routines remove repeated
/// bounds-checked byte writes by writing through raw memory (the
/// standard technique, as in OpenZeppelin's Base64). Measured:
/// swapping only these encoders - nothing else changed in that
/// commit - took the full tokenURI call from ~362M to ~64M view
/// gas with byte-identical output. Proven bit-identical to the
/// reference implementations in test/Guards.t.sol, including
/// against the actual PRG and the actual assembled page.
library Codec {
/// Lowercase hex, two characters per input byte.
function hexString(bytes memory data) internal pure returns (bytes memory out) {
assembly ("memory-safe") {
let len := mload(data)
out := mload(0x40)
mstore(out, mul(len, 2))
let src := add(data, 0x20)
let dst := add(out, 0x20)
// "0123456789abcdef", left-aligned in one word
let table := 0x3031323334353637383961626364656600000000000000000000000000000000
let end := add(src, len)
for {} lt(src, end) { src := add(src, 1) } {
let b := byte(0, mload(src))
mstore8(dst, byte(shr(4, b), table))
mstore8(add(dst, 1), byte(and(b, 0x0f), table))
dst := add(dst, 2)
}
mstore(0x40, and(add(dst, 31), not(31)))
}
}
bytes internal constant B64_TABLE =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/// Standard RFC 4648 base64 with '=' padding. The main loop's MLOAD
/// physically reads 32 bytes and may reach past the logical end of
/// `data` (only the top 3 bytes participate in the result - the same
/// read-ahead OpenZeppelin's Base64 documents); the final partial
/// group uses explicit single-byte loads, so the OUTPUT never depends
/// on memory beyond the logical end of `data`.
function base64(bytes memory data) internal pure returns (bytes memory result) {
uint256 len = data.length;
if (len == 0) return result;
bytes memory table = B64_TABLE;
result = new bytes(4 * ((len + 2) / 3));
assembly ("memory-safe") {
let tablePtr := add(table, 0x20)
let src := add(data, 0x20)
let dst := add(result, 0x20)
let fullEnd := add(src, sub(len, mod(len, 3)))
for {} lt(src, fullEnd) { src := add(src, 3) } {
let input := shr(232, mload(src)) // the top 3 bytes
mstore8(dst, byte(0, mload(add(tablePtr, and(shr(18, input), 0x3f)))))
mstore8(add(dst, 1), byte(0, mload(add(tablePtr, and(shr(12, input), 0x3f)))))
mstore8(add(dst, 2), byte(0, mload(add(tablePtr, and(shr(6, input), 0x3f)))))
mstore8(add(dst, 3), byte(0, mload(add(tablePtr, and(input, 0x3f)))))
dst := add(dst, 4)
}
switch mod(len, 3)
case 1 {
let b0 := byte(0, mload(fullEnd))
mstore8(dst, byte(0, mload(add(tablePtr, shr(2, b0)))))
mstore8(add(dst, 1), byte(0, mload(add(tablePtr, and(shl(4, b0), 0x3f)))))
mstore8(add(dst, 2), 0x3d)
mstore8(add(dst, 3), 0x3d)
}
case 2 {
let b0 := byte(0, mload(fullEnd))
let b1 := byte(0, mload(add(fullEnd, 1)))
mstore8(dst, byte(0, mload(add(tablePtr, shr(2, b0)))))
mstore8(add(dst, 1), byte(0, mload(add(tablePtr, and(or(shl(4, b0), shr(4, b1)), 0x3f)))))
mstore8(add(dst, 2), byte(0, mload(add(tablePtr, and(shl(2, b1), 0x3f)))))
mstore8(add(dst, 3), 0x3d)
}
}
}
}
src/PerceptionCodec.sol
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 CypherDAO
/*******************************************************************************
___ ___ ___ ___ ___ ___
/ /\ /__/\ / /\ /__/\ _____ / /\ / /\
/ /:/ \ \:\ / /::\ | |::\ / /::\ / /:/_ / /::\
/ /:/ \__\:\ / /:/\:\ | |:|:\ / /:/\:\ / /:/ /\ / /:/\:\
/ /:/ ___ ___ / /::\ / /:/~/::\ __|__|:|\:\ / /:/~/::\ / /:/ /:/_ / /:/~/:/
/__/:/ / /\ /__/\ /:/\:\ /__/:/ /:/\:\ /__/::::| \:\ /__/:/ /:/\:| /__/:/ /:/ /\ /__/:/ /:/___
\ \:\ / /:/ \ \:\/:/__\/ \ \:\/:/__\/ \ \:\~~\__\/ \ \:\/:/~/:/ \ \:\/:/ /:/ \ \:\/:::::/
\ \:\ /:/ \ \::/ \ \::/ \ \:\ \ \::/ /:/ \ \::/ /:/ \ \::/~~~~
\ \:\/:/ \ \:\ \ \:\ \ \:\ \ \:\/:/ \ \:\/:/ \ \:\
\ \::/ \ \:\ \ \:\ \ \:\ \ \::/ \ \::/ \ \:\
\__\/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/
P E R C E P T I O N . C A N A R Y . B R A I N 0 2 5
Perception Chamber: base64 for the token's strings, an internal library compiled into the token and the launcher.
*******************************************************************************/
pragma solidity 0.8.30;
/// @title PerceptionCodec - base64 for the token's own strings, byte for byte the rehearsal codec's output
/// @notice Study K phase 2. The rehearsal's Codec.base64 (the PoC's, the Chamber's) writes one character at a
/// time through a table: measured at ~73 gas an input byte, it was two thirds of the tokenURI. This
/// encoder takes twenty-four input bytes at a time, spreads them into thirty-two six-bit lanes with
/// masks and shifts, maps every lane to its character with lane-parallel arithmetic, and writes the
/// thirty-two characters with one MSTORE; a data: URI is the prefix and the encoding in one
/// allocation, so nothing is copied to be prefixed. RFC 4648 with '=' padding, the same bytes as the
/// rehearsal codec on every input: test/PerceptionCodec.t.sol holds it there, on every length
/// residue, on fuzzed bytes and on the real page, program, image and JSON.
/// @dev The rehearsal codec is untouched and stays the oracle. Lane arithmetic, for the reviewer: a lane
/// holds v in 0..63; the character is v+65 (A..Z), v+71 (a..z), v-4 (0..9), 43 (+), 47 (/). With
/// ge(k) the per-lane 0/1 indicator of v >= k, the character is
/// v + 65 + 6*ge(26) + 3*ge(63) - 75*ge(52) - 15*ge(62): every lane's additions stay below 256 and
/// every lane's subtraction stays at or above zero, so no carry or borrow crosses a lane. ge(k) is
/// ((v + 128 - k) & 128) >> 7, which needs v + 128 - k < 256: true for v <= 63.
library PerceptionCodec {
/// @notice base64 of `data`, padded
function base64(bytes memory data) internal pure returns (bytes memory) {
return dataURI("", data);
}
/// @notice `prefix` followed by base64 of `data`, in one allocation
function dataURI(string memory prefix, bytes memory data) internal pure returns (bytes memory out) {
assembly ("memory-safe") {
// ---- the block transform: 32 bytes whose top 24 are input -> 32 characters
function enc(w) -> o {
// A. eight groups of 24 bits, packed at the top, into eight 32-bit slots (each group at the top of its slot)
// groups 4-7 down 32; then within each 128-bit half, groups 2-3 / 6-7 down 16; then within
// each 64-bit quarter, the odd group down 8
w := or(and(w, 0xffffffffffffffffffffffff0000000000000000000000000000000000000000),
shr(32, and(w, 0x000000000000000000000000ffffffffffffffffffffffff0000000000000000)))
w := or(and(w, 0xffffffffffff00000000000000000000ffffffffffff00000000000000000000),
shr(16, and(w, 0x000000000000ffffffffffff00000000000000000000ffffffffffff00000000)))
w := or(and(w, 0xffffff0000000000ffffff0000000000ffffff0000000000ffffff0000000000),
shr(8, and(w, 0x000000ffffff0000000000ffffff0000000000ffffff0000000000ffffff0000)))
// B. within every slot, the four 6-bit fields into four byte lanes
w := or(or(shr(2, and(w, 0xfc000000fc000000fc000000fc000000fc000000fc000000fc000000fc000000)),
shr(4, and(w, 0x03f0000003f0000003f0000003f0000003f0000003f0000003f0000003f00000))),
or(shr(6, and(w, 0x000fc000000fc000000fc000000fc000000fc000000fc000000fc000000fc000)),
shr(8, and(w, 0x00003f0000003f0000003f0000003f0000003f0000003f0000003f0000003f00))))
// C. every lane to its character (the arithmetic in the contract's notes)
let ge26 := shr(7, and(add(w, 0x6666666666666666666666666666666666666666666666666666666666666666), 0x8080808080808080808080808080808080808080808080808080808080808080))
let ge52 := shr(7, and(add(w, 0x4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c), 0x8080808080808080808080808080808080808080808080808080808080808080))
let ge62 := shr(7, and(add(w, 0x4242424242424242424242424242424242424242424242424242424242424242), 0x8080808080808080808080808080808080808080808080808080808080808080))
let ge63 := shr(7, and(add(w, 0x4141414141414141414141414141414141414141414141414141414141414141), 0x8080808080808080808080808080808080808080808080808080808080808080))
o := sub(add(add(w, 0x4141414141414141414141414141414141414141414141414141414141414141), add(mul(ge26, 6), mul(ge63, 3))),
add(mul(ge52, 75), mul(ge62, 15)))
}
let len := mload(data)
let plen := mload(prefix)
let encoded := mul(4, div(add(len, 2), 3))
let total := add(plen, encoded)
out := mload(0x40)
mstore(out, total)
let dst := add(out, 0x20)
mcopy(dst, add(prefix, 0x20), plen)
dst := add(dst, plen)
let src := add(data, 0x20)
// the full blocks: 24 bytes in, 32 characters out, one MSTORE each
let blockEnd := add(src, sub(len, mod(len, 24)))
for {} lt(src, blockEnd) { src := add(src, 24) dst := add(dst, 32) } {
mstore(dst, enc(mload(src)))
}
// the remainder: r bytes (0..23) zero-padded to a block, only its 4*ceil(r/3) characters kept,
// and '=' where the padding says so. The MSTORE reaches past the string's end into the word
// the free pointer below leaves clear.
let r := mod(len, 24)
if r {
mstore(dst, enc(and(mload(src), shl(mul(8, sub(32, r)), not(0)))))
let last := add(dst, mul(4, div(r, 3))) // the partial group's four characters, if any
switch mod(r, 3)
case 1 { mstore8(add(last, 2), 0x3d) mstore8(add(last, 3), 0x3d) }
case 2 { mstore8(add(last, 3), 0x3d) }
}
mstore(0x40, and(add(add(add(out, 0x40), total), 0x3f), not(0x1f)))
}
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 1000,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=../rehearsal/lib/forge-std/src/",
"rehearsal/=../rehearsal/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.