Feature Tip: Add private address tag to any address under My Name Tag !
Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 20 from a total of 20 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Create File From... | 21425983 | 6 days ago | IN | 0 ETH | 0.00161208 | ||||
Create File From... | 21152714 | 44 days ago | IN | 0 ETH | 0.00202113 | ||||
Create File From... | 20769621 | 97 days ago | IN | 0 ETH | 0.00059793 | ||||
Create File From... | 20727773 | 103 days ago | IN | 0 ETH | 0.00062738 | ||||
Create File From... | 20533581 | 130 days ago | IN | 0 ETH | 0.00088212 | ||||
Create File | 19876081 | 222 days ago | IN | 0 ETH | 0.00274574 | ||||
Create File From... | 19842779 | 227 days ago | IN | 0 ETH | 0.00166852 | ||||
Create File From... | 19678596 | 250 days ago | IN | 0 ETH | 0.00293036 | ||||
Create File From... | 19072461 | 335 days ago | IN | 0 ETH | 0.00173126 | ||||
Create File From... | 19072459 | 335 days ago | IN | 0 ETH | 0.00345734 | ||||
Create File From... | 19072458 | 335 days ago | IN | 0 ETH | 0.00289117 | ||||
Create File From... | 19072454 | 335 days ago | IN | 0 ETH | 0.00487553 | ||||
Create File From... | 19068447 | 335 days ago | IN | 0 ETH | 0.00297364 | ||||
Create File From... | 19068436 | 335 days ago | IN | 0 ETH | 0.00272638 | ||||
Create File From... | 19061984 | 336 days ago | IN | 0 ETH | 0.00436903 | ||||
Create File From... | 19056547 | 337 days ago | IN | 0 ETH | 0.02147482 | ||||
Create File From... | 19056136 | 337 days ago | IN | 0 ETH | 0.00904731 | ||||
Create File From... | 19056130 | 337 days ago | IN | 0 ETH | 0.00293981 | ||||
Create File From... | 19051576 | 338 days ago | IN | 0 ETH | 0.00883484 | ||||
Create File From... | 18947499 | 352 days ago | IN | 0 ETH | 0.00220747 |
Latest 1 internal transaction
Advanced mode:
Parent Transaction Hash | Block |
From
|
To
|
|||
---|---|---|---|---|---|---|
18898263 | 359 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
FileStore
Compiler Version
v0.8.23+commit.f704f362
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.22; import {SSTORE2} from "solady/utils/SSTORE2.sol"; import {LibString} from "solady/utils/LibString.sol"; import {IFileStore} from "./IFileStore.sol"; import {File, BytecodeSlice, SliceOutOfBounds} from "./File.sol"; import {addContent, isValidPointer} from "./common.sol"; /** * @title EthFS FileStore * @notice Content-addressable file storage for Ethereum. Files are composed of slices of contract bytecode, the most efficient way to store and retrieve data onchain. */ contract FileStore is IFileStore { /** * @dev The address of the CREATE2 deterministic deployer */ address public immutable deployer; /** * @dev Mapping of filenames to their respective SSTORE2 pointer where the ABI-encoded File lives */ mapping(string filename => address pointer) public files; /** * * @param _deployer The address of the deterministic CREATE2 deployer */ constructor(address _deployer) { deployer = _deployer; emit Deployed(); } /** * @notice Checks if a file exists for a given filename * @param filename The name of the file to check * @return True if the file exists, false otherwise */ function fileExists(string memory filename) public view returns (bool) { return files[filename] != address(0); } /** * @notice Retrieves the pointer address for a given filename * @param filename The name of the file * @return pointer The pointer address of the file */ function getPointer( string memory filename ) public view returns (address pointer) { pointer = files[filename]; if (pointer == address(0)) { revert FileNotFound(filename); } return pointer; } /** * @notice Retrieves a file by its filename * @param filename The name of the file * @return file The file associated with the filename */ function getFile( string memory filename ) public view returns (File memory file) { address pointer = files[filename]; if (pointer == address(0)) { revert FileNotFound(filename); } return abi.decode(SSTORE2.read(pointer), (File)); } /** * @notice Creates a new file with the provided file contents * @dev This is a convenience method to simplify small file uploads. It's recommended to use `createFileFromPointers` or `createFileFromSlices` for larger files. This particular method splits `contents` into 24575-byte chunks before storing them via SSTORE2. * @param filename The name of the new file * @param contents The contents of the file * @return pointer The pointer address of the new file * @return file The newly created file */ function createFile( string memory filename, string memory contents ) public returns (address pointer, File memory file) { return _createFile(filename, _fileFromContents(contents), new bytes(0)); } /** * @notice Creates a new file with the provided file contents and file metadata * @dev This is a convenience method to simplify small file uploads. It's recommended to use `createFileFromPointers` or `createFileFromSlices` for larger files. This particular method splits `contents` into 24575-byte chunks before storing them via SSTORE2. * @param filename The name of the new file * @param contents The contents of the file * @param metadata Additional file metadata, usually a JSON-encoded string, for offchain indexers * @return pointer The pointer address of the new file * @return file The newly created file */ function createFile( string memory filename, string memory contents, bytes memory metadata ) public returns (address pointer, File memory file) { return _createFile(filename, _fileFromContents(contents), metadata); } /** * @notice Creates a new file where its content is composed of the provided string chunks * @dev This is a convenience method to simplify small and nuanced file uploads. It's recommended to use `createFileFromPointers` or `createFileFromSlices` for larger files. This particular will store each chunk separately via SSTORE2. For best gas efficiency, each chunk should be as large as possible (up to the contract size limit) and at least 32 bytes. * @param filename The name of the new file * @param chunks The string chunks composing the file * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromChunks( string memory filename, string[] memory chunks ) public returns (address pointer, File memory file) { return _createFile(filename, _fileFromChunks(chunks), new bytes(0)); } /** * @notice Creates a new file with the provided string chunks and file metadata * @dev This is a convenience method to simplify small and nuanced file uploads. It's recommended to use `createFileFromPointers` or `createFileFromSlices` for larger files. This particular will store each chunk separately via SSTORE2. For best gas efficiency, each chunk should be as large as possible (up to the contract size limit) and at least 32 bytes. * @param filename The name of the new file * @param chunks The string chunks composing the file * @param metadata Additional file metadata, usually a JSON-encoded string, for offchain indexers * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromChunks( string memory filename, string[] memory chunks, bytes memory metadata ) public returns (address pointer, File memory file) { return _createFile(filename, _fileFromChunks(chunks), metadata); } /** * @notice Creates a new file where its content is composed of the provided SSTORE2 pointers * @param filename The name of the new file * @param pointers The SSTORE2 pointers composing the file * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromPointers( string memory filename, address[] memory pointers ) public returns (address pointer, File memory file) { return _createFile(filename, _fileFromPointers(pointers), new bytes(0)); } /** * @notice Creates a new file with the provided SSTORE2 pointers and file metadata * @param filename The name of the new file * @param pointers The SSTORE2 pointers composing the file * @param metadata Additional file metadata, usually a JSON-encoded string, for offchain indexers * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromPointers( string memory filename, address[] memory pointers, bytes memory metadata ) public returns (address pointer, File memory file) { return _createFile(filename, _fileFromPointers(pointers), metadata); } /** * @notice Creates a new file where its content is composed of the provided bytecode slices * @param filename The name of the new file * @param slices The bytecode slices composing the file * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromSlices( string memory filename, BytecodeSlice[] memory slices ) public returns (address pointer, File memory file) { return _createFile(filename, _fileFromSlices(slices), new bytes(0)); } /** * @notice Creates a new file with the provided bytecode slices and file metadata * @param filename The name of the new file * @param slices The bytecode slices composing the file * @param metadata Additional file metadata, usually a JSON-encoded string, for offchain indexers * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromSlices( string memory filename, BytecodeSlice[] memory slices, bytes memory metadata ) public returns (address pointer, File memory file) { return _createFile(filename, _fileFromSlices(slices), metadata); } /** * @dev Internal function for preparing a file from its contents */ function _fileFromContents( string memory contents ) internal returns (File memory file) { uint256 size = bytes(contents).length; uint256 chunkSize = 0x6000 - 1; uint256 numChunks = (size + chunkSize - 1) / chunkSize; string[] memory chunks = new string[](numChunks); for (uint256 i = 0; i < numChunks; ++i) { uint256 start = i * chunkSize; uint256 end = start + chunkSize > size ? size : start + chunkSize; chunks[i] = LibString.slice(contents, start, end); } return _fileFromChunks(chunks); } /** * @dev Internal function for preparing a file from its chunks */ function _fileFromChunks( string[] memory chunks ) internal returns (File memory file) { uint256 size = 0; BytecodeSlice[] memory slices = new BytecodeSlice[](chunks.length); for (uint256 i = 0; i < chunks.length; ++i) { slices[i].pointer = addContent(deployer, bytes(chunks[i])); slices[i].start = uint32(SSTORE2.DATA_OFFSET); slices[i].end = uint32( SSTORE2.DATA_OFFSET + bytes(chunks[i]).length ); size += slices[i].end - slices[i].start; } return File({size: size, slices: slices}); } /** * @dev Internal function for preparing a file from its pointers */ function _fileFromPointers( address[] memory pointers ) internal view returns (File memory file) { uint256 size = 0; BytecodeSlice[] memory slices = new BytecodeSlice[](pointers.length); for (uint256 i = 0; i < pointers.length; ++i) { if (!isValidPointer(pointers[i])) { revert InvalidPointer(pointers[i]); } slices[i].pointer = pointers[i]; slices[i].start = uint32(SSTORE2.DATA_OFFSET); slices[i].end = uint32(pointers[i].code.length); size += slices[i].end - slices[i].start; } return File({size: size, slices: slices}); } /** * @dev Internal function for preparing a file from its slices */ function _fileFromSlices( BytecodeSlice[] memory slices ) internal view returns (File memory file) { uint256 size = 0; for (uint256 i = 0; i < slices.length; ++i) { if (slices[i].end - slices[i].start <= 0) { revert SliceEmpty( slices[i].pointer, slices[i].start, slices[i].end ); } uint32 codeSize = uint32(slices[i].pointer.code.length); if (slices[i].end > codeSize) { revert SliceOutOfBounds( slices[i].pointer, codeSize, slices[i].start, slices[i].end ); } size += slices[i].end - slices[i].start; } return File({size: size, slices: slices}); } /** * @dev Internal function for creating a file */ function _createFile( string memory filename, File memory file, bytes memory metadata ) internal returns (address pointer, File memory) { if (file.size == 0) { revert FileEmpty(); } if (files[filename] != address(0)) { revert FilenameExists(filename); } pointer = addContent(deployer, abi.encode(file)); files[filename] = pointer; emit FileCreated(filename, pointer, filename, file.size, metadata); return (pointer, file); } /** * @notice Convenience method for reading files in frontends and indexers where libraries are not accessible. * @dev This method is intentionally left out of the `IFileStore` interface. * Contracts should use `File.read()` directly, rather than this method. Otherwise you will incur unnecessary gas for passing around large byte blobs. * @param filename The name of the file to read * @return contents The contents of the file */ function readFile( string memory filename ) public view returns (string memory contents) { return getFile(filename).read(); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Read and write to persistent storage at a fraction of the cost. /// @author Solady (https://github.com/vectorized/solmady/blob/main/src/utils/SSTORE2.sol) /// @author Saw-mon-and-Natalie (https://github.com/Saw-mon-and-Natalie) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SSTORE2.sol) /// @author Modified from 0xSequence (https://github.com/0xSequence/sstore2/blob/master/contracts/SSTORE2.sol) library SSTORE2 { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev We skip the first byte as it's a STOP opcode, /// which ensures the contract can't be called. uint256 internal constant DATA_OFFSET = 1; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Unable to deploy the storage contract. error DeploymentFailed(); /// @dev The storage contract address is invalid. error InvalidPointer(); /// @dev Attempt to read outside of the storage contract's bytecode bounds. error ReadOutOfBounds(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* WRITE LOGIC */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Writes `data` into the bytecode of a storage contract and returns its address. function write(bytes memory data) internal returns (address pointer) { /// @solidity memory-safe-assembly assembly { let originalDataLength := mload(data) // Add 1 to data size since we are prefixing it with a STOP opcode. let dataSize := add(originalDataLength, DATA_OFFSET) /** * ------------------------------------------------------------------------------+ * Opcode | Mnemonic | Stack | Memory | * ------------------------------------------------------------------------------| * 61 dataSize | PUSH2 dataSize | dataSize | | * 80 | DUP1 | dataSize dataSize | | * 60 0xa | PUSH1 0xa | 0xa dataSize dataSize | | * 3D | RETURNDATASIZE | 0 0xa dataSize dataSize | | * 39 | CODECOPY | dataSize | [0..dataSize): code | * 3D | RETURNDATASIZE | 0 dataSize | [0..dataSize): code | * F3 | RETURN | | [0..dataSize): code | * 00 | STOP | | | * ------------------------------------------------------------------------------+ * @dev Prefix the bytecode with a STOP opcode to ensure it cannot be called. * Also PUSH2 is used since max contract size cap is 24,576 bytes which is less than 2 ** 16. */ mstore( // Do a out-of-gas revert if `dataSize` is more than 2 bytes. // The actual EVM limit may be smaller and may change over time. add(data, gt(dataSize, 0xffff)), // Left shift `dataSize` by 64 so that it lines up with the 0000 after PUSH2. or(0xfd61000080600a3d393df300, shl(0x40, dataSize)) ) // Deploy a new contract with the generated creation code. pointer := create(0, add(data, 0x15), add(dataSize, 0xa)) // If `pointer` is zero, revert. if iszero(pointer) { // Store the function selector of `DeploymentFailed()`. mstore(0x00, 0x30116425) // Revert with (offset, size). revert(0x1c, 0x04) } // Restore original length of the variable size `data`. mstore(data, originalDataLength) } } /// @dev Writes `data` into the bytecode of a storage contract with `salt` /// and returns its deterministic address. function writeDeterministic(bytes memory data, bytes32 salt) internal returns (address pointer) { /// @solidity memory-safe-assembly assembly { let originalDataLength := mload(data) let dataSize := add(originalDataLength, DATA_OFFSET) mstore( // Do a out-of-gas revert if `dataSize` is more than 2 bytes. // The actual EVM limit may be smaller and may change over time. add(data, gt(dataSize, 0xffff)), // Left shift `dataSize` by 64 so that it lines up with the 0000 after PUSH2. or(0xfd61000080600a3d393df300, shl(0x40, dataSize)) ) // Deploy a new contract with the generated creation code. pointer := create2(0, add(data, 0x15), add(dataSize, 0xa), salt) // If `pointer` is zero, revert. if iszero(pointer) { // Store the function selector of `DeploymentFailed()`. mstore(0x00, 0x30116425) // Revert with (offset, size). revert(0x1c, 0x04) } // Restore original length of the variable size `data`. mstore(data, originalDataLength) } } /// @dev Returns the initialization code hash of the storage contract for `data`. /// Used for mining vanity addresses with create2crunch. function initCodeHash(bytes memory data) internal pure returns (bytes32 hash) { /// @solidity memory-safe-assembly assembly { let originalDataLength := mload(data) let dataSize := add(originalDataLength, DATA_OFFSET) // Do a out-of-gas revert if `dataSize` is more than 2 bytes. // The actual EVM limit may be smaller and may change over time. returndatacopy(returndatasize(), returndatasize(), shr(16, dataSize)) mstore(data, or(0x61000080600a3d393df300, shl(0x40, dataSize))) hash := keccak256(add(data, 0x15), add(dataSize, 0xa)) // Restore original length of the variable size `data`. mstore(data, originalDataLength) } } /// @dev Returns the address of the storage contract for `data` /// deployed with `salt` by `deployer`. /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly. function predictDeterministicAddress(bytes memory data, bytes32 salt, address deployer) internal pure returns (address predicted) { bytes32 hash = initCodeHash(data); /// @solidity memory-safe-assembly assembly { // Compute and store the bytecode hash. mstore8(0x00, 0xff) // Write the prefix. mstore(0x35, hash) mstore(0x01, shl(96, deployer)) mstore(0x15, salt) predicted := keccak256(0x00, 0x55) // Restore the part of the free memory pointer that has been overwritten. mstore(0x35, 0) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* READ LOGIC */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns all the `data` from the bytecode of the storage contract at `pointer`. function read(address pointer) internal view returns (bytes memory data) { /// @solidity memory-safe-assembly assembly { let pointerCodesize := extcodesize(pointer) if iszero(pointerCodesize) { // Store the function selector of `InvalidPointer()`. mstore(0x00, 0x11052bb4) // Revert with (offset, size). revert(0x1c, 0x04) } // Offset all indices by 1 to skip the STOP opcode. let size := sub(pointerCodesize, DATA_OFFSET) // Get the pointer to the free memory and allocate // enough 32-byte words for the data and the length of the data, // then copy the code to the allocated memory. // Masking with 0xffe0 will suffice, since contract size is less than 16 bits. data := mload(0x40) mstore(0x40, add(data, and(add(size, 0x3f), 0xffe0))) mstore(data, size) mstore(add(add(data, 0x20), size), 0) // Zeroize the last slot. extcodecopy(pointer, add(data, 0x20), DATA_OFFSET, size) } } /// @dev Returns the `data` from the bytecode of the storage contract at `pointer`, /// from the byte at `start`, to the end of the data stored. function read(address pointer, uint256 start) internal view returns (bytes memory data) { /// @solidity memory-safe-assembly assembly { let pointerCodesize := extcodesize(pointer) if iszero(pointerCodesize) { // Store the function selector of `InvalidPointer()`. mstore(0x00, 0x11052bb4) // Revert with (offset, size). revert(0x1c, 0x04) } // If `!(pointer.code.size > start)`, reverts. // This also handles the case where `start + DATA_OFFSET` overflows. if iszero(gt(pointerCodesize, start)) { // Store the function selector of `ReadOutOfBounds()`. mstore(0x00, 0x84eb0dd1) // Revert with (offset, size). revert(0x1c, 0x04) } let size := sub(pointerCodesize, add(start, DATA_OFFSET)) // Get the pointer to the free memory and allocate // enough 32-byte words for the data and the length of the data, // then copy the code to the allocated memory. // Masking with 0xffe0 will suffice, since contract size is less than 16 bits. data := mload(0x40) mstore(0x40, add(data, and(add(size, 0x3f), 0xffe0))) mstore(data, size) mstore(add(add(data, 0x20), size), 0) // Zeroize the last slot. extcodecopy(pointer, add(data, 0x20), add(start, DATA_OFFSET), size) } } /// @dev Returns the `data` from the bytecode of the storage contract at `pointer`, /// from the byte at `start`, to the byte at `end` (exclusive) of the data stored. function read(address pointer, uint256 start, uint256 end) internal view returns (bytes memory data) { /// @solidity memory-safe-assembly assembly { let pointerCodesize := extcodesize(pointer) if iszero(pointerCodesize) { // Store the function selector of `InvalidPointer()`. mstore(0x00, 0x11052bb4) // Revert with (offset, size). revert(0x1c, 0x04) } // If `!(pointer.code.size > end) || (start > end)`, revert. // This also handles the cases where // `end + DATA_OFFSET` or `start + DATA_OFFSET` overflows. if iszero( and( gt(pointerCodesize, end), // Within bounds. iszero(gt(start, end)) // Valid range. ) ) { // Store the function selector of `ReadOutOfBounds()`. mstore(0x00, 0x84eb0dd1) // Revert with (offset, size). revert(0x1c, 0x04) } let size := sub(end, start) // Get the pointer to the free memory and allocate // enough 32-byte words for the data and the length of the data, // then copy the code to the allocated memory. // Masking with 0xffe0 will suffice, since contract size is less than 16 bits. data := mload(0x40) mstore(0x40, add(data, and(add(size, 0x3f), 0xffe0))) mstore(data, size) mstore(add(add(data, 0x20), size), 0) // Zeroize the last slot. extcodecopy(pointer, add(data, 0x20), add(start, DATA_OFFSET), size) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Library for converting numbers into strings and other string operations. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibString.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/LibString.sol) library LibString { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The `length` of the output is too small to contain all the hex digits. error HexLengthInsufficient(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The constant returned when the `search` is not found in the string. uint256 internal constant NOT_FOUND = type(uint256).max; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* DECIMAL OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the base 10 decimal representation of `value`. function toString(uint256 value) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { // The maximum value of a uint256 contains 78 digits (1 byte per digit), but // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned. // We will need 1 word for the trailing zeros padding, 1 word for the length, // and 3 words for a maximum of 78 digits. str := add(mload(0x40), 0x80) // Update the free memory pointer to allocate. mstore(0x40, add(str, 0x20)) // Zeroize the slot after the string. mstore(str, 0) // Cache the end of the memory to calculate the length later. let end := str let w := not(0) // Tsk. // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for { let temp := value } 1 {} { str := add(str, w) // `sub(str, 1)`. // Write the character to the pointer. // The ASCII index of the '0' character is 48. mstore8(str, add(48, mod(temp, 10))) // Keep dividing `temp` until zero. temp := div(temp, 10) if iszero(temp) { break } } let length := sub(end, str) // Move the pointer 32 bytes leftwards to make room for the length. str := sub(str, 0x20) // Store the length. mstore(str, length) } } /// @dev Returns the base 10 decimal representation of `value`. function toString(int256 value) internal pure returns (string memory str) { if (value >= 0) { return toString(uint256(value)); } unchecked { str = toString(uint256(-value)); } /// @solidity memory-safe-assembly assembly { // We still have some spare memory space on the left, // as we have allocated 3 words (96 bytes) for up to 78 digits. let length := mload(str) // Load the string length. mstore(str, 0x2d) // Store the '-' character. str := sub(str, 1) // Move back the string pointer by a byte. mstore(str, add(length, 1)) // Update the string length. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HEXADECIMAL OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the hexadecimal representation of `value`, /// left-padded to an input length of `length` bytes. /// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte, /// giving a total length of `length * 2 + 2` bytes. /// Reverts if `length` is too small for the output to contain all the digits. function toHexString(uint256 value, uint256 length) internal pure returns (string memory str) { str = toHexStringNoPrefix(value, length); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Write the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Write the length. } } /// @dev Returns the hexadecimal representation of `value`, /// left-padded to an input length of `length` bytes. /// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte, /// giving a total length of `length * 2` bytes. /// Reverts if `length` is too small for the output to contain all the digits. function toHexStringNoPrefix(uint256 value, uint256 length) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { // We need 0x20 bytes for the trailing zeros padding, `length * 2` bytes // for the digits, 0x02 bytes for the prefix, and 0x20 bytes for the length. // We add 0x20 to the total and round down to a multiple of 0x20. // (0x20 + 0x20 + 0x02 + 0x20) = 0x62. str := add(mload(0x40), and(add(shl(1, length), 0x42), not(0x1f))) // Allocate the memory. mstore(0x40, add(str, 0x20)) // Zeroize the slot after the string. mstore(str, 0) // Cache the end to calculate the length later. let end := str // Store "0123456789abcdef" in scratch space. mstore(0x0f, 0x30313233343536373839616263646566) let start := sub(str, add(length, length)) let w := not(1) // Tsk. let temp := value // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for {} 1 {} { str := add(str, w) // `sub(str, 2)`. mstore8(add(str, 1), mload(and(temp, 15))) mstore8(str, mload(and(shr(4, temp), 15))) temp := shr(8, temp) if iszero(xor(str, start)) { break } } if temp { // Store the function selector of `HexLengthInsufficient()`. mstore(0x00, 0x2194895a) // Revert with (offset, size). revert(0x1c, 0x04) } // Compute the string's length. let strLength := sub(end, str) // Move the pointer and write the length. str := sub(str, 0x20) mstore(str, strLength) } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte. /// As address are 20 bytes long, the output will left-padded to have /// a length of `20 * 2 + 2` bytes. function toHexString(uint256 value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Write the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Write the length. } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x". /// The output excludes leading "0" from the `toHexString` output. /// `0x00: "0x0", 0x01: "0x1", 0x12: "0x12", 0x123: "0x123"`. function toMinimalHexString(uint256 value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present. let strLength := add(mload(str), 2) // Compute the length. mstore(add(str, o), 0x3078) // Write the "0x" prefix, accounting for leading zero. str := sub(add(str, o), 2) // Move the pointer, accounting for leading zero. mstore(str, sub(strLength, o)) // Write the length, accounting for leading zero. } } /// @dev Returns the hexadecimal representation of `value`. /// The output excludes leading "0" from the `toHexStringNoPrefix` output. /// `0x00: "0", 0x01: "1", 0x12: "12", 0x123: "123"`. function toMinimalHexStringNoPrefix(uint256 value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present. let strLength := mload(str) // Get the length. str := add(str, o) // Move the pointer, accounting for leading zero. mstore(str, sub(strLength, o)) // Write the length, accounting for leading zero. } } /// @dev Returns the hexadecimal representation of `value`. /// The output is encoded using 2 hexadecimal digits per byte. /// As address are 20 bytes long, the output will left-padded to have /// a length of `20 * 2` bytes. function toHexStringNoPrefix(uint256 value) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length, // 0x02 bytes for the prefix, and 0x40 bytes for the digits. // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x40) is 0xa0. str := add(mload(0x40), 0x80) // Allocate the memory. mstore(0x40, add(str, 0x20)) // Zeroize the slot after the string. mstore(str, 0) // Cache the end to calculate the length later. let end := str // Store "0123456789abcdef" in scratch space. mstore(0x0f, 0x30313233343536373839616263646566) let w := not(1) // Tsk. // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for { let temp := value } 1 {} { str := add(str, w) // `sub(str, 2)`. mstore8(add(str, 1), mload(and(temp, 15))) mstore8(str, mload(and(shr(4, temp), 15))) temp := shr(8, temp) if iszero(temp) { break } } // Compute the string's length. let strLength := sub(end, str) // Move the pointer and write the length. str := sub(str, 0x20) mstore(str, strLength) } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x", encoded using 2 hexadecimal digits per byte, /// and the alphabets are capitalized conditionally according to /// https://eips.ethereum.org/EIPS/eip-55 function toHexStringChecksummed(address value) internal pure returns (string memory str) { str = toHexString(value); /// @solidity memory-safe-assembly assembly { let mask := shl(6, div(not(0), 255)) // `0b010000000100000000 ...` let o := add(str, 0x22) let hashed := and(keccak256(o, 40), mul(34, mask)) // `0b10001000 ... ` let t := shl(240, 136) // `0b10001000 << 240` for { let i := 0 } 1 {} { mstore(add(i, i), mul(t, byte(i, hashed))) i := add(i, 1) if eq(i, 20) { break } } mstore(o, xor(mload(o), shr(1, and(mload(0x00), and(mload(o), mask))))) o := add(o, 0x20) mstore(o, xor(mload(o), shr(1, and(mload(0x20), and(mload(o), mask))))) } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte. function toHexString(address value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Write the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Write the length. } } /// @dev Returns the hexadecimal representation of `value`. /// The output is encoded using 2 hexadecimal digits per byte. function toHexStringNoPrefix(address value) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { str := mload(0x40) // Allocate the memory. // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length, // 0x02 bytes for the prefix, and 0x28 bytes for the digits. // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x28) is 0x80. mstore(0x40, add(str, 0x80)) // Store "0123456789abcdef" in scratch space. mstore(0x0f, 0x30313233343536373839616263646566) str := add(str, 2) mstore(str, 40) let o := add(str, 0x20) mstore(add(o, 40), 0) value := shl(96, value) // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for { let i := 0 } 1 {} { let p := add(o, add(i, i)) let temp := byte(i, value) mstore8(add(p, 1), mload(and(temp, 15))) mstore8(p, mload(shr(4, temp))) i := add(i, 1) if eq(i, 20) { break } } } } /// @dev Returns the hex encoded string from the raw bytes. /// The output is encoded using 2 hexadecimal digits per byte. function toHexString(bytes memory raw) internal pure returns (string memory str) { str = toHexStringNoPrefix(raw); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Write the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Write the length. } } /// @dev Returns the hex encoded string from the raw bytes. /// The output is encoded using 2 hexadecimal digits per byte. function toHexStringNoPrefix(bytes memory raw) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { let length := mload(raw) str := add(mload(0x40), 2) // Skip 2 bytes for the optional prefix. mstore(str, add(length, length)) // Store the length of the output. // Store "0123456789abcdef" in scratch space. mstore(0x0f, 0x30313233343536373839616263646566) let o := add(str, 0x20) let end := add(raw, length) for {} iszero(eq(raw, end)) {} { raw := add(raw, 1) mstore8(add(o, 1), mload(and(mload(raw), 15))) mstore8(o, mload(and(shr(4, mload(raw)), 15))) o := add(o, 2) } mstore(o, 0) // Zeroize the slot after the string. mstore(0x40, add(o, 0x20)) // Allocate the memory. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* RUNE STRING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the number of UTF characters in the string. function runeCount(string memory s) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { if mload(s) { mstore(0x00, div(not(0), 255)) mstore(0x20, 0x0202020202020202020202020202020202020202020202020303030304040506) let o := add(s, 0x20) let end := add(o, mload(s)) for { result := 1 } 1 { result := add(result, 1) } { o := add(o, byte(0, mload(shr(250, mload(o))))) if iszero(lt(o, end)) { break } } } } } /// @dev Returns if this string is a 7-bit ASCII string. /// (i.e. all characters codes are in [0..127]) function is7BitASCII(string memory s) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let mask := shl(7, div(not(0), 255)) result := 1 let n := mload(s) if n { let o := add(s, 0x20) let end := add(o, n) let last := mload(end) mstore(end, 0) for {} 1 {} { if and(mask, mload(o)) { result := 0 break } o := add(o, 0x20) if iszero(lt(o, end)) { break } } mstore(end, last) } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* BYTE STRING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // For performance and bytecode compactness, all indices of the following operations // are byte (ASCII) offsets, not UTF character offsets. /// @dev Returns `subject` all occurrences of `search` replaced with `replacement`. function replace(string memory subject, string memory search, string memory replacement) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) let searchLength := mload(search) let replacementLength := mload(replacement) subject := add(subject, 0x20) search := add(search, 0x20) replacement := add(replacement, 0x20) result := add(mload(0x40), 0x20) let subjectEnd := add(subject, subjectLength) if iszero(gt(searchLength, subjectLength)) { let subjectSearchEnd := add(sub(subjectEnd, searchLength), 1) let h := 0 if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) } let m := shl(3, sub(0x20, and(searchLength, 0x1f))) let s := mload(search) for {} 1 {} { let t := mload(subject) // Whether the first `searchLength % 32` bytes of // `subject` and `search` matches. if iszero(shr(m, xor(t, s))) { if h { if iszero(eq(keccak256(subject, searchLength), h)) { mstore(result, t) result := add(result, 1) subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } continue } } // Copy the `replacement` one word at a time. for { let o := 0 } 1 {} { mstore(add(result, o), mload(add(replacement, o))) o := add(o, 0x20) if iszero(lt(o, replacementLength)) { break } } result := add(result, replacementLength) subject := add(subject, searchLength) if searchLength { if iszero(lt(subject, subjectSearchEnd)) { break } continue } } mstore(result, t) result := add(result, 1) subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } } } let resultRemainder := result result := add(mload(0x40), 0x20) let k := add(sub(resultRemainder, result), sub(subjectEnd, subject)) // Copy the rest of the string one word at a time. for {} lt(subject, subjectEnd) {} { mstore(resultRemainder, mload(subject)) resultRemainder := add(resultRemainder, 0x20) subject := add(subject, 0x20) } result := sub(result, 0x20) let last := add(add(result, 0x20), k) // Zeroize the slot after the string. mstore(last, 0) mstore(0x40, add(last, 0x20)) // Allocate the memory. mstore(result, k) // Store the length. } } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from left to right, starting from `from`. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function indexOf(string memory subject, string memory search, uint256 from) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { for { let subjectLength := mload(subject) } 1 {} { if iszero(mload(search)) { if iszero(gt(from, subjectLength)) { result := from break } result := subjectLength break } let searchLength := mload(search) let subjectStart := add(subject, 0x20) result := not(0) // Initialize to `NOT_FOUND`. subject := add(subjectStart, from) let end := add(sub(add(subjectStart, subjectLength), searchLength), 1) let m := shl(3, sub(0x20, and(searchLength, 0x1f))) let s := mload(add(search, 0x20)) if iszero(and(lt(subject, end), lt(from, subjectLength))) { break } if iszero(lt(searchLength, 0x20)) { for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} { if iszero(shr(m, xor(mload(subject), s))) { if eq(keccak256(subject, searchLength), h) { result := sub(subject, subjectStart) break } } subject := add(subject, 1) if iszero(lt(subject, end)) { break } } break } for {} 1 {} { if iszero(shr(m, xor(mload(subject), s))) { result := sub(subject, subjectStart) break } subject := add(subject, 1) if iszero(lt(subject, end)) { break } } break } } } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from left to right. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function indexOf(string memory subject, string memory search) internal pure returns (uint256 result) { result = indexOf(subject, search, 0); } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from right to left, starting from `from`. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function lastIndexOf(string memory subject, string memory search, uint256 from) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { for {} 1 {} { result := not(0) // Initialize to `NOT_FOUND`. let searchLength := mload(search) if gt(searchLength, mload(subject)) { break } let w := result let fromMax := sub(mload(subject), searchLength) if iszero(gt(fromMax, from)) { from := fromMax } let end := add(add(subject, 0x20), w) subject := add(add(subject, 0x20), from) if iszero(gt(subject, end)) { break } // As this function is not too often used, // we shall simply use keccak256 for smaller bytecode size. for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} { if eq(keccak256(subject, searchLength), h) { result := sub(subject, add(end, 1)) break } subject := add(subject, w) // `sub(subject, 1)`. if iszero(gt(subject, end)) { break } } break } } } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from right to left. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function lastIndexOf(string memory subject, string memory search) internal pure returns (uint256 result) { result = lastIndexOf(subject, search, uint256(int256(-1))); } /// @dev Returns true if `search` is found in `subject`, false otherwise. function contains(string memory subject, string memory search) internal pure returns (bool) { return indexOf(subject, search) != NOT_FOUND; } /// @dev Returns whether `subject` starts with `search`. function startsWith(string memory subject, string memory search) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let searchLength := mload(search) // Just using keccak256 directly is actually cheaper. // forgefmt: disable-next-item result := and( iszero(gt(searchLength, mload(subject))), eq( keccak256(add(subject, 0x20), searchLength), keccak256(add(search, 0x20), searchLength) ) ) } } /// @dev Returns whether `subject` ends with `search`. function endsWith(string memory subject, string memory search) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let searchLength := mload(search) let subjectLength := mload(subject) // Whether `search` is not longer than `subject`. let withinRange := iszero(gt(searchLength, subjectLength)) // Just using keccak256 directly is actually cheaper. // forgefmt: disable-next-item result := and( withinRange, eq( keccak256( // `subject + 0x20 + max(subjectLength - searchLength, 0)`. add(add(subject, 0x20), mul(withinRange, sub(subjectLength, searchLength))), searchLength ), keccak256(add(search, 0x20), searchLength) ) ) } } /// @dev Returns `subject` repeated `times`. function repeat(string memory subject, uint256 times) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) if iszero(or(iszero(times), iszero(subjectLength))) { subject := add(subject, 0x20) result := mload(0x40) let output := add(result, 0x20) for {} 1 {} { // Copy the `subject` one word at a time. for { let o := 0 } 1 {} { mstore(add(output, o), mload(add(subject, o))) o := add(o, 0x20) if iszero(lt(o, subjectLength)) { break } } output := add(output, subjectLength) times := sub(times, 1) if iszero(times) { break } } mstore(output, 0) // Zeroize the slot after the string. let resultLength := sub(output, add(result, 0x20)) mstore(result, resultLength) // Store the length. // Allocate the memory. mstore(0x40, add(result, add(resultLength, 0x20))) } } } /// @dev Returns a copy of `subject` sliced from `start` to `end` (exclusive). /// `start` and `end` are byte offsets. function slice(string memory subject, uint256 start, uint256 end) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) if iszero(gt(subjectLength, end)) { end := subjectLength } if iszero(gt(subjectLength, start)) { start := subjectLength } if lt(start, end) { result := mload(0x40) let resultLength := sub(end, start) mstore(result, resultLength) subject := add(subject, start) let w := not(0x1f) // Copy the `subject` one word at a time, backwards. for { let o := and(add(resultLength, 0x1f), w) } 1 {} { mstore(add(result, o), mload(add(subject, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } // Zeroize the slot after the string. mstore(add(add(result, 0x20), resultLength), 0) // Allocate memory for the length and the bytes, // rounded up to a multiple of 32. mstore(0x40, add(result, and(add(resultLength, 0x3f), w))) } } } /// @dev Returns a copy of `subject` sliced from `start` to the end of the string. /// `start` is a byte offset. function slice(string memory subject, uint256 start) internal pure returns (string memory result) { result = slice(subject, start, uint256(int256(-1))); } /// @dev Returns all the indices of `search` in `subject`. /// The indices are byte offsets. function indicesOf(string memory subject, string memory search) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) let searchLength := mload(search) if iszero(gt(searchLength, subjectLength)) { subject := add(subject, 0x20) search := add(search, 0x20) result := add(mload(0x40), 0x20) let subjectStart := subject let subjectSearchEnd := add(sub(add(subject, subjectLength), searchLength), 1) let h := 0 if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) } let m := shl(3, sub(0x20, and(searchLength, 0x1f))) let s := mload(search) for {} 1 {} { let t := mload(subject) // Whether the first `searchLength % 32` bytes of // `subject` and `search` matches. if iszero(shr(m, xor(t, s))) { if h { if iszero(eq(keccak256(subject, searchLength), h)) { subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } continue } } // Append to `result`. mstore(result, sub(subject, subjectStart)) result := add(result, 0x20) // Advance `subject` by `searchLength`. subject := add(subject, searchLength) if searchLength { if iszero(lt(subject, subjectSearchEnd)) { break } continue } } subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } } let resultEnd := result // Assign `result` to the free memory pointer. result := mload(0x40) // Store the length of `result`. mstore(result, shr(5, sub(resultEnd, add(result, 0x20)))) // Allocate memory for result. // We allocate one more word, so this array can be recycled for {split}. mstore(0x40, add(resultEnd, 0x20)) } } } /// @dev Returns a arrays of strings based on the `delimiter` inside of the `subject` string. function split(string memory subject, string memory delimiter) internal pure returns (string[] memory result) { uint256[] memory indices = indicesOf(subject, delimiter); /// @solidity memory-safe-assembly assembly { let w := not(0x1f) let indexPtr := add(indices, 0x20) let indicesEnd := add(indexPtr, shl(5, add(mload(indices), 1))) mstore(add(indicesEnd, w), mload(subject)) mstore(indices, add(mload(indices), 1)) let prevIndex := 0 for {} 1 {} { let index := mload(indexPtr) mstore(indexPtr, 0x60) if iszero(eq(index, prevIndex)) { let element := mload(0x40) let elementLength := sub(index, prevIndex) mstore(element, elementLength) // Copy the `subject` one word at a time, backwards. for { let o := and(add(elementLength, 0x1f), w) } 1 {} { mstore(add(element, o), mload(add(add(subject, prevIndex), o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } // Zeroize the slot after the string. mstore(add(add(element, 0x20), elementLength), 0) // Allocate memory for the length and the bytes, // rounded up to a multiple of 32. mstore(0x40, add(element, and(add(elementLength, 0x3f), w))) // Store the `element` into the array. mstore(indexPtr, element) } prevIndex := add(index, mload(delimiter)) indexPtr := add(indexPtr, 0x20) if iszero(lt(indexPtr, indicesEnd)) { break } } result := indices if iszero(mload(delimiter)) { result := add(indices, 0x20) mstore(result, sub(mload(indices), 2)) } } } /// @dev Returns a concatenated string of `a` and `b`. /// Cheaper than `string.concat()` and does not de-align the free memory pointer. function concat(string memory a, string memory b) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let w := not(0x1f) result := mload(0x40) let aLength := mload(a) // Copy `a` one word at a time, backwards. for { let o := and(add(aLength, 0x20), w) } 1 {} { mstore(add(result, o), mload(add(a, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } let bLength := mload(b) let output := add(result, aLength) // Copy `b` one word at a time, backwards. for { let o := and(add(bLength, 0x20), w) } 1 {} { mstore(add(output, o), mload(add(b, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } let totalLength := add(aLength, bLength) let last := add(add(result, 0x20), totalLength) // Zeroize the slot after the string. mstore(last, 0) // Stores the length. mstore(result, totalLength) // Allocate memory for the length and the bytes, // rounded up to a multiple of 32. mstore(0x40, and(add(last, 0x1f), w)) } } /// @dev Returns a copy of the string in either lowercase or UPPERCASE. /// WARNING! This function is only compatible with 7-bit ASCII strings. function toCase(string memory subject, bool toUpper) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let length := mload(subject) if length { result := add(mload(0x40), 0x20) subject := add(subject, 1) let flags := shl(add(70, shl(5, toUpper)), 0x3ffffff) let w := not(0) for { let o := length } 1 {} { o := add(o, w) let b := and(0xff, mload(add(subject, o))) mstore8(add(result, o), xor(b, and(shr(b, flags), 0x20))) if iszero(o) { break } } result := mload(0x40) mstore(result, length) // Store the length. let last := add(add(result, 0x20), length) mstore(last, 0) // Zeroize the slot after the string. mstore(0x40, add(last, 0x20)) // Allocate the memory. } } } /// @dev Returns a string from a small bytes32 string. /// `smallString` must be null terminated, or behavior will be undefined. function fromSmallString(bytes32 smallString) internal pure returns (string memory result) { if (smallString == bytes32(0)) return result; /// @solidity memory-safe-assembly assembly { result := mload(0x40) let n := 0 for {} 1 {} { n := add(n, 1) if iszero(byte(n, smallString)) { break } // Scan for '\0'. } mstore(result, n) let o := add(result, 0x20) mstore(o, smallString) mstore(add(o, n), 0) mstore(0x40, add(result, 0x40)) } } /// @dev Returns a lowercased copy of the string. /// WARNING! This function is only compatible with 7-bit ASCII strings. function lower(string memory subject) internal pure returns (string memory result) { result = toCase(subject, false); } /// @dev Returns an UPPERCASED copy of the string. /// WARNING! This function is only compatible with 7-bit ASCII strings. function upper(string memory subject) internal pure returns (string memory result) { result = toCase(subject, true); } /// @dev Escapes the string to be used within HTML tags. function escapeHTML(string memory s) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let end := add(s, mload(s)) result := add(mload(0x40), 0x20) // Store the bytes of the packed offsets and strides into the scratch space. // `packed = (stride << 5) | offset`. Max offset is 20. Max stride is 6. mstore(0x1f, 0x900094) mstore(0x08, 0xc0000000a6ab) // Store ""&'<>" into the scratch space. mstore(0x00, shl(64, 0x2671756f743b26616d703b262333393b266c743b2667743b)) for {} iszero(eq(s, end)) {} { s := add(s, 1) let c := and(mload(s), 0xff) // Not in `["\"","'","&","<",">"]`. if iszero(and(shl(c, 1), 0x500000c400000000)) { mstore8(result, c) result := add(result, 1) continue } let t := shr(248, mload(c)) mstore(result, mload(and(t, 0x1f))) result := add(result, shr(5, t)) } let last := result mstore(last, 0) // Zeroize the slot after the string. result := mload(0x40) mstore(result, sub(last, add(result, 0x20))) // Store the length. mstore(0x40, add(last, 0x20)) // Allocate the memory. } } /// @dev Escapes the string to be used within double-quotes in a JSON. /// If `addDoubleQuotes` is true, the result will be enclosed in double-quotes. function escapeJSON(string memory s, bool addDoubleQuotes) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let end := add(s, mload(s)) result := add(mload(0x40), 0x20) if addDoubleQuotes { mstore8(result, 34) result := add(1, result) } // Store "\\u0000" in scratch space. // Store "0123456789abcdef" in scratch space. // Also, store `{0x08:"b", 0x09:"t", 0x0a:"n", 0x0c:"f", 0x0d:"r"}`. // into the scratch space. mstore(0x15, 0x5c75303030303031323334353637383961626364656662746e006672) // Bitmask for detecting `["\"","\\"]`. let e := or(shl(0x22, 1), shl(0x5c, 1)) for {} iszero(eq(s, end)) {} { s := add(s, 1) let c := and(mload(s), 0xff) if iszero(lt(c, 0x20)) { if iszero(and(shl(c, 1), e)) { // Not in `["\"","\\"]`. mstore8(result, c) result := add(result, 1) continue } mstore8(result, 0x5c) // "\\". mstore8(add(result, 1), c) result := add(result, 2) continue } if iszero(and(shl(c, 1), 0x3700)) { // Not in `["\b","\t","\n","\f","\d"]`. mstore8(0x1d, mload(shr(4, c))) // Hex value. mstore8(0x1e, mload(and(c, 15))) // Hex value. mstore(result, mload(0x19)) // "\\u00XX". result := add(result, 6) continue } mstore8(result, 0x5c) // "\\". mstore8(add(result, 1), mload(add(c, 8))) result := add(result, 2) } if addDoubleQuotes { mstore8(result, 34) result := add(1, result) } let last := result mstore(last, 0) // Zeroize the slot after the string. result := mload(0x40) mstore(result, sub(last, add(result, 0x20))) // Store the length. mstore(0x40, add(last, 0x20)) // Allocate the memory. } } /// @dev Escapes the string to be used within double-quotes in a JSON. function escapeJSON(string memory s) internal pure returns (string memory result) { result = escapeJSON(s, false); } /// @dev Returns whether `a` equals `b`. function eq(string memory a, string memory b) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { result := eq(keccak256(add(a, 0x20), mload(a)), keccak256(add(b, 0x20), mload(b))) } } /// @dev Returns whether `a` equals `b`. For small strings up to 32 bytes. /// `b` must be null terminated, or behavior will be undefined. function eqs(string memory a, bytes32 b) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { // These should be evaluated on compile time, as far as possible. let x := and(b, add(not(b), 1)) let r := or(shl(8, iszero(b)), shl(7, iszero(iszero(shr(128, x))))) r := or(r, shl(6, iszero(iszero(shr(64, shr(r, x)))))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) result := gt(eq(mload(a), sub(32, shr(3, r))), shr(r, xor(b, mload(add(a, 0x20))))) } } /// @dev Packs a single string with its length into a single word. /// Returns `bytes32(0)` if the length is zero or greater than 31. function packOne(string memory a) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { // We don't need to zero right pad the string, // since this is our own custom non-standard packing scheme. result := mul( // Load the length and the bytes. mload(add(a, 0x1f)), // `length != 0 && length < 32`. Abuses underflow. // Assumes that the length is valid and within the block gas limit. lt(sub(mload(a), 1), 0x1f) ) } } /// @dev Unpacks a string packed using {packOne}. /// Returns the empty string if `packed` is `bytes32(0)`. /// If `packed` is not an output of {packOne}, the output behavior is undefined. function unpackOne(bytes32 packed) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { // Grab the free memory pointer. result := mload(0x40) // Allocate 2 words (1 for the length, 1 for the bytes). mstore(0x40, add(result, 0x40)) // Zeroize the length slot. mstore(result, 0) // Store the length and bytes. mstore(add(result, 0x1f), packed) // Right pad with zeroes. mstore(add(add(result, 0x20), mload(result)), 0) } } /// @dev Packs two strings with their lengths into a single word. /// Returns `bytes32(0)` if combined length is zero or greater than 30. function packTwo(string memory a, string memory b) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { let aLength := mload(a) // We don't need to zero right pad the strings, // since this is our own custom non-standard packing scheme. result := mul( // Load the length and the bytes of `a` and `b`. or( shl(shl(3, sub(0x1f, aLength)), mload(add(a, aLength))), mload(sub(add(b, 0x1e), aLength)) ), // `totalLength != 0 && totalLength < 31`. Abuses underflow. // Assumes that the lengths are valid and within the block gas limit. lt(sub(add(aLength, mload(b)), 1), 0x1e) ) } } /// @dev Unpacks strings packed using {packTwo}. /// Returns the empty strings if `packed` is `bytes32(0)`. /// If `packed` is not an output of {packTwo}, the output behavior is undefined. function unpackTwo(bytes32 packed) internal pure returns (string memory resultA, string memory resultB) { /// @solidity memory-safe-assembly assembly { // Grab the free memory pointer. resultA := mload(0x40) resultB := add(resultA, 0x40) // Allocate 2 words for each string (1 for the length, 1 for the byte). Total 4 words. mstore(0x40, add(resultB, 0x40)) // Zeroize the length slots. mstore(resultA, 0) mstore(resultB, 0) // Store the lengths and bytes. mstore(add(resultA, 0x1f), packed) mstore(add(resultB, 0x1f), mload(add(add(resultA, 0x20), mload(resultA)))) // Right pad with zeroes. mstore(add(add(resultA, 0x20), mload(resultA)), 0) mstore(add(add(resultB, 0x20), mload(resultB)), 0) } } /// @dev Directly returns `a` without copying. function directReturn(string memory a) internal pure { assembly { // Assumes that the string does not start from the scratch space. let retStart := sub(a, 0x20) let retSize := add(mload(a), 0x40) // Right pad with zeroes. Just in case the string is produced // by a method that doesn't zero right pad. mstore(add(retStart, retSize), 0) // Store the return offset. mstore(retStart, 0x20) // End the transaction, returning the string. return(retStart, retSize) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.22; import {File, BytecodeSlice} from "./File.sol"; /// @title EthFS FileStore interface /// @notice Specifies a content-addressable onchain file store interface IFileStore { event Deployed(); /** * @dev Emitted when a new file is created * @param indexedFilename The indexed filename for easier finding by filename in logs * @param pointer The pointer address of the file * @param filename The name of the file * @param size The total size of the file * @param metadata Additional metadata of the file, only emitted for use in offchain indexers */ event FileCreated( string indexed indexedFilename, address indexed pointer, string filename, uint256 size, bytes metadata ); /** * @dev Error thrown when a requested file is not found * @param filename The name of the file requested */ error FileNotFound(string filename); /** * @dev Error thrown when a filename already exists * @param filename The name of the file attempted to be created */ error FilenameExists(string filename); /** * @dev Error thrown when attempting to create an empty file */ error FileEmpty(); /** * @dev Error thrown when a provided slice for a file is empty * @param pointer The contract address where the bytecode lives * @param start The byte offset to start the slice (inclusive) * @param end The byte offset to end the slice (exclusive) */ error SliceEmpty(address pointer, uint32 start, uint32 end); /** * @dev Error thrown when the provided pointer's bytecode does not have the expected STOP opcode prefix from SSTORE2 * @param pointer The SSTORE2 pointer address */ error InvalidPointer(address pointer); /** * @notice Returns the address of the CREATE2 deterministic deployer used by this FileStore * @return The address of the CREATE2 deterministic deployer */ function deployer() external view returns (address); /** * @notice Retrieves the pointer address of a file by its filename * @param filename The name of the file * @return pointer The pointer address of the file */ function files( string memory filename ) external view returns (address pointer); /** * @notice Checks if a file exists for a given filename * @param filename The name of the file to check * @return True if the file exists, false otherwise */ function fileExists(string memory filename) external view returns (bool); /** * @notice Retrieves the pointer address for a given filename * @param filename The name of the file * @return pointer The pointer address of the file */ function getPointer( string memory filename ) external view returns (address pointer); /** * @notice Retrieves a file by its filename * @param filename The name of the file * @return file The file associated with the filename */ function getFile( string memory filename ) external view returns (File memory file); /** * @notice Creates a new file with the provided file contents * @dev This is a convenience method to simplify small file uploads. It's recommended to use `createFileFromPointers` or `createFileFromSlices` for larger files. This particular method splits `contents` into 24575-byte chunks before storing them via SSTORE2. * @param filename The name of the new file * @param contents The contents of the file * @return pointer The pointer address of the new file * @return file The newly created file */ function createFile( string memory filename, string memory contents ) external returns (address pointer, File memory file); /** * @notice Creates a new file with the provided file contents and file metadata * @dev This is a convenience method to simplify small file uploads. It's recommended to use `createFileFromPointers` or `createFileFromSlices` for larger files. This particular method splits `contents` into 24575-byte chunks before storing them via SSTORE2. * @param filename The name of the new file * @param contents The contents of the file * @param metadata Additional file metadata, usually a JSON-encoded string, for offchain indexers * @return pointer The pointer address of the new file * @return file The newly created file */ function createFile( string memory filename, string memory contents, bytes memory metadata ) external returns (address pointer, File memory file); /** * @notice Creates a new file where its content is composed of the provided string chunks * @dev This is a convenience method to simplify small and nuanced file uploads. It's recommended to use `createFileFromPointers` or `createFileFromSlices` for larger files. This particular will store each chunk separately via SSTORE2. For best gas efficiency, each chunk should be as large as possible (up to the contract size limit) and at least 32 bytes. * @param filename The name of the new file * @param chunks The string chunks composing the file * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromChunks( string memory filename, string[] memory chunks ) external returns (address pointer, File memory file); /** * @notice Creates a new file with the provided string chunks and file metadata * @dev This is a convenience method to simplify small and nuanced file uploads. It's recommended to use `createFileFromPointers` or `createFileFromSlices` for larger files. This particular will store each chunk separately via SSTORE2. For best gas efficiency, each chunk should be as large as possible (up to the contract size limit) and at least 32 bytes. * @param filename The name of the new file * @param chunks The string chunks composing the file * @param metadata Additional file metadata, usually a JSON-encoded string, for offchain indexers * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromChunks( string memory filename, string[] memory chunks, bytes memory metadata ) external returns (address pointer, File memory file); /** * @notice Creates a new file where its content is composed of the provided SSTORE2 pointers * @param filename The name of the new file * @param pointers The SSTORE2 pointers composing the file * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromPointers( string memory filename, address[] memory pointers ) external returns (address pointer, File memory file); /** * @notice Creates a new file with the provided SSTORE2 pointers and file metadata * @param filename The name of the new file * @param pointers The SSTORE2 pointers composing the file * @param metadata Additional file metadata, usually a JSON-encoded string, for offchain indexers * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromPointers( string memory filename, address[] memory pointers, bytes memory metadata ) external returns (address pointer, File memory file); /** * @notice Creates a new file where its content is composed of the provided bytecode slices * @param filename The name of the new file * @param slices The bytecode slices composing the file * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromSlices( string memory filename, BytecodeSlice[] memory slices ) external returns (address pointer, File memory file); /** * @notice Creates a new file with the provided bytecode slices and file metadata * @param filename The name of the new file * @param slices The bytecode slices composing the file * @param metadata Additional file metadata, usually a JSON-encoded string, for offchain indexers * @return pointer The pointer address of the new file * @return file The newly created file */ function createFileFromSlices( string memory filename, BytecodeSlice[] memory slices, bytes memory metadata ) external returns (address pointer, File memory file); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.22; /** * @title EthFS File * @notice A representation of an onchain file, composed of slices of contract bytecode and utilities to construct the file contents from those slices. * @dev For best gas efficiency, it's recommended using `File.read()` as close to the output returned by the contract call as possible. Lots of gas is consumed every time a large data blob is passed between functions. */ /** * @dev Represents a reference to a slice of bytecode in a contract */ struct BytecodeSlice { address pointer; uint32 start; uint32 end; } /** * @dev Represents a file composed of one or more bytecode slices */ struct File { // Total length of file contents (sum of all slice sizes). Useful when you want to use DynamicBuffer to build the file contents from the slices. uint256 size; BytecodeSlice[] slices; } // extend File struct with read functions using {read} for File global; using {readUnchecked} for File global; /** * @dev Error thrown when a slice is out of the bounds of the contract's bytecode */ error SliceOutOfBounds( address pointer, uint32 codeSize, uint32 sliceStart, uint32 sliceEnd ); /** * @notice Reads the contents of a file by concatenating its slices * @param file The file to read * @return contents The concatenated contents of the file */ function read(File memory file) view returns (string memory contents) { BytecodeSlice[] memory slices = file.slices; bytes4 sliceOutOfBoundsSelector = SliceOutOfBounds.selector; assembly { let len := mload(slices) let size := 0x20 contents := mload(0x40) let slice let pointer let start let end let codeSize for { let i := 0 } lt(i, len) { i := add(i, 1) } { slice := mload(add(slices, add(0x20, mul(i, 0x20)))) pointer := mload(slice) start := mload(add(slice, 0x20)) end := mload(add(slice, 0x40)) codeSize := extcodesize(pointer) if gt(end, codeSize) { mstore(0x00, sliceOutOfBoundsSelector) mstore(0x04, pointer) mstore(0x24, codeSize) mstore(0x44, start) mstore(0x64, end) revert(0x00, 0x84) } extcodecopy(pointer, add(contents, size), start, sub(end, start)) size := add(size, sub(end, start)) } // update contents size mstore(contents, sub(size, 0x20)) // store contents mstore(0x40, add(contents, and(add(size, 0x1f), not(0x1f)))) } } /** * @notice Reads the contents of a file without reverting on unreadable/invalid slices. Skips any slices that are out of bounds or invalid. Useful if you are composing contract bytecode where a contract can still selfdestruct (which would result in an invalid slice) and want to avoid reverts but still output potentially "corrupted" file contents (due to missing data). * @param file The file to read * @return contents The concatenated contents of the file, skipping invalid slices */ function readUnchecked(File memory file) view returns (string memory contents) { BytecodeSlice[] memory slices = file.slices; assembly { let len := mload(slices) let size := 0x20 contents := mload(0x40) let slice let pointer let start let end let codeSize for { let i := 0 } lt(i, len) { i := add(i, 1) } { slice := mload(add(slices, add(0x20, mul(i, 0x20)))) pointer := mload(slice) start := mload(add(slice, 0x20)) end := mload(add(slice, 0x40)) codeSize := extcodesize(pointer) if lt(end, codeSize) { extcodecopy( pointer, add(contents, size), start, sub(end, start) ) size := add(size, sub(end, start)) } } // update contents size mstore(contents, sub(size, 0x20)) // store contents mstore(0x40, add(contents, and(add(size, 0x1f), not(0x1f)))) } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.22; import {SSTORE2} from "solady/utils/SSTORE2.sol"; bytes32 constant SALT = bytes32("EthFS"); /** * @dev Error thrown when the pointer of the content added does not match the one we compute from the content, signaling something weird going on with the deployer * @param expectedPointer The expected address of the content * @param actualPointer The actual address of the content */ error UnexpectedPointer(address expectedPointer, address actualPointer); /** * @dev Converts data into creation code for an SSTORE2 data contract * @param content The bytes content to be converted * @return creationCode The creation code for the data contract */ function contentToInitCode( bytes memory content ) pure returns (bytes memory creationCode) { // Use the same strategy as Solady's SSTORE2 to write a data contract, but do this via the deployer for a constant address // https://github.com/Vectorized/solady/blob/cb801a60f8319a148697b09d19b748d04e3d65c4/src/utils/SSTORE2.sol#L44-L59 // TODO: convert this to assembly? return abi.encodePacked( bytes11(0x61000080600a3d393df300) | // Overlay content size (plus offset for STOP opcode) into second and third bytes bytes11(bytes3(uint24(content.length + 1))), content ); } /** * @dev Predicts the address of a data contract based on its content * @param deployer The deployer's address * @param content The content of the data contract * @return pointer The predicted address of the data contract */ function getPointer( address deployer, bytes memory content ) pure returns (address pointer) { return SSTORE2.predictDeterministicAddress(content, SALT, deployer); } /** * @dev Checks if a pointer (data contract address) already exists * @param pointer The data contract address to check * @return true if the data contract exists, false otherwise */ function pointerExists(address pointer) view returns (bool) { return pointer.code.length > 0; } /** * @dev Adds content as a data contract using a deterministic deployer * @param deployer The deployer's address * @param content The content to be added as a data contract * @return pointer The address of the data contract */ function addContent( address deployer, bytes memory content ) returns (address pointer) { address expectedPointer = getPointer(deployer, content); if (pointerExists(expectedPointer)) { return expectedPointer; } (bool success, bytes memory data) = deployer.call( abi.encodePacked(SALT, contentToInitCode(content)) ); if (!success) revertWithBytes(data); pointer = address(uint160(bytes20(data))); if (pointer != expectedPointer) { revert UnexpectedPointer(expectedPointer, pointer); } } /** * @notice Reverts the transaction using the provided raw bytes as the revert reason * @dev Uses assembly to perform the revert operation with the raw bytes * @param reason The raw bytes revert reason */ function revertWithBytes(bytes memory reason) pure { assembly { // reason+32 is a pointer to the error message, mload(reason) is the length of the error message revert(add(reason, 0x20), mload(reason)) } } /** * @dev Checks if the given address points to a valid SSTORE2 data contract (i.e. starts with STOP opcode) * @param pointer The address to be checked * @return isValid true if the address points to a valid contract (bytecode starts with a STOP opcode), false otherwise */ function isValidPointer(address pointer) view returns (bool isValid) { // The assembly below is equivalent to // // pointer.code.length >= 1 && pointer.code[0] == 0x00; // // but less gas because it doesn't have to load all the pointer's bytecode assembly { // Get the size of the bytecode at pointer let size := extcodesize(pointer) // Initialize first byte with INVALID opcode let firstByte := 0xfe // If there's at least one byte of code, copy the first byte if gt(size, 0) { // Allocate memory for the first byte let code := mload(0x40) // Copy the first byte of the code extcodecopy(pointer, code, 0, 1) // Retrieve the first byte, ensuring it's a single byte firstByte := and(mload(sub(code, 31)), 0xff) } // Check if the first byte is 0x00 (STOP opcode) isValid := eq(firstByte, 0x00) } }
{ "remappings": [ "forge-std/=lib/forge-std/src/", "openzeppelin/=lib/openzeppelin-contracts/contracts/", "solady/=lib/solady/src/", "@latticexyz/gas-report/=node_modules/@latticexyz/gas-report/src/", "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "ds-test/=lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "openzeppelin-contracts/=lib/openzeppelin-contracts/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "none", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_deployer","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"FileEmpty","type":"error"},{"inputs":[{"internalType":"string","name":"filename","type":"string"}],"name":"FileNotFound","type":"error"},{"inputs":[{"internalType":"string","name":"filename","type":"string"}],"name":"FilenameExists","type":"error"},{"inputs":[{"internalType":"address","name":"pointer","type":"address"}],"name":"InvalidPointer","type":"error"},{"inputs":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"name":"SliceEmpty","type":"error"},{"inputs":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"codeSize","type":"uint32"},{"internalType":"uint32","name":"sliceStart","type":"uint32"},{"internalType":"uint32","name":"sliceEnd","type":"uint32"}],"name":"SliceOutOfBounds","type":"error"},{"inputs":[{"internalType":"address","name":"expectedPointer","type":"address"},{"internalType":"address","name":"actualPointer","type":"address"}],"name":"UnexpectedPointer","type":"error"},{"anonymous":false,"inputs":[],"name":"Deployed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"string","name":"indexedFilename","type":"string"},{"indexed":true,"internalType":"address","name":"pointer","type":"address"},{"indexed":false,"internalType":"string","name":"filename","type":"string"},{"indexed":false,"internalType":"uint256","name":"size","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"metadata","type":"bytes"}],"name":"FileCreated","type":"event"},{"inputs":[{"internalType":"string","name":"filename","type":"string"},{"internalType":"string","name":"contents","type":"string"}],"name":"createFile","outputs":[{"internalType":"address","name":"pointer","type":"address"},{"components":[{"internalType":"uint256","name":"size","type":"uint256"},{"components":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"internalType":"struct BytecodeSlice[]","name":"slices","type":"tuple[]"}],"internalType":"struct File","name":"file","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"},{"internalType":"string","name":"contents","type":"string"},{"internalType":"bytes","name":"metadata","type":"bytes"}],"name":"createFile","outputs":[{"internalType":"address","name":"pointer","type":"address"},{"components":[{"internalType":"uint256","name":"size","type":"uint256"},{"components":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"internalType":"struct BytecodeSlice[]","name":"slices","type":"tuple[]"}],"internalType":"struct File","name":"file","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"},{"internalType":"string[]","name":"chunks","type":"string[]"},{"internalType":"bytes","name":"metadata","type":"bytes"}],"name":"createFileFromChunks","outputs":[{"internalType":"address","name":"pointer","type":"address"},{"components":[{"internalType":"uint256","name":"size","type":"uint256"},{"components":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"internalType":"struct BytecodeSlice[]","name":"slices","type":"tuple[]"}],"internalType":"struct File","name":"file","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"},{"internalType":"string[]","name":"chunks","type":"string[]"}],"name":"createFileFromChunks","outputs":[{"internalType":"address","name":"pointer","type":"address"},{"components":[{"internalType":"uint256","name":"size","type":"uint256"},{"components":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"internalType":"struct BytecodeSlice[]","name":"slices","type":"tuple[]"}],"internalType":"struct File","name":"file","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"},{"internalType":"address[]","name":"pointers","type":"address[]"},{"internalType":"bytes","name":"metadata","type":"bytes"}],"name":"createFileFromPointers","outputs":[{"internalType":"address","name":"pointer","type":"address"},{"components":[{"internalType":"uint256","name":"size","type":"uint256"},{"components":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"internalType":"struct BytecodeSlice[]","name":"slices","type":"tuple[]"}],"internalType":"struct File","name":"file","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"},{"internalType":"address[]","name":"pointers","type":"address[]"}],"name":"createFileFromPointers","outputs":[{"internalType":"address","name":"pointer","type":"address"},{"components":[{"internalType":"uint256","name":"size","type":"uint256"},{"components":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"internalType":"struct BytecodeSlice[]","name":"slices","type":"tuple[]"}],"internalType":"struct File","name":"file","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"},{"components":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"internalType":"struct BytecodeSlice[]","name":"slices","type":"tuple[]"},{"internalType":"bytes","name":"metadata","type":"bytes"}],"name":"createFileFromSlices","outputs":[{"internalType":"address","name":"pointer","type":"address"},{"components":[{"internalType":"uint256","name":"size","type":"uint256"},{"components":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"internalType":"struct BytecodeSlice[]","name":"slices","type":"tuple[]"}],"internalType":"struct File","name":"file","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"},{"components":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"internalType":"struct BytecodeSlice[]","name":"slices","type":"tuple[]"}],"name":"createFileFromSlices","outputs":[{"internalType":"address","name":"pointer","type":"address"},{"components":[{"internalType":"uint256","name":"size","type":"uint256"},{"components":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"internalType":"struct BytecodeSlice[]","name":"slices","type":"tuple[]"}],"internalType":"struct File","name":"file","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"deployer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"}],"name":"fileExists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"}],"name":"files","outputs":[{"internalType":"address","name":"pointer","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"}],"name":"getFile","outputs":[{"components":[{"internalType":"uint256","name":"size","type":"uint256"},{"components":[{"internalType":"address","name":"pointer","type":"address"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"}],"internalType":"struct BytecodeSlice[]","name":"slices","type":"tuple[]"}],"internalType":"struct File","name":"file","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"}],"name":"getPointer","outputs":[{"internalType":"address","name":"pointer","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"filename","type":"string"}],"name":"readFile","outputs":[{"internalType":"string","name":"contents","type":"string"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60a060405234801561001057600080fd5b50604051611cb5380380611cb583398101604081905261002f9161006b565b6001600160a01b0381166080526040517f3fad920548ed9f22deb8333b4cc1e4f9bc36666a1c2aa30ad59a0a3bb9dcbb9290600090a15061009b565b60006020828403121561007d57600080fd5b81516001600160a01b038116811461009457600080fd5b9392505050565b608051611bf16100c4600039600081816101c00152818161086a0152610dd50152611bf16000f3fe608060405234801561001057600080fd5b50600436106100ea5760003560e01c8063d0e11f721161008c578063e24eaca411610066578063e24eaca41461021a578063e77557611461022d578063e9c7b51c14610261578063fae172e61461027457600080fd5b8063d0e11f72146101a8578063d5f39488146101bb578063e0876aa8146101fa57600080fd5b806381ad193a116100c857806381ad193a1461014c57806383e870d31461015f5780639bccd6ad146101725780639d3127df1461019557600080fd5b806355bb7d2c146100ef57806360f9bb11146101195780637611cb0214610139575b600080fd5b6101026100fd3660046113fc565b610287565b604051610110929190611500565b60405180910390f35b61012c61012736600461152c565b6102c5565b60405161011091906115b0565b610102610147366004611636565b6102de565b61010261015a366004611690565b61030a565b61010261016d366004611772565b610355565b61018561018036600461152c565b610381565b6040519015158152602001610110565b6101026101a33660046117cc565b6103be565b6101026101b6366004611825565b6103ea565b6101e27f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610110565b61020d61020836600461152c565b610416565b604051610110919061187e565b610102610228366004611891565b6104a3565b6101e261023b36600461152c565b80516020818301810180516000825292820191909301209152546001600160a01b031681565b61010261026f3660046118ea565b6104cf565b6101e261028236600461152c565b6104fb565b60006102a6604051806040016040528060008152602001606081525090565b6102b9856102b38661054c565b856107d0565b91509150935093915050565b60606102d86102d383610416565b61094a565b92915050565b60006102fd604051806040016040528060008152602001606081525090565b6102b9856102b3866109ef565b6000610329604051806040016040528060008152602001606081525090565b61034a8461033685610c32565b6040805160008152602081019091526107d0565b915091509250929050565b6000610374604051806040016040528060008152602001606081525090565b6102b9856102b386610d45565b6000806001600160a01b031660008360405161039d9190611944565b908152604051908190036020019020546001600160a01b0316141592915050565b60006103dd604051806040016040528060008152602001606081525090565b61034a846103368561054c565b6000610409604051806040016040528060008152602001606081525090565b61034a8461033685610d45565b6040805180820190915260008152606060208201526000808360405161043c9190611944565b908152604051908190036020019020546001600160a01b03169050806104805782604051630b5d665f60e31b815260040161047791906115b0565b60405180910390fd5b61048981610f32565b80602001905181019061049c9190611960565b9392505050565b60006104c2604051806040016040528060008152602001606081525090565b61034a84610336856109ef565b60006104ee604051806040016040528060008152602001606081525090565b6102b9856102b386610c32565b6000808260405161050c9190611944565b908152604051908190036020019020546001600160a01b03169050806105475781604051630b5d665f60e31b815260040161047791906115b0565b919050565b6040805180820190915260008152606060208201526000805b83518110156107b657600084828151811061058257610582611a77565b6020026020010151602001518583815181106105a0576105a0611a77565b6020026020010151604001516105b69190611aa3565b63ffffffff1611610659578381815181106105d3576105d3611a77565b6020026020010151600001518482815181106105f1576105f1611a77565b60200260200101516020015185838151811061060f5761060f611a77565b602002602001015160400151604051630fb55db160e41b8152600401610477939291906001600160a01b0393909316835263ffffffff918216602084015216604082015260600190565b600084828151811061066d5761066d611a77565b6020026020010151600001516001600160a01b03163b90508063ffffffff1685838151811061069e5761069e611a77565b60200260200101516040015163ffffffff161115610755578482815181106106c8576106c8611a77565b602002602001015160000151818684815181106106e7576106e7611a77565b60200260200101516020015187858151811061070557610705611a77565b602090810291909101015160409081015190516386d14d8960e01b81526001600160a01b03909416600485015263ffffffff92831660248501529082166044840152166064820152608401610477565b84828151811061076757610767611a77565b60200260200101516020015185838151811061078557610785611a77565b60200260200101516040015161079b9190611aa3565b6107ab9063ffffffff1684611ac7565b925050600101610565565b506040805180820190915290815260208101929092525090565b60006107ef604051806040016040528060008152602001606081525090565b83516000036108115760405163d74d341f60e01b815260040160405180910390fd5b60006001600160a01b031660008660405161082c9190611944565b908152604051908190036020019020546001600160a01b03161461086557846040516301856ec560e51b815260040161047791906115b0565b6108ae7f00000000000000000000000000000000000000000000000000000000000000008560405160200161089a919061187e565b604051602081830303815290604052610f7c565b9150816000866040516108c19190611944565b90815260405190819003602001812080546001600160a01b039384166001600160a01b0319909116179055908316906108fb908790611944565b60405180910390207f656833a15067acdf08730a6a38b6ab9ed5e3265936848d56eac08e7b3b7239648787600001518760405161093a93929190611ada565b60405180910390a3509391925050565b6020808201518051604051926386d14d8960e01b9190600080808080805b878110156109cd57602081026020018a01519550855194506020860151935060408601519250843b9150818311156109b457886000528460045281602452836044528260645260846000fd5b83830384888d01873c8383039690960195600101610968565b505050505050602081038552601f19601f820116850160405250505050919050565b60408051808201909152600081526060602082015260008083516001600160401b03811115610a2057610a206111fc565b604051908082528060200260200182016040528015610a6b57816020015b6040805160608101825260008082526020808301829052928201528252600019909201910181610a3e5790505b50905060005b8451811015610c1957610a9c858281518110610a8f57610a8f611a77565b6020026020010151611094565b610ae357848181518110610ab257610ab2611a77565b60200260200101516040516326cd283760e01b815260040161047791906001600160a01b0391909116815260200190565b848181518110610af557610af5611a77565b6020026020010151828281518110610b0f57610b0f611a77565b6020026020010151600001906001600160a01b031690816001600160a01b0316815250506001828281518110610b4757610b47611a77565b60200260200101516020019063ffffffff16908163ffffffff1681525050848181518110610b7757610b77611a77565b60200260200101516001600160a01b03163b828281518110610b9b57610b9b611a77565b60200260200101516040019063ffffffff16908163ffffffff1681525050818181518110610bcb57610bcb611a77565b602002602001015160200151828281518110610be957610be9611a77565b602002602001015160400151610bff9190611aa3565b610c0f9063ffffffff1684611ac7565b9250600101610a71565b5060408051808201909152918252602082015292915050565b6040805180820190915260008152606060208201528151615fff6000816001610c5b8286611ac7565b610c659190611b05565b610c6f9190611b18565b90506000816001600160401b03811115610c8b57610c8b6111fc565b604051908082528060200260200182016040528015610cbe57816020015b6060815260200190600190039081610ca95790505b50905060005b82811015610d31576000610cd88583611b3a565b9050600086610ce78784611ac7565b11610cfb57610cf68683611ac7565b610cfd565b865b9050610d0a8983836110bd565b848481518110610d1c57610d1c611a77565b60209081029190910101525050600101610cc4565b50610d3b81610d45565b9695505050505050565b60408051808201909152600081526060602082015260008083516001600160401b03811115610d7657610d766111fc565b604051908082528060200260200182016040528015610dc157816020015b6040805160608101825260008082526020808301829052928201528252600019909201910181610d945790505b50905060005b8451811015610c1957610e137f0000000000000000000000000000000000000000000000000000000000000000868381518110610e0657610e06611a77565b6020026020010151610f7c565b828281518110610e2557610e25611a77565b6020026020010151600001906001600160a01b031690816001600160a01b0316815250506001828281518110610e5d57610e5d611a77565b60200260200101516020019063ffffffff16908163ffffffff1681525050848181518110610e8d57610e8d611a77565b6020026020010151516001610ea29190611ac7565b828281518110610eb457610eb4611a77565b60200260200101516040019063ffffffff16908163ffffffff1681525050818181518110610ee457610ee4611a77565b602002602001015160200151828281518110610f0257610f02611a77565b602002602001015160400151610f189190611aa3565b610f289063ffffffff1684611ac7565b9250600101610dc7565b6060813b80610f49576311052bb46000526004601cfd5b600181039050604051915061ffe0603f820116820160405280825260008160208401015280600160208401853c50919050565b600080610f898484611123565b90506001600160a01b0381163b15610fa25790506102d8565b600080856001600160a01b031664457468465360d81b610fc187611138565b604051602001610fd2929190611b51565b60408051601f1981840301815290829052610fec91611944565b6000604051808303816000865af19150503d8060008114611029576040519150601f19603f3d011682016040523d82523d6000602084013e61102e565b606091505b509150915081611041576110418161118d565b61104a81611b77565b60601c93506001600160a01b038316841461108b57604051636509115d60e01b81526001600160a01b03808516600483015285166024820152604401610477565b50505092915050565b6000813b60fe81156110b5576040516001600082873c601e19015160ff1690505b159392505050565b606083518281116110cc578092505b8381116110d7578093505b508183101561049c575060405182820380825293830193601f19601f820181165b86810151848201528101806110f85750600083830160200152603f9091011681016040529392505050565b600061049c8264457468465360d81b85611195565b6060815160016111489190611ac7565b60e81b6001600160e81b0319166a61000080600a3d393df30060a81b1782604051602001611177929190611bb3565b6040516020818303038152906040529050919050565b805160208201fd5b6000806111a1856111cb565b905060ff600053806035528260601b60015283601552605560002091506000603552509392505050565b60008151600181018060101c3d3d3e6a61000080600a3d393df300604082901b178452600a01601584012092525090565b634e487b7160e01b600052604160045260246000fd5b604051606081016001600160401b0381118282101715611234576112346111fc565b60405290565b604080519081016001600160401b0381118282101715611234576112346111fc565b604051601f8201601f191681016001600160401b0381118282101715611284576112846111fc565b604052919050565b600082601f83011261129d57600080fd5b81356001600160401b038111156112b6576112b66111fc565b6112c9601f8201601f191660200161125c565b8181528460208386010111156112de57600080fd5b816020850160208301376000918101602001919091529392505050565b60006001600160401b03821115611314576113146111fc565b5060051b60200190565b6001600160a01b038116811461133357600080fd5b50565b63ffffffff8116811461133357600080fd5b600082601f83011261135957600080fd5b8135602061136e611369836112fb565b61125c565b8281526060928302850182019282820191908785111561138d57600080fd5b8387015b858110156113ef5781818a0312156113a95760008081fd5b6113b1611212565b81356113bc8161131e565b8152818601356113cb81611336565b818701526040828101356113de81611336565b908201528452928401928101611391565b5090979650505050505050565b60008060006060848603121561141157600080fd5b83356001600160401b038082111561142857600080fd5b6114348783880161128c565b9450602086013591508082111561144a57600080fd5b61145687838801611348565b9350604086013591508082111561146c57600080fd5b506114798682870161128c565b9150509250925092565b600060408084018351855260208085015160408288015282815180855260609450606089019150838301925060005b818110156114f257835180516001600160a01b031684528581015163ffffffff9081168786015290880151168784015292840192918501916001016114b2565b509098975050505050505050565b6001600160a01b038316815260406020820181905260009061152490830184611483565b949350505050565b60006020828403121561153e57600080fd5b81356001600160401b0381111561155457600080fd5b6115248482850161128c565b60005b8381101561157b578181015183820152602001611563565b50506000910152565b6000815180845261159c816020860160208601611560565b601f01601f19169290920160200192915050565b60208152600061049c6020830184611584565b600082601f8301126115d457600080fd5b813560206115e4611369836112fb565b8083825260208201915060208460051b87010193508684111561160657600080fd5b602086015b8481101561162b57803561161e8161131e565b835291830191830161160b565b509695505050505050565b60008060006060848603121561164b57600080fd5b83356001600160401b038082111561166257600080fd5b61166e8783880161128c565b9450602086013591508082111561168457600080fd5b611456878388016115c3565b600080604083850312156116a357600080fd5b82356001600160401b03808211156116ba57600080fd5b6116c68683870161128c565b935060208501359150808211156116dc57600080fd5b506116e98582860161128c565b9150509250929050565b600082601f83011261170457600080fd5b81356020611714611369836112fb565b82815260059290921b8401810191818101908684111561173357600080fd5b8286015b8481101561162b5780356001600160401b038111156117565760008081fd5b6117648986838b010161128c565b845250918301918301611737565b60008060006060848603121561178757600080fd5b83356001600160401b038082111561179e57600080fd5b6117aa8783880161128c565b945060208601359150808211156117c057600080fd5b611456878388016116f3565b600080604083850312156117df57600080fd5b82356001600160401b03808211156117f657600080fd5b6118028683870161128c565b9350602085013591508082111561181857600080fd5b506116e985828601611348565b6000806040838503121561183857600080fd5b82356001600160401b038082111561184f57600080fd5b61185b8683870161128c565b9350602085013591508082111561187157600080fd5b506116e9858286016116f3565b60208152600061049c6020830184611483565b600080604083850312156118a457600080fd5b82356001600160401b03808211156118bb57600080fd5b6118c78683870161128c565b935060208501359150808211156118dd57600080fd5b506116e9858286016115c3565b6000806000606084860312156118ff57600080fd5b83356001600160401b038082111561191657600080fd5b6119228783880161128c565b9450602086013591508082111561193857600080fd5b6114568783880161128c565b60008251611956818460208701611560565b9190910192915050565b6000602080838503121561197357600080fd5b82516001600160401b038082111561198a57600080fd5b818501915060408083880312156119a057600080fd5b6119a861123a565b8351815284840151838111156119bd57600080fd5b80850194505087601f8501126119d257600080fd5b835192506119e2611369846112fb565b8381526060938402850186019386820191908a861115611a0157600080fd5b958701955b85871015611a645780878c031215611a1e5760008081fd5b611a26611212565b8751611a318161131e565b815287890151611a4081611336565b818a015287860151611a5181611336565b8187015283529586019591870191611a06565b5095820195909552979650505050505050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b63ffffffff828116828216039080821115611ac057611ac0611a8d565b5092915050565b808201808211156102d8576102d8611a8d565b606081526000611aed6060830186611584565b8460208401528281036040840152610d3b8185611584565b818103818111156102d8576102d8611a8d565b600082611b3557634e487b7160e01b600052601260045260246000fd5b500490565b80820281158282048414176102d8576102d8611a8d565b82815260008251611b69816020850160208701611560565b919091016020019392505050565b805160208201516bffffffffffffffffffffffff198082169291906014831015611bab5780818460140360031b1b83161693505b505050919050565b6001600160a81b0319831681528151600090611bd681600b850160208701611560565b91909101600b01939250505056fea164736f6c6343000817000a000000000000000000000000914d7fec6aac8cd542e72bca78b30650d45643d7
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100ea5760003560e01c8063d0e11f721161008c578063e24eaca411610066578063e24eaca41461021a578063e77557611461022d578063e9c7b51c14610261578063fae172e61461027457600080fd5b8063d0e11f72146101a8578063d5f39488146101bb578063e0876aa8146101fa57600080fd5b806381ad193a116100c857806381ad193a1461014c57806383e870d31461015f5780639bccd6ad146101725780639d3127df1461019557600080fd5b806355bb7d2c146100ef57806360f9bb11146101195780637611cb0214610139575b600080fd5b6101026100fd3660046113fc565b610287565b604051610110929190611500565b60405180910390f35b61012c61012736600461152c565b6102c5565b60405161011091906115b0565b610102610147366004611636565b6102de565b61010261015a366004611690565b61030a565b61010261016d366004611772565b610355565b61018561018036600461152c565b610381565b6040519015158152602001610110565b6101026101a33660046117cc565b6103be565b6101026101b6366004611825565b6103ea565b6101e27f000000000000000000000000914d7fec6aac8cd542e72bca78b30650d45643d781565b6040516001600160a01b039091168152602001610110565b61020d61020836600461152c565b610416565b604051610110919061187e565b610102610228366004611891565b6104a3565b6101e261023b36600461152c565b80516020818301810180516000825292820191909301209152546001600160a01b031681565b61010261026f3660046118ea565b6104cf565b6101e261028236600461152c565b6104fb565b60006102a6604051806040016040528060008152602001606081525090565b6102b9856102b38661054c565b856107d0565b91509150935093915050565b60606102d86102d383610416565b61094a565b92915050565b60006102fd604051806040016040528060008152602001606081525090565b6102b9856102b3866109ef565b6000610329604051806040016040528060008152602001606081525090565b61034a8461033685610c32565b6040805160008152602081019091526107d0565b915091509250929050565b6000610374604051806040016040528060008152602001606081525090565b6102b9856102b386610d45565b6000806001600160a01b031660008360405161039d9190611944565b908152604051908190036020019020546001600160a01b0316141592915050565b60006103dd604051806040016040528060008152602001606081525090565b61034a846103368561054c565b6000610409604051806040016040528060008152602001606081525090565b61034a8461033685610d45565b6040805180820190915260008152606060208201526000808360405161043c9190611944565b908152604051908190036020019020546001600160a01b03169050806104805782604051630b5d665f60e31b815260040161047791906115b0565b60405180910390fd5b61048981610f32565b80602001905181019061049c9190611960565b9392505050565b60006104c2604051806040016040528060008152602001606081525090565b61034a84610336856109ef565b60006104ee604051806040016040528060008152602001606081525090565b6102b9856102b386610c32565b6000808260405161050c9190611944565b908152604051908190036020019020546001600160a01b03169050806105475781604051630b5d665f60e31b815260040161047791906115b0565b919050565b6040805180820190915260008152606060208201526000805b83518110156107b657600084828151811061058257610582611a77565b6020026020010151602001518583815181106105a0576105a0611a77565b6020026020010151604001516105b69190611aa3565b63ffffffff1611610659578381815181106105d3576105d3611a77565b6020026020010151600001518482815181106105f1576105f1611a77565b60200260200101516020015185838151811061060f5761060f611a77565b602002602001015160400151604051630fb55db160e41b8152600401610477939291906001600160a01b0393909316835263ffffffff918216602084015216604082015260600190565b600084828151811061066d5761066d611a77565b6020026020010151600001516001600160a01b03163b90508063ffffffff1685838151811061069e5761069e611a77565b60200260200101516040015163ffffffff161115610755578482815181106106c8576106c8611a77565b602002602001015160000151818684815181106106e7576106e7611a77565b60200260200101516020015187858151811061070557610705611a77565b602090810291909101015160409081015190516386d14d8960e01b81526001600160a01b03909416600485015263ffffffff92831660248501529082166044840152166064820152608401610477565b84828151811061076757610767611a77565b60200260200101516020015185838151811061078557610785611a77565b60200260200101516040015161079b9190611aa3565b6107ab9063ffffffff1684611ac7565b925050600101610565565b506040805180820190915290815260208101929092525090565b60006107ef604051806040016040528060008152602001606081525090565b83516000036108115760405163d74d341f60e01b815260040160405180910390fd5b60006001600160a01b031660008660405161082c9190611944565b908152604051908190036020019020546001600160a01b03161461086557846040516301856ec560e51b815260040161047791906115b0565b6108ae7f000000000000000000000000914d7fec6aac8cd542e72bca78b30650d45643d78560405160200161089a919061187e565b604051602081830303815290604052610f7c565b9150816000866040516108c19190611944565b90815260405190819003602001812080546001600160a01b039384166001600160a01b0319909116179055908316906108fb908790611944565b60405180910390207f656833a15067acdf08730a6a38b6ab9ed5e3265936848d56eac08e7b3b7239648787600001518760405161093a93929190611ada565b60405180910390a3509391925050565b6020808201518051604051926386d14d8960e01b9190600080808080805b878110156109cd57602081026020018a01519550855194506020860151935060408601519250843b9150818311156109b457886000528460045281602452836044528260645260846000fd5b83830384888d01873c8383039690960195600101610968565b505050505050602081038552601f19601f820116850160405250505050919050565b60408051808201909152600081526060602082015260008083516001600160401b03811115610a2057610a206111fc565b604051908082528060200260200182016040528015610a6b57816020015b6040805160608101825260008082526020808301829052928201528252600019909201910181610a3e5790505b50905060005b8451811015610c1957610a9c858281518110610a8f57610a8f611a77565b6020026020010151611094565b610ae357848181518110610ab257610ab2611a77565b60200260200101516040516326cd283760e01b815260040161047791906001600160a01b0391909116815260200190565b848181518110610af557610af5611a77565b6020026020010151828281518110610b0f57610b0f611a77565b6020026020010151600001906001600160a01b031690816001600160a01b0316815250506001828281518110610b4757610b47611a77565b60200260200101516020019063ffffffff16908163ffffffff1681525050848181518110610b7757610b77611a77565b60200260200101516001600160a01b03163b828281518110610b9b57610b9b611a77565b60200260200101516040019063ffffffff16908163ffffffff1681525050818181518110610bcb57610bcb611a77565b602002602001015160200151828281518110610be957610be9611a77565b602002602001015160400151610bff9190611aa3565b610c0f9063ffffffff1684611ac7565b9250600101610a71565b5060408051808201909152918252602082015292915050565b6040805180820190915260008152606060208201528151615fff6000816001610c5b8286611ac7565b610c659190611b05565b610c6f9190611b18565b90506000816001600160401b03811115610c8b57610c8b6111fc565b604051908082528060200260200182016040528015610cbe57816020015b6060815260200190600190039081610ca95790505b50905060005b82811015610d31576000610cd88583611b3a565b9050600086610ce78784611ac7565b11610cfb57610cf68683611ac7565b610cfd565b865b9050610d0a8983836110bd565b848481518110610d1c57610d1c611a77565b60209081029190910101525050600101610cc4565b50610d3b81610d45565b9695505050505050565b60408051808201909152600081526060602082015260008083516001600160401b03811115610d7657610d766111fc565b604051908082528060200260200182016040528015610dc157816020015b6040805160608101825260008082526020808301829052928201528252600019909201910181610d945790505b50905060005b8451811015610c1957610e137f000000000000000000000000914d7fec6aac8cd542e72bca78b30650d45643d7868381518110610e0657610e06611a77565b6020026020010151610f7c565b828281518110610e2557610e25611a77565b6020026020010151600001906001600160a01b031690816001600160a01b0316815250506001828281518110610e5d57610e5d611a77565b60200260200101516020019063ffffffff16908163ffffffff1681525050848181518110610e8d57610e8d611a77565b6020026020010151516001610ea29190611ac7565b828281518110610eb457610eb4611a77565b60200260200101516040019063ffffffff16908163ffffffff1681525050818181518110610ee457610ee4611a77565b602002602001015160200151828281518110610f0257610f02611a77565b602002602001015160400151610f189190611aa3565b610f289063ffffffff1684611ac7565b9250600101610dc7565b6060813b80610f49576311052bb46000526004601cfd5b600181039050604051915061ffe0603f820116820160405280825260008160208401015280600160208401853c50919050565b600080610f898484611123565b90506001600160a01b0381163b15610fa25790506102d8565b600080856001600160a01b031664457468465360d81b610fc187611138565b604051602001610fd2929190611b51565b60408051601f1981840301815290829052610fec91611944565b6000604051808303816000865af19150503d8060008114611029576040519150601f19603f3d011682016040523d82523d6000602084013e61102e565b606091505b509150915081611041576110418161118d565b61104a81611b77565b60601c93506001600160a01b038316841461108b57604051636509115d60e01b81526001600160a01b03808516600483015285166024820152604401610477565b50505092915050565b6000813b60fe81156110b5576040516001600082873c601e19015160ff1690505b159392505050565b606083518281116110cc578092505b8381116110d7578093505b508183101561049c575060405182820380825293830193601f19601f820181165b86810151848201528101806110f85750600083830160200152603f9091011681016040529392505050565b600061049c8264457468465360d81b85611195565b6060815160016111489190611ac7565b60e81b6001600160e81b0319166a61000080600a3d393df30060a81b1782604051602001611177929190611bb3565b6040516020818303038152906040529050919050565b805160208201fd5b6000806111a1856111cb565b905060ff600053806035528260601b60015283601552605560002091506000603552509392505050565b60008151600181018060101c3d3d3e6a61000080600a3d393df300604082901b178452600a01601584012092525090565b634e487b7160e01b600052604160045260246000fd5b604051606081016001600160401b0381118282101715611234576112346111fc565b60405290565b604080519081016001600160401b0381118282101715611234576112346111fc565b604051601f8201601f191681016001600160401b0381118282101715611284576112846111fc565b604052919050565b600082601f83011261129d57600080fd5b81356001600160401b038111156112b6576112b66111fc565b6112c9601f8201601f191660200161125c565b8181528460208386010111156112de57600080fd5b816020850160208301376000918101602001919091529392505050565b60006001600160401b03821115611314576113146111fc565b5060051b60200190565b6001600160a01b038116811461133357600080fd5b50565b63ffffffff8116811461133357600080fd5b600082601f83011261135957600080fd5b8135602061136e611369836112fb565b61125c565b8281526060928302850182019282820191908785111561138d57600080fd5b8387015b858110156113ef5781818a0312156113a95760008081fd5b6113b1611212565b81356113bc8161131e565b8152818601356113cb81611336565b818701526040828101356113de81611336565b908201528452928401928101611391565b5090979650505050505050565b60008060006060848603121561141157600080fd5b83356001600160401b038082111561142857600080fd5b6114348783880161128c565b9450602086013591508082111561144a57600080fd5b61145687838801611348565b9350604086013591508082111561146c57600080fd5b506114798682870161128c565b9150509250925092565b600060408084018351855260208085015160408288015282815180855260609450606089019150838301925060005b818110156114f257835180516001600160a01b031684528581015163ffffffff9081168786015290880151168784015292840192918501916001016114b2565b509098975050505050505050565b6001600160a01b038316815260406020820181905260009061152490830184611483565b949350505050565b60006020828403121561153e57600080fd5b81356001600160401b0381111561155457600080fd5b6115248482850161128c565b60005b8381101561157b578181015183820152602001611563565b50506000910152565b6000815180845261159c816020860160208601611560565b601f01601f19169290920160200192915050565b60208152600061049c6020830184611584565b600082601f8301126115d457600080fd5b813560206115e4611369836112fb565b8083825260208201915060208460051b87010193508684111561160657600080fd5b602086015b8481101561162b57803561161e8161131e565b835291830191830161160b565b509695505050505050565b60008060006060848603121561164b57600080fd5b83356001600160401b038082111561166257600080fd5b61166e8783880161128c565b9450602086013591508082111561168457600080fd5b611456878388016115c3565b600080604083850312156116a357600080fd5b82356001600160401b03808211156116ba57600080fd5b6116c68683870161128c565b935060208501359150808211156116dc57600080fd5b506116e98582860161128c565b9150509250929050565b600082601f83011261170457600080fd5b81356020611714611369836112fb565b82815260059290921b8401810191818101908684111561173357600080fd5b8286015b8481101561162b5780356001600160401b038111156117565760008081fd5b6117648986838b010161128c565b845250918301918301611737565b60008060006060848603121561178757600080fd5b83356001600160401b038082111561179e57600080fd5b6117aa8783880161128c565b945060208601359150808211156117c057600080fd5b611456878388016116f3565b600080604083850312156117df57600080fd5b82356001600160401b03808211156117f657600080fd5b6118028683870161128c565b9350602085013591508082111561181857600080fd5b506116e985828601611348565b6000806040838503121561183857600080fd5b82356001600160401b038082111561184f57600080fd5b61185b8683870161128c565b9350602085013591508082111561187157600080fd5b506116e9858286016116f3565b60208152600061049c6020830184611483565b600080604083850312156118a457600080fd5b82356001600160401b03808211156118bb57600080fd5b6118c78683870161128c565b935060208501359150808211156118dd57600080fd5b506116e9858286016115c3565b6000806000606084860312156118ff57600080fd5b83356001600160401b038082111561191657600080fd5b6119228783880161128c565b9450602086013591508082111561193857600080fd5b6114568783880161128c565b60008251611956818460208701611560565b9190910192915050565b6000602080838503121561197357600080fd5b82516001600160401b038082111561198a57600080fd5b818501915060408083880312156119a057600080fd5b6119a861123a565b8351815284840151838111156119bd57600080fd5b80850194505087601f8501126119d257600080fd5b835192506119e2611369846112fb565b8381526060938402850186019386820191908a861115611a0157600080fd5b958701955b85871015611a645780878c031215611a1e5760008081fd5b611a26611212565b8751611a318161131e565b815287890151611a4081611336565b818a015287860151611a5181611336565b8187015283529586019591870191611a06565b5095820195909552979650505050505050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b63ffffffff828116828216039080821115611ac057611ac0611a8d565b5092915050565b808201808211156102d8576102d8611a8d565b606081526000611aed6060830186611584565b8460208401528281036040840152610d3b8185611584565b818103818111156102d8576102d8611a8d565b600082611b3557634e487b7160e01b600052601260045260246000fd5b500490565b80820281158282048414176102d8576102d8611a8d565b82815260008251611b69816020850160208701611560565b919091016020019392505050565b805160208201516bffffffffffffffffffffffff198082169291906014831015611bab5780818460140360031b1b83161693505b505050919050565b6001600160a81b0319831681528151600090611bd681600b850160208701611560565b91909101600b01939250505056fea164736f6c6343000817000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000914d7fec6aac8cd542e72bca78b30650d45643d7
-----Decoded View---------------
Arg [0] : _deployer (address): 0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000914d7fec6aac8cd542e72bca78b30650d45643d7
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.