Verified contractExactMIT
CarnageStore
Address0x70fb26207119dee3a307d8a741a46c2e25ddf471
- Balance
0 ETH
- Transactions
463
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- 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
- 26,356,094
- Creation transaction
- 0x50f142183c…5398acf89a
2 files
- src/CarnageStore.solmain3.27 KB
- src/CarnageAdmin.sol1.87 KB
src/CarnageStore.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface ICarnageAdmin {
function owner() external view returns (address);
function backup() external view returns (address);
function refreshMetadata() external;
function totalMinted() external view returns (uint256);
function mintedAt(uint256 tokenId) external view returns (uint64);
}
import {CarnageAdmin} from "./CarnageAdmin.sol";
/// The NFT's backup wallet, to start a supporting contract with the same backup
/// (address(0) when there is no NFT yet or it does not say).
function _backupOf(address nft_) view returns (address b) {
if (nft_.code.length == 0) return address(0);
try ICarnageAdmin(nft_).backup() returns (address x) { b = x; } catch {}
}
/// Named files kept as SSTORE2 chunks: each chunk is a contract whose code is a
/// STOP byte followed by the data, read back with EXTCODECOPY. Two files are
/// used: "loader" (the packed artwork, stored already base64-encoded) and
/// "table" (the fight list, likewise). Both can be replaced at any time by the
/// store's owner or backup: clear() then append() again. A replaced file's old
/// chunks stay on chain, unreferenced.
///
/// The store has its OWN owner and backup (CarnageAdmin) and no link to the NFT at
/// all, so replacing the NFT never touches the store or the data in it (2 Nov 2026).
/// The constructor still takes the NFT's address, only to copy its backup wallet.
contract CarnageStore is CarnageAdmin {
error TooBig();
error WriteFailed();
event FileChanged(bytes32 indexed name, uint256 chunks, uint256 size);
mapping(bytes32 => address[]) private _chunks;
mapping(bytes32 => uint256) public size;
constructor(address nft_) CarnageAdmin(_backupOf(nft_)) {}
modifier onlyAdmin() {
_checkAdmin();
_;
}
function append(bytes32 name, bytes calldata data) external onlyAdmin {
if (data.length == 0 || data.length > 24575) revert TooBig();
// init code: PUSH2 len+1, DUP1, PUSH1 0x0a, RETURNDATASIZE, CODECOPY, RETURNDATASIZE, RETURN
// then the runtime code: 0x00 (STOP) + data
bytes memory init = abi.encodePacked(hex"61", uint16(data.length + 1), hex"80600a3d393df300", data);
address p;
assembly { p := create(0, add(init, 0x20), mload(init)) }
if (p == address(0)) revert WriteFailed();
_chunks[name].push(p);
size[name] += data.length;
emit FileChanged(name, _chunks[name].length, size[name]);
}
function clear(bytes32 name) external onlyAdmin {
delete _chunks[name];
size[name] = 0;
emit FileChanged(name, 0, 0);
}
function chunks(bytes32 name) external view returns (address[] memory) {
return _chunks[name];
}
/// The whole file (for checking; the renderer copies chunks itself).
function read(bytes32 name) external view returns (bytes memory out) {
address[] memory c = _chunks[name];
out = new bytes(size[name]);
uint256 at;
for (uint256 i; i < c.length; i++) {
address p = c[i];
uint256 n;
assembly { n := sub(extcodesize(p), 1) extcodecopy(p, add(add(out, 0x20), at), 1, n) }
at += n;
}
}
}
src/CarnageAdmin.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
/// Owner + backup for the collection's supporting contracts (store, renderer, still).
/// Each has its OWN owner rather than asking the NFT, so the NFT can be replaced or
/// re-pointed without these contracts losing their admin (Jim, 2 Nov 2026).
/// - owner: set to the deployer; changed by a two-step transfer (the new owner must
/// accept, so a typo cannot lose the contract)
/// - backup: a second wallet with the same admin rights, set by the owner
abstract contract CarnageAdmin {
error NotAdmin();
error NotOwner();
error NotPendingOwner();
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event BackupSet(address backup);
address public owner;
address public pendingOwner;
address public backup;
constructor(address backup_) {
owner = msg.sender;
backup = backup_;
emit OwnershipTransferred(address(0), msg.sender);
emit BackupSet(backup_);
}
modifier onlyOwner() {
if (msg.sender != owner) revert NotOwner();
_;
}
function _checkAdmin() internal view {
if (msg.sender != owner && msg.sender != backup) revert NotAdmin();
}
function setBackup(address backup_) external onlyOwner {
backup = backup_;
emit BackupSet(backup_);
}
function transferOwnership(address newOwner) external onlyOwner {
pendingOwner = newOwner;
emit OwnershipTransferStarted(owner, newOwner);
}
function acceptOwnership() external {
if (msg.sender != pendingOwner) revert NotPendingOwner();
emit OwnershipTransferred(owner, msg.sender);
owner = msg.sender;
pendingOwner = address(0);
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 1000,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"ERC721A/=lib/ERC721A/contracts/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"forge-std/=lib/forge-std/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.