Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"generative/BundleStorage.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title BundleStorage
* @notice Stores bundle.min.js with automatic chunking in one transaction
* @dev Simplified - only stores bundle, three.js is referenced from existing onchain source
*/
contract BundleStorage is Ownable {
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
error InvalidLibraryName();
error LibraryAlreadySet();
error LibraryNotSet();
error InvalidChunkData();
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event LibraryStored(string indexed libraryName, uint256 totalChunks, uint256 totalSize);
event LibraryUpdated(string indexed libraryName);
/*//////////////////////////////////////////////////////////////
STATE VARIABLES
//////////////////////////////////////////////////////////////*/
uint256 constant MAX_BYTES = 24575;
struct DataLocation {
address pointer;
uint48 start;
uint48 end;
}
struct Library {
DataLocation[] chunks;
uint256 totalSize;
bool exists;
}
// libraryName => Library data
mapping(string => Library) public libraries;
// Track library names
string[] public libraryNames;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor() Ownable(msg.sender) {}
/*//////////////////////////////////////////////////////////////
STORAGE FUNCTIONS
//////////////////////////////////////////////////////////////*/
/**
* @notice Store a library by providing the complete code
* @dev Handles chunking automatically in one call
* @param libraryName Name of the library (e.g., "bundle.min.js")
* @param code The complete library code as bytes
*/
function storeLibrary(
string calldata libraryName,
bytes calldata code
) external onlyOwner {
require(bytes(libraryName).length > 0, "Empty library name");
require(code.length > 0, "Empty code");
Library storage lib = libraries[libraryName];
if (lib.exists) revert LibraryAlreadySet();
// Split code into chunks
uint256 totalChunks = 0;
uint256 offset = 0;
while (offset < code.length) {
uint256 chunkSize = code.length - offset;
if (chunkSize > MAX_BYTES) {
chunkSize = MAX_BYTES;
}
bytes memory chunk = code[offset:offset + chunkSize];
address pointer = SSTORE2Write(chunk);
lib.chunks.push(DataLocation({
pointer: pointer,
start: 0,
end: uint48(chunkSize)
}));
offset += chunkSize;
totalChunks++;
}
lib.totalSize = code.length;
lib.exists = true;
if (totalChunks == 1) {
libraryNames.push(libraryName);
}
emit LibraryStored(libraryName, totalChunks, code.length);
}
/**
* @notice Update an existing library
* @param libraryName Name of the library to update
* @param code The new library code
*/
function updateLibrary(
string calldata libraryName,
bytes calldata code
) external onlyOwner {
require(bytes(libraryName).length > 0, "Empty library name");
require(code.length > 0, "Empty code");
Library storage lib = libraries[libraryName];
if (!lib.exists) revert LibraryNotSet();
// Clear existing chunks
delete lib.chunks;
lib.totalSize = 0;
// Store new chunks
uint256 offset = 0;
while (offset < code.length) {
uint256 chunkSize = code.length - offset;
if (chunkSize > MAX_BYTES) {
chunkSize = MAX_BYTES;
}
bytes memory chunk = code[offset:offset + chunkSize];
address pointer = SSTORE2Write(chunk);
lib.chunks.push(DataLocation({
pointer: pointer,
start: 0,
end: uint48(chunkSize)
}));
offset += chunkSize;
}
lib.totalSize = code.length;
emit LibraryUpdated(libraryName);
}
/*//////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/
/**
* @notice Get the full library code
* @param libraryName Name of the library
* @return The complete library code as a string
*/
function getLibrary(string calldata libraryName) external view returns (string memory) {
Library storage lib = libraries[libraryName];
if (!lib.exists) revert LibraryNotSet();
bytes memory result = new bytes(lib.totalSize);
uint256 offset = 0;
for (uint256 i = 0; i < lib.chunks.length; i++) {
DataLocation memory loc = lib.chunks[i];
bytes memory chunk = SSTORE2Read(loc.pointer, loc.start, loc.end);
for (uint256 j = 0; j < chunk.length; j++) {
result[offset++] = chunk[j];
}
}
return string(result);
}
/**
* @notice Get library info
* @param libraryName Name of the library
* @return exists Whether the library exists
* @return totalChunks Total number of chunks
* @return totalSize Total size in bytes
*/
function getLibraryInfo(string calldata libraryName)
external
view
returns (bool exists, uint256 totalChunks, uint256 totalSize)
{
Library storage lib = libraries[libraryName];
return (lib.exists, lib.chunks.length, lib.totalSize);
}
/**
* @notice Get the number of libraries stored
*/
function getLibraryCount() external view returns (uint256) {
return libraryNames.length;
}
/*//////////////////////////////////////////////////////////////
INTERNAL SSTORE2 LOGIC
//////////////////////////////////////////////////////////////*/
function SSTORE2Write(bytes memory data) internal returns (address pointer) {
bytes memory runtimeCode = abi.encodePacked(hex"00", data);
bytes memory creationCode = abi.encodePacked(
hex"63",
uint32(runtimeCode.length),
hex"80_60_0E_60_00_39_60_00_F3",
runtimeCode
);
assembly {
pointer := create(0, add(creationCode, 0x20), mload(creationCode))
if iszero(pointer) {
revert(0, 0)
}
}
}
function SSTORE2Read(address pointer, uint256 start, uint256 end) internal view returns (bytes memory) {
bytes memory data = new bytes(end - start);
assembly {
extcodecopy(pointer, add(data, 0x20), add(start, 1), sub(end, start))
}
return data;
}
}
"
},
"@openzeppelin/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
}
}}
Submitted on: 2025-11-05 14:32:31
Comments
Log in to comment.
No comments yet.