Source Code
Overview
ETH Balance
0 ETH
More Info
ContractCreator
Multichain Info
N/A
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Source Code Verified (Exact Match)
Contract Name:
PingPong
Compiler Version
v0.8.27+commit.40a35a09
Optimization Enabled:
Yes with 1000 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
pragma solidity ^0.8.27; import "@openzeppelin-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import "@openzeppelin-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin-upgradeable/utils/PausableUpgradeable.sol"; import "../../Base.sol"; import "../../../core/25-handler/IBCHandler.sol"; import "../03-zkgm/IEurekaModule.sol"; // Protocol specific packet struct PingPongPacket { bool ping; } library PingPongLib { bytes1 public constant ACK_SUCCESS = 0x01; error ErrOnlyOneChannel(); error ErrInvalidAck(); error ErrNoChannel(); error ErrInfiniteGame(); error ErrOnlyZKGM(); event Ring(bool ping); event TimedOut(); event Acknowledged(); event Zkgoblim(uint32 channelId, bytes sender, bytes message); function encode( PingPongPacket memory packet ) internal pure returns (bytes memory) { return abi.encode(packet.ping); } function decode( bytes memory packet ) internal pure returns (PingPongPacket memory) { bool ping = abi.decode(packet, (bool)); return PingPongPacket({ping: ping}); } } contract PingPong is IBCAppBase, Initializable, UUPSUpgradeable, OwnableUpgradeable, PausableUpgradeable, IEurekaModule { using PingPongLib for *; IIBCPacket private ibcHandler; uint32 private _gap0; uint64 private timeout; address private zkgmProtocol; constructor() { _disableInitializers(); } function initialize( IIBCPacket _ibcHandler, address admin, uint64 _timeout ) public initializer { __Ownable_init(admin); ibcHandler = _ibcHandler; timeout = _timeout; } function ibcAddress() public view virtual override returns (address) { return address(ibcHandler); } function initiate( PingPongPacket memory packet, uint32 channelId, uint64 localTimeout ) public { ibcHandler.sendPacket( channelId, // No height timeout 0, // Timestamp timeout localTimeout, // Raw protocol packet packet.encode() ); } function onRecvPacket( IBCPacket calldata packet, address, bytes calldata ) external virtual override onlyIBC returns (bytes memory acknowledgement) { PingPongPacket memory pp = PingPongLib.decode(packet.data); emit PingPongLib.Ring(pp.ping); uint64 localTimeout = uint64(block.timestamp * 1e9) + timeout; // Send back the packet after having reversed the bool and set the counterparty timeout initiate( PingPongPacket({ping: !pp.ping}), packet.destinationChannelId, localTimeout ); // Return protocol specific successful acknowledgement return abi.encodePacked(PingPongLib.ACK_SUCCESS); } function onAcknowledgementPacket( IBCPacket calldata, bytes calldata acknowledgement, address ) external virtual override onlyIBC { /* In practice, a more sophisticated protocol would check and execute code depending on the counterparty outcome (refund etc...). In our case, the acknowledgement will always be ACK_SUCCESS */ if ( keccak256(acknowledgement) != keccak256(abi.encodePacked(PingPongLib.ACK_SUCCESS)) ) { revert PingPongLib.ErrInvalidAck(); } emit PingPongLib.Acknowledged(); } function onTimeoutPacket( IBCPacket calldata, address ) external virtual override onlyIBC { /* Similarly to the onAcknowledgementPacket function, this indicates a failure to deliver the packet in expected time. A sophisticated protocol would revert the action done before sending this packet. */ emit PingPongLib.TimedOut(); } function onChanOpenInit( uint32, uint32, string calldata, address ) external virtual override onlyIBC {} function onChanOpenTry( uint32, uint32, uint32, string calldata, string calldata, address ) external virtual override onlyIBC {} function onChanOpenAck( uint32 channelId, uint32, string calldata, address ) external virtual override onlyIBC {} function onChanOpenConfirm( uint32 channelId, address ) external virtual override onlyIBC {} function onChanCloseInit( uint32, address ) external virtual override onlyIBC { // The ping-pong is infinite, closing the channel is disallowed. revert PingPongLib.ErrInfiniteGame(); } function onChanCloseConfirm( uint32, address ) external virtual override onlyIBC { // Symmetric to onChanCloseInit revert PingPongLib.ErrInfiniteGame(); } function _authorizeUpgrade( address newImplementation ) internal override onlyOwner {} function setZkgm( address zkgm ) public onlyOwner { zkgmProtocol = zkgm; } function onZkgm(uint32 channelId, bytes calldata sender, bytes calldata message) public { if (msg.sender != zkgmProtocol) { revert PingPongLib.ErrOnlyZKGM(); } emit PingPongLib.Zkgoblim(channelId, sender, message); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.20; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Storage of the initializable contract. * * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions * when using with upgradeable contracts. * * @custom:storage-location erc7201:openzeppelin.storage.Initializable */ struct InitializableStorage { /** * @dev Indicates that the contract has been initialized. */ uint64 _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool _initializing; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00; /** * @dev The contract is already initialized. */ error InvalidInitialization(); /** * @dev The contract is not initializing. */ error NotInitializing(); /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint64 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in * production. * * Emits an {Initialized} event. */ modifier initializer() { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); // Cache values to avoid duplicated sloads bool isTopLevelCall = !$._initializing; uint64 initialized = $._initialized; // Allowed calls: // - initialSetup: the contract is not in the initializing state and no previous version was // initialized // - construction: the contract is initialized at version 1 (no reininitialization) and the // current contract is just being deployed bool initialSetup = initialized == 0 && isTopLevelCall; bool construction = initialized == 1 && address(this).code.length == 0; if (!initialSetup && !construction) { revert InvalidInitialization(); } $._initialized = 1; if (isTopLevelCall) { $._initializing = true; } _; if (isTopLevelCall) { $._initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint64 version) { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing || $._initialized >= version) { revert InvalidInitialization(); } $._initialized = version; $._initializing = true; _; $._initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { _checkInitializing(); _; } /** * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}. */ function _checkInitializing() internal view virtual { if (!_isInitializing()) { revert NotInitializing(); } } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing) { revert InvalidInitialization(); } if ($._initialized != type(uint64).max) { $._initialized = type(uint64).max; emit Initialized(type(uint64).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint64) { return _getInitializableStorage()._initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _getInitializableStorage()._initializing; } /** * @dev Returns a pointer to the storage namespace. */ // solhint-disable-next-line var-name-mixedcase function _getInitializableStorage() private pure returns (InitializableStorage storage $) { assembly { $.slot := INITIALIZABLE_STORAGE } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.20; import {IERC1822Proxiable} from "@openzeppelin/interfaces/draft-IERC1822.sol"; import {ERC1967Utils} from "@openzeppelin/proxy/ERC1967/ERC1967Utils.sol"; import {Initializable} from "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. */ abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable { /// @custom:oz-upgrades-unsafe-allow state-variable-immutable address private immutable __self = address(this); /** * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)` * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called, * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string. * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function * during an upgrade. */ string public constant UPGRADE_INTERFACE_VERSION = "5.0.0"; /** * @dev The call is from an unauthorized context. */ error UUPSUnauthorizedCallContext(); /** * @dev The storage `slot` is unsupported as a UUID. */ error UUPSUnsupportedProxiableUUID(bytes32 slot); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { _checkProxy(); _; } /** * @dev Check that the execution is not being performed through a delegate call. This allows a function to be * callable on the implementing contract but not through proxies. */ modifier notDelegated() { _checkNotDelegated(); _; } function __UUPSUpgradeable_init() internal onlyInitializing { } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /** * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the * implementation. It is used to validate the implementation's compatibility when performing an upgrade. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier. */ function proxiableUUID() external view virtual notDelegated returns (bytes32) { return ERC1967Utils.IMPLEMENTATION_SLOT; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. * * @custom:oz-upgrades-unsafe-allow-reachable delegatecall */ function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallUUPS(newImplementation, data); } /** * @dev Reverts if the execution is not performed via delegatecall or the execution * context is not of a proxy with an ERC1967-compliant implementation pointing to self. * See {_onlyProxy}. */ function _checkProxy() internal view virtual { if ( address(this) == __self || // Must be called through delegatecall ERC1967Utils.getImplementation() != __self // Must be called through an active proxy ) { revert UUPSUnauthorizedCallContext(); } } /** * @dev Reverts if the execution is performed via delegatecall. * See {notDelegated}. */ function _checkNotDelegated() internal view virtual { if (address(this) != __self) { // Must not be called through delegatecall revert UUPSUnauthorizedCallContext(); } } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; /** * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call. * * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value * is expected to be the implementation slot in ERC1967. * * Emits an {IERC1967-Upgraded} event. */ function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private { try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) { if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) { revert UUPSUnsupportedProxiableUUID(slot); } ERC1967Utils.upgradeToAndCall(newImplementation, data); } catch { // The implementation is not UUPS revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol) pragma solidity ^0.8.20; import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol"; import {Initializable} from "../proxy/utils/Initializable.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 OwnableUpgradeable is Initializable, ContextUpgradeable { /// @custom:storage-location erc7201:openzeppelin.storage.Ownable struct OwnableStorage { address _owner; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300; function _getOwnableStorage() private pure returns (OwnableStorage storage $) { assembly { $.slot := OwnableStorageLocation } } /** * @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. */ function __Ownable_init(address initialOwner) internal onlyInitializing { __Ownable_init_unchained(initialOwner); } function __Ownable_init_unchained(address initialOwner) internal onlyInitializing { 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) { OwnableStorage storage $ = _getOwnableStorage(); 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 { OwnableStorage storage $ = _getOwnableStorage(); address oldOwner = $._owner; $._owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol) pragma solidity ^0.8.20; import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol"; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract PausableUpgradeable is Initializable, ContextUpgradeable { /// @custom:storage-location erc7201:openzeppelin.storage.Pausable struct PausableStorage { bool _paused; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300; function _getPausableStorage() private pure returns (PausableStorage storage $) { assembly { $.slot := PausableStorageLocation } } /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); /** * @dev The operation failed because the contract is paused. */ error EnforcedPause(); /** * @dev The operation failed because the contract is not paused. */ error ExpectedPause(); /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal onlyInitializing { __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { PausableStorage storage $ = _getPausableStorage(); $._paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { PausableStorage storage $ = _getPausableStorage(); return $._paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { if (paused()) { revert EnforcedPause(); } } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { if (!paused()) { revert ExpectedPause(); } } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { PausableStorage storage $ = _getPausableStorage(); $._paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { PausableStorage storage $ = _getPausableStorage(); $._paused = false; emit Unpaused(_msgSender()); } }
pragma solidity ^0.8.27; import "../core/05-port/IIBCModule.sol"; library IBCAppLib { error ErrNotIBC(); error ErrNotImplemented(); } /** * @dev Base contract of the IBC App protocol */ abstract contract IBCAppBase is IIBCModule { /** * @dev Throws if called by any account other than the IBC contract. */ modifier onlyIBC() { _checkIBC(); _; } /** * @dev Returns the address of the IBC contract. */ function ibcAddress() public view virtual returns (address); /** * @dev Throws if the sender is not the IBC contract. */ function _checkIBC() internal view virtual { if (ibcAddress() != msg.sender) { revert IBCAppLib.ErrNotIBC(); } } /** * @dev See IIBCModule-onChanOpenInit * * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanOpenInit( uint32, uint32, string calldata, address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onChanOpenTry * * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanOpenTry( uint32, uint32, uint32, string calldata, string calldata, address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onChanOpenAck * * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanOpenAck( uint32, uint32, string calldata, address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onChanOpenConfirm * * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanOpenConfirm( uint32, address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onChanCloseInit * * NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanCloseInit( uint32, address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onChanCloseConfirm * * NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onChanCloseConfirm( uint32, address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onRecvPacket * * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onRecvPacket( IBCPacket calldata, address, bytes calldata ) external virtual override onlyIBC returns (bytes memory acknowledgement) {} /** * @dev See IIBCModule-onRecvIntentPacket * * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onRecvIntentPacket( IBCPacket calldata, address, bytes calldata ) external virtual override onlyIBC returns (bytes memory) { revert IBCAppLib.ErrNotImplemented(); } /** * @dev See IIBCModule-onAcknowledgementPacket * * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onAcknowledgementPacket( IBCPacket calldata, bytes calldata, address ) external virtual override onlyIBC {} /** * @dev See IIBCModule-onTimeoutPacket * * NOTE: You must apply an `onlyIBC` modifier to the function if a derived contract overrides it. */ function onTimeoutPacket( IBCPacket calldata, address ) external virtual override onlyIBC {} }
pragma solidity ^0.8.27; import "../24-host/IBCStore.sol"; import "../02-client/IBCClient.sol"; import "../03-connection/IBCConnection.sol"; import "../04-channel/IBCChannel.sol"; import "../04-channel/IBCPacket.sol"; import "@openzeppelin-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import "@openzeppelin-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin-upgradeable/utils/ContextUpgradeable.sol"; import "@openzeppelin/utils/Context.sol"; /** * @dev IBCHandler is a contract that implements [ICS-25](https://github.com/cosmos/ibc/tree/main/spec/core/ics-025-handler-interface). */ abstract contract IBCHandler is Initializable, UUPSUpgradeable, OwnableUpgradeable, IBCStore, IBCClient, IBCConnectionImpl, IBCChannelImpl, IBCPacketImpl { constructor() { _disableInitializers(); } function initialize( address admin ) public virtual initializer { __Ownable_init(admin); __UUPSUpgradeable_init(); commitments[nextClientSequencePath] = bytes32(uint256(1)); commitments[nextChannelSequencePath] = bytes32(uint256(1)); commitments[nextConnectionSequencePath] = bytes32(uint256(1)); } function _authorizeUpgrade( address newImplementation ) internal override onlyOwner {} }
pragma solidity ^0.8.27; interface IEurekaModule { function onZkgm( uint32 channelId, bytes calldata sender, bytes calldata message ) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC1822.sol) pragma solidity ^0.8.20; /** * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified * proxy whose upgrades are fully controlled by the current implementation. */ interface IERC1822Proxiable { /** * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation * address. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. */ function proxiableUUID() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol) pragma solidity ^0.8.20; import {IBeacon} from "../beacon/IBeacon.sol"; import {Address} from "../../utils/Address.sol"; import {StorageSlot} from "../../utils/StorageSlot.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. */ library ERC1967Utils { // We re-declare ERC-1967 events here because they can't be used directly from IERC1967. // This will be fixed in Solidity 0.8.21. At that point we should remove these events. /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Emitted when the beacon is changed. */ event BeaconUpgraded(address indexed beacon); /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1. */ // solhint-disable-next-line private-vars-leading-underscore bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev The `implementation` of the proxy is invalid. */ error ERC1967InvalidImplementation(address implementation); /** * @dev The `admin` of the proxy is invalid. */ error ERC1967InvalidAdmin(address admin); /** * @dev The `beacon` of the proxy is invalid. */ error ERC1967InvalidBeacon(address beacon); /** * @dev An upgrade function sees `msg.value > 0` that may be lost. */ error ERC1967NonPayable(); /** * @dev Returns the current implementation address. */ function getImplementation() internal view returns (address) { return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { if (newImplementation.code.length == 0) { revert ERC1967InvalidImplementation(newImplementation); } StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Performs implementation upgrade with additional setup call if data is nonempty. * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected * to avoid stuck value in the contract. * * Emits an {IERC1967-Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); if (data.length > 0) { Address.functionDelegateCall(newImplementation, data); } else { _checkNonPayable(); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1. */ // solhint-disable-next-line private-vars-leading-underscore bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Returns the current admin. * * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103` */ function getAdmin() internal view returns (address) { return StorageSlot.getAddressSlot(ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { if (newAdmin == address(0)) { revert ERC1967InvalidAdmin(address(0)); } StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {IERC1967-AdminChanged} event. */ function changeAdmin(address newAdmin) internal { emit AdminChanged(getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1. */ // solhint-disable-next-line private-vars-leading-underscore bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Returns the current beacon. */ function getBeacon() internal view returns (address) { return StorageSlot.getAddressSlot(BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { if (newBeacon.code.length == 0) { revert ERC1967InvalidBeacon(newBeacon); } StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon; address beaconImplementation = IBeacon(newBeacon).implementation(); if (beaconImplementation.code.length == 0) { revert ERC1967InvalidImplementation(beaconImplementation); } } /** * @dev Change the beacon and trigger a setup call if data is nonempty. * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected * to avoid stuck value in the contract. * * Emits an {IERC1967-BeaconUpgraded} event. * * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for * efficiency. */ function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0) { Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data); } else { _checkNonPayable(); } } /** * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract * if an upgrade doesn't perform an initialization call. */ function _checkNonPayable() private { if (msg.value > 0) { revert ERC1967NonPayable(); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } 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; } }
pragma solidity ^0.8.27; import "../Types.sol"; // IIBCModule defines an interface that implements all the callbacks // that modules must define as specified in ICS-26 // https://github.com/cosmos/ibc/blob/2921c5cec7b18e4ef77677e16a6b693051ae3b35/spec/core/ics-026-routing-module/README.md interface IIBCModule { function onChanOpenInit( uint32 connectionId, uint32 channelId, string calldata version, address relayer ) external; function onChanOpenTry( uint32 connectionId, uint32 channelId, uint32 counterpartyChannelId, string calldata version, string calldata counterpartyVersion, address relayer ) external; function onChanOpenAck( uint32 channelId, uint32 counterpartyChannelId, string calldata counterpartyVersion, address relayer ) external; function onChanOpenConfirm(uint32 channelId, address relayer) external; function onChanCloseInit(uint32 channelId, address relayer) external; function onChanCloseConfirm(uint32 channelId, address relayer) external; function onRecvIntentPacket( IBCPacket calldata packet, address marketMaker, bytes calldata marketMakerMsg ) external returns (bytes memory); function onRecvPacket( IBCPacket calldata packet, address relayer, bytes calldata relayerMsg ) external returns (bytes memory); function onAcknowledgementPacket( IBCPacket calldata packet, bytes calldata acknowledgement, address relayer ) external; function onTimeoutPacket(IBCPacket calldata, address relayer) external; }
pragma solidity ^0.8.27; import "../02-client/ILightClient.sol"; import "../05-port/IIBCModule.sol"; import "../Types.sol"; library IBCStoreLib { string public constant COMMITMENT_PREFIX = "wasm"; bytes1 public constant COMMITMENT_PREFIX_PATH = 0x03; } abstract contract IBCStore { // Commitments // keccak256(IBC-compatible-store-path) => keccak256(IBC-compatible-commitment) mapping(bytes32 => bytes32) public commitments; // ClientType -> Address mapping(string => address) public clientRegistry; // ClientId -> ClientType mapping(uint32 => string) public clientTypes; // ClientId -> Address mapping(uint32 => address) public clientImpls; // ConnectionId -> Connection mapping(uint32 => IBCConnection) public connections; // ChannelId -> Channel mapping(uint32 => IBCChannel) public channels; // ChannelId -> PortId mapping(uint32 => address) public channelOwner; // Sequences for identifier bytes32 constant nextClientSequencePath = keccak256("nextClientSequence"); bytes32 constant nextConnectionSequencePath = keccak256("nextConnectionSequence"); bytes32 constant nextChannelSequencePath = keccak256("nextChannelSequence"); function getClient( uint32 clientId ) public view returns (ILightClient) { return getClientInternal(clientId); } function getClientInternal( uint32 clientId ) internal view returns (ILightClient) { address clientImpl = clientImpls[clientId]; if (clientImpl == address(0)) { revert IBCErrors.ErrClientNotFound(); } return ILightClient(clientImpl); } function lookupModuleByChannel( uint32 channelId ) internal view virtual returns (IIBCModule) { address module = channelOwner[channelId]; if (module == address(0)) { revert IBCErrors.ErrModuleNotFound(); } return IIBCModule(module); } function claimChannel(address portId, uint32 channelId) internal { channelOwner[channelId] = portId; } function authenticateChannelOwner( uint32 channelId ) internal view returns (bool) { return msg.sender == channelOwner[channelId]; } function ensureConnectionState( uint32 connectionId ) internal view returns (uint32) { IBCConnection storage connection = connections[connectionId]; if (connection.state != IBCConnectionState.Open) { revert IBCErrors.ErrInvalidConnectionState(); } return connection.clientId; } function ensureChannelState( uint32 channelId ) internal view returns (IBCChannel storage) { IBCChannel storage channel = channels[channelId]; if (channel.state != IBCChannelState.Open) { revert IBCErrors.ErrInvalidChannelState(); } return channel; } }
pragma solidity ^0.8.27; import "./ILightClient.sol"; import "../25-handler/IBCMsgs.sol"; import "../24-host/IBCStore.sol"; import "../24-host/IBCCommitment.sol"; import "../02-client/IIBCClient.sol"; library IBCClientLib { event RegisterClient(string clientType, address clientAddress); event CreateClient( string clientType, uint32 clientId, string counterpartyChainId ); event UpdateClient(uint32 clientId, uint64 height); event Misbehaviour(uint32 clientId); } /** * @dev IBCClient is a contract that implements [ICS-2](https://github.com/cosmos/ibc/tree/main/spec/core/ics-002-client-semantics). */ abstract contract IBCClient is IBCStore, IIBCClient { /** * @dev registerClient registers a new client type into the client registry */ function registerClient( string calldata clientType, ILightClient client ) external override { if (address(clientRegistry[clientType]) != address(0)) { revert IBCErrors.ErrClientTypeAlreadyExists(); } clientRegistry[clientType] = address(client); emit IBCClientLib.RegisterClient(clientType, address(client)); } /** * @dev createClient creates a new client state and populates it with a given consensus state */ function createClient( IBCMsgs.MsgCreateClient calldata msg_ ) external override returns (uint32) { address clientImpl = clientRegistry[msg_.clientType]; if (clientImpl == address(0)) { revert IBCErrors.ErrClientTypeNotFound(); } uint32 clientId = generateClientIdentifier(); clientTypes[clientId] = msg_.clientType; clientImpls[clientId] = clientImpl; (ConsensusStateUpdate memory update, string memory counterpartyChainId) = ILightClient(clientImpl).createClient( clientId, msg_.clientStateBytes, msg_.consensusStateBytes ); commitments[IBCCommitment.clientStateCommitmentKey(clientId)] = update.clientStateCommitment; commitments[IBCCommitment.consensusStateCommitmentKey( clientId, update.height )] = update.consensusStateCommitment; emit IBCClientLib.CreateClient( msg_.clientType, clientId, counterpartyChainId ); return clientId; } /** * @dev updateClient updates the consensus state and the state root from a provided header */ function updateClient( IBCMsgs.MsgUpdateClient calldata msg_ ) external override { ConsensusStateUpdate memory update = getClientInternal(msg_.clientId) .updateClient(msg_.clientId, msg_.clientMessage); commitments[IBCCommitment.clientStateCommitmentKey(msg_.clientId)] = update.clientStateCommitment; commitments[IBCCommitment.consensusStateCommitmentKey( msg_.clientId, update.height )] = update.consensusStateCommitment; emit IBCClientLib.UpdateClient(msg_.clientId, update.height); } /** * @dev misbehaviour submits a misbehaviour to the client for it to take action if it is correct */ function misbehaviour( IBCMsgs.MsgMisbehaviour calldata msg_ ) external override { getClientInternal(msg_.clientId).misbehaviour( msg_.clientId, msg_.clientMessage ); emit IBCClientLib.Misbehaviour(msg_.clientId); } function generateClientIdentifier() internal returns (uint32) { uint32 nextClientSequence = uint32(uint256(commitments[nextClientSequencePath])); commitments[nextClientSequencePath] = bytes32(uint256(nextClientSequence + 1)); return nextClientSequence; } }
pragma solidity ^0.8.27; import "../24-host/IBCStore.sol"; import "../25-handler/IBCMsgs.sol"; import "../24-host/IBCCommitment.sol"; import "../03-connection/IIBCConnection.sol"; library IBCConnectionLib { event ConnectionOpenInit( uint32 connectionId, uint32 clientId, uint32 counterpartyClientId ); event ConnectionOpenTry( uint32 connectionId, uint32 clientId, uint32 counterpartyClientId, uint32 counterpartyConnectionId ); event ConnectionOpenAck( uint32 connectionId, uint32 clientId, uint32 counterpartyClientId, uint32 counterpartyConnectionId ); event ConnectionOpenConfirm( uint32 connectionId, uint32 clientId, uint32 counterpartyClientId, uint32 counterpartyConnectionId ); } /** * @dev IBCConnection is a contract that implements [ICS-3](https://github.com/cosmos/ibc/tree/main/spec/core/ics-003-connection-semantics). */ abstract contract IBCConnectionImpl is IBCStore, IIBCConnection { /** * @dev connectionOpenInit initialises a connection attempt on chain A. The generated connection identifier * is returned. */ function connectionOpenInit( IBCMsgs.MsgConnectionOpenInit calldata msg_ ) external override returns (uint32) { uint32 connectionId = generateConnectionIdentifier(); IBCConnection storage connection = connections[connectionId]; connection.clientId = msg_.clientId; connection.state = IBCConnectionState.Init; connection.counterpartyClientId = msg_.counterpartyClientId; commitConnection(connectionId, connection); emit IBCConnectionLib.ConnectionOpenInit( connectionId, msg_.clientId, msg_.counterpartyClientId ); return connectionId; } /** * @dev connectionOpenTry relays notice of a connection attempt on chain A to chain B (this * code is executed on chain B). */ function connectionOpenTry( IBCMsgs.MsgConnectionOpenTry calldata msg_ ) external override returns (uint32) { uint32 connectionId = generateConnectionIdentifier(); IBCConnection storage connection = connections[connectionId]; connection.clientId = msg_.clientId; connection.state = IBCConnectionState.TryOpen; connection.counterpartyClientId = msg_.counterpartyClientId; connection.counterpartyConnectionId = msg_.counterpartyConnectionId; IBCConnection memory expectedConnection = IBCConnection({ state: IBCConnectionState.Init, clientId: msg_.counterpartyClientId, counterpartyClientId: msg_.clientId, counterpartyConnectionId: 0 }); if ( !verifyConnectionState( connection, msg_.proofHeight, msg_.proofInit, msg_.counterpartyConnectionId, expectedConnection ) ) { revert IBCErrors.ErrInvalidProof(); } commitConnection(connectionId, connection); emit IBCConnectionLib.ConnectionOpenTry( connectionId, msg_.clientId, msg_.counterpartyClientId, msg_.counterpartyConnectionId ); return connectionId; } /** * @dev connectionOpenAck relays acceptance of a connection open attempt from chain B back * to chain A (this code is executed on chain A). */ function connectionOpenAck( IBCMsgs.MsgConnectionOpenAck calldata msg_ ) external override { IBCConnection storage connection = connections[msg_.connectionId]; if (connection.state != IBCConnectionState.Init) { revert IBCErrors.ErrInvalidConnectionState(); } IBCConnection memory expectedConnection = IBCConnection({ state: IBCConnectionState.TryOpen, clientId: connection.counterpartyClientId, counterpartyClientId: connection.clientId, counterpartyConnectionId: msg_.connectionId }); if ( !verifyConnectionState( connection, msg_.proofHeight, msg_.proofTry, msg_.counterpartyConnectionId, expectedConnection ) ) { revert IBCErrors.ErrInvalidProof(); } connection.state = IBCConnectionState.Open; connection.counterpartyConnectionId = msg_.counterpartyConnectionId; commitConnection(msg_.connectionId, connection); emit IBCConnectionLib.ConnectionOpenAck( msg_.connectionId, connection.clientId, connection.counterpartyClientId, connection.counterpartyConnectionId ); } /** * @dev connectionOpenConfirm confirms opening of a connection on chain A to chain B, after * which the connection is open on both chains (this code is executed on chain B). */ function connectionOpenConfirm( IBCMsgs.MsgConnectionOpenConfirm calldata msg_ ) external override { IBCConnection storage connection = connections[msg_.connectionId]; if (connection.state != IBCConnectionState.TryOpen) { revert IBCErrors.ErrInvalidConnectionState(); } IBCConnection memory expectedConnection = IBCConnection({ state: IBCConnectionState.Open, clientId: connection.counterpartyClientId, counterpartyClientId: connection.clientId, counterpartyConnectionId: msg_.connectionId }); if ( !verifyConnectionState( connection, msg_.proofHeight, msg_.proofAck, connection.counterpartyConnectionId, expectedConnection ) ) { revert IBCErrors.ErrInvalidProof(); } connection.state = IBCConnectionState.Open; commitConnection(msg_.connectionId, connection); emit IBCConnectionLib.ConnectionOpenConfirm( msg_.connectionId, connection.clientId, connection.counterpartyClientId, connection.counterpartyConnectionId ); } function encodeConnection( IBCConnection memory connection ) internal pure returns (bytes32) { return keccak256(abi.encode(connection)); } function encodeConnectionStorage( IBCConnection storage connection ) internal pure returns (bytes32) { return keccak256(abi.encode(connection)); } function commitConnection( uint32 connectionId, IBCConnection storage connection ) internal { commitments[IBCCommitment.connectionCommitmentKey(connectionId)] = encodeConnectionStorage(connection); } function verifyConnectionState( IBCConnection storage connection, uint64 height, bytes calldata proof, uint32 connectionId, IBCConnection memory counterpartyConnection ) internal returns (bool) { return getClientInternal(connection.clientId).verifyMembership( connection.clientId, height, proof, abi.encodePacked( IBCCommitment.connectionCommitmentKey(connectionId) ), abi.encodePacked(encodeConnection(counterpartyConnection)) ); } function generateConnectionIdentifier() internal returns (uint32) { uint32 nextConnectionSequence = uint32(uint256(commitments[nextConnectionSequencePath])); commitments[nextConnectionSequencePath] = bytes32(uint256(nextConnectionSequence + 1)); return nextConnectionSequence; } }
pragma solidity ^0.8.27; import "solady/utils/LibString.sol"; import "../24-host/IBCStore.sol"; import "../25-handler/IBCMsgs.sol"; import "../24-host/IBCCommitment.sol"; import "../04-channel/IIBCChannel.sol"; import "../05-port/IIBCModule.sol"; import "../../lib/Hex.sol"; library IBCChannelLib { event ChannelOpenInit( address portId, uint32 channelId, bytes counterpartyPortId, uint32 connectionId, string version ); event ChannelOpenTry( address portId, uint32 channelId, bytes counterpartyPortId, uint32 counterpartyChannelId, uint32 connectionId, string counterpartyVersion ); event ChannelOpenAck( address portId, uint32 channelId, bytes counterpartyPortId, uint32 counterpartyChannelId, uint32 connectionId ); event ChannelOpenConfirm( address portId, uint32 channelId, bytes counterpartyPortId, uint32 counterpartyChannelId, uint32 connectionId ); event ChannelCloseInit( address portId, uint32 channelId, bytes counterpartyPortId, uint32 counterpartyChannelId ); event ChannelCloseConfirm( address portId, uint32 channelId, bytes counterpartyPortId, uint32 counterpartyChannelId ); } /** * @dev IBCChannelHandshake is a contract that implements [ICS-4](https://github.com/cosmos/ibc/tree/main/spec/core/ics-004-channel-and-packet-semantics). */ abstract contract IBCChannelImpl is IBCStore, IIBCChannel { using LibString for *; /** * @dev channelOpenInit is called by a module to initiate a channel opening handshake with a module on another chain. */ function channelOpenInit( IBCMsgs.MsgChannelOpenInit calldata msg_ ) external override returns (uint32) { ensureConnectionState(msg_.connectionId); uint32 channelId = generateChannelIdentifier(); IBCChannel storage channel = channels[channelId]; channel.state = IBCChannelState.Init; channel.connectionId = msg_.connectionId; channel.version = msg_.version; channel.counterpartyPortId = msg_.counterpartyPortId; commitChannel(channelId, channel); claimChannel(msg_.portId, channelId); IIBCModule(msg_.portId).onChanOpenInit( msg_.connectionId, channelId, msg_.version, msg_.relayer ); emit IBCChannelLib.ChannelOpenInit( msg_.portId, channelId, channel.counterpartyPortId, msg_.connectionId, msg_.version ); return channelId; } /** * @dev channelOpenTry is called by a module to accept the first step of a channel opening handshake initiated by a module on another chain. */ function channelOpenTry( IBCMsgs.MsgChannelOpenTry calldata msg_ ) external override returns (uint32) { if (msg_.channel.state != IBCChannelState.TryOpen) { revert IBCErrors.ErrInvalidChannelState(); } uint32 clientId = ensureConnectionState(msg_.channel.connectionId); IBCChannel memory expectedChannel = IBCChannel({ state: IBCChannelState.Init, counterpartyChannelId: 0, connectionId: getCounterpartyConnection(msg_.channel.connectionId), counterpartyPortId: abi.encodePacked(msg_.portId), version: msg_.counterpartyVersion }); if ( !verifyChannelState( clientId, msg_.proofHeight, msg_.proofInit, msg_.channel.counterpartyChannelId, expectedChannel ) ) { revert IBCErrors.ErrInvalidProof(); } uint32 channelId = generateChannelIdentifier(); channels[channelId] = msg_.channel; commitChannelCalldata(channelId, msg_.channel); claimChannel(msg_.portId, channelId); IIBCModule(msg_.portId).onChanOpenTry( msg_.channel.connectionId, channelId, msg_.channel.counterpartyChannelId, msg_.channel.version, msg_.counterpartyVersion, msg_.relayer ); emit IBCChannelLib.ChannelOpenTry( msg_.portId, channelId, msg_.channel.counterpartyPortId, msg_.channel.counterpartyChannelId, msg_.channel.connectionId, msg_.counterpartyVersion ); return channelId; } /** * @dev channelOpenAck is called by the handshake-originating module to acknowledge the acceptance of the initial request by the counterparty module on the other chain. */ function channelOpenAck( IBCMsgs.MsgChannelOpenAck calldata msg_ ) external override { IBCChannel storage channel = channels[msg_.channelId]; if (channel.state != IBCChannelState.Init) { revert IBCErrors.ErrInvalidChannelState(); } uint32 clientId = ensureConnectionState(channel.connectionId); address portId = channelOwner[msg_.channelId]; IBCChannel memory expectedChannel = IBCChannel({ state: IBCChannelState.TryOpen, counterpartyChannelId: msg_.channelId, connectionId: getCounterpartyConnection(channel.connectionId), counterpartyPortId: abi.encodePacked(portId), version: msg_.counterpartyVersion }); if ( !verifyChannelState( clientId, msg_.proofHeight, msg_.proofTry, msg_.counterpartyChannelId, expectedChannel ) ) { revert IBCErrors.ErrInvalidProof(); } channel.state = IBCChannelState.Open; channel.version = msg_.counterpartyVersion; channel.counterpartyChannelId = msg_.counterpartyChannelId; commitChannel(msg_.channelId, channel); IIBCModule(portId).onChanOpenAck( msg_.channelId, msg_.counterpartyChannelId, msg_.counterpartyVersion, msg_.relayer ); emit IBCChannelLib.ChannelOpenAck( portId, msg_.channelId, channel.counterpartyPortId, msg_.counterpartyChannelId, channel.connectionId ); } /** * @dev channelOpenConfirm is called by the counterparty module to close their end of the channel, since the other end has been closed. */ function channelOpenConfirm( IBCMsgs.MsgChannelOpenConfirm calldata msg_ ) external override { IBCChannel storage channel = channels[msg_.channelId]; if (channel.state != IBCChannelState.TryOpen) { revert IBCErrors.ErrInvalidChannelState(); } uint32 clientId = ensureConnectionState(channel.connectionId); address portId = channelOwner[msg_.channelId]; IBCChannel memory expectedChannel = IBCChannel({ state: IBCChannelState.Open, counterpartyChannelId: msg_.channelId, connectionId: getCounterpartyConnection(channel.connectionId), counterpartyPortId: abi.encodePacked(portId), version: channel.version }); if ( !verifyChannelState( clientId, msg_.proofHeight, msg_.proofAck, channel.counterpartyChannelId, expectedChannel ) ) { revert IBCErrors.ErrInvalidProof(); } channel.state = IBCChannelState.Open; commitChannel(msg_.channelId, channel); IIBCModule(portId).onChanOpenConfirm(msg_.channelId, msg_.relayer); emit IBCChannelLib.ChannelOpenConfirm( portId, msg_.channelId, channel.counterpartyPortId, channel.counterpartyChannelId, channel.connectionId ); } /** * @dev channelCloseInit is called by either module to close their end of the channel. Once closed, channels cannot be reopened. */ function channelCloseInit( IBCMsgs.MsgChannelCloseInit calldata msg_ ) external override { IBCChannel storage channel = channels[msg_.channelId]; if (channel.state != IBCChannelState.Open) { revert IBCErrors.ErrInvalidChannelState(); } ensureConnectionState(channel.connectionId); channel.state = IBCChannelState.Closed; commitChannel(msg_.channelId, channel); address portId = channelOwner[msg_.channelId]; IIBCModule(portId).onChanCloseInit(msg_.channelId, msg_.relayer); emit IBCChannelLib.ChannelCloseInit( portId, msg_.channelId, channel.counterpartyPortId, channel.counterpartyChannelId ); } /** * @dev channelCloseConfirm is called by the counterparty module to close their end of the * channel, since the other end has been closed. */ function channelCloseConfirm( IBCMsgs.MsgChannelCloseConfirm calldata msg_ ) external override { IBCChannel storage channel = channels[msg_.channelId]; if (channel.state != IBCChannelState.Open) { revert IBCErrors.ErrInvalidChannelState(); } uint32 clientId = ensureConnectionState(channel.connectionId); address portId = channelOwner[msg_.channelId]; IBCChannel memory expectedChannel = IBCChannel({ state: IBCChannelState.Closed, counterpartyChannelId: msg_.channelId, connectionId: getCounterpartyConnection(channel.connectionId), counterpartyPortId: abi.encodePacked(portId), version: channel.version }); if ( !verifyChannelState( clientId, msg_.proofHeight, msg_.proofInit, channel.counterpartyChannelId, expectedChannel ) ) { revert IBCErrors.ErrInvalidProof(); } channel.state = IBCChannelState.Closed; commitChannel(msg_.channelId, channel); IIBCModule(portId).onChanCloseConfirm(msg_.channelId, msg_.relayer); emit IBCChannelLib.ChannelCloseConfirm( portId, msg_.channelId, channel.counterpartyPortId, channel.counterpartyChannelId ); } function encodeChannel( IBCChannel memory channel ) internal pure returns (bytes32) { return keccak256(abi.encode(channel)); } function commitChannel( uint32 channelId, IBCChannel storage channel ) internal { commitments[IBCCommitment.channelCommitmentKey(channelId)] = encodeChannel(channel); } function commitChannelCalldata( uint32 channelId, IBCChannel calldata channel ) internal { commitments[IBCCommitment.channelCommitmentKey(channelId)] = encodeChannelCalldata(channel); } function encodeChannelCalldata( IBCChannel calldata channel ) internal pure returns (bytes32) { return keccak256(abi.encode(channel)); } function verifyChannelState( uint32 clientId, uint64 height, bytes calldata proof, uint32 channelId, IBCChannel memory channel ) internal returns (bool) { return getClientInternal(clientId).verifyMembership( clientId, height, proof, abi.encodePacked(IBCCommitment.channelCommitmentKey(channelId)), abi.encodePacked(encodeChannel(channel)) ); } function getCounterpartyConnection( uint32 connectionId ) internal view returns (uint32) { return connections[connectionId].counterpartyConnectionId; } function generateChannelIdentifier() internal returns (uint32) { uint32 nextChannelSequence = uint32(uint256(commitments[nextChannelSequencePath])); commitments[nextChannelSequencePath] = bytes32(uint256(nextChannelSequence + 1)); return nextChannelSequence; } }
pragma solidity ^0.8.27; import "../24-host/IBCStore.sol"; import "../25-handler/IBCMsgs.sol"; import "../24-host/IBCStore.sol"; import "../24-host/IBCCommitment.sol"; import "../04-channel/IIBCPacket.sol"; import "../05-port/IIBCModule.sol"; import "../Types.sol"; library IBCPacketLib { bytes32 public constant COMMITMENT_MAGIC = 0x0100000000000000000000000000000000000000000000000000000000000000; bytes32 public constant COMMITMENT_NULL = bytes32(uint256(0)); event PacketSend(IBCPacket packet); event PacketRecv(IBCPacket packet, address maker, bytes makerMsg); event IntentPacketRecv(IBCPacket packet, address maker, bytes makerMsg); event WriteAck(IBCPacket packet, bytes acknowledgement); event PacketAck(IBCPacket packet, bytes acknowledgement, address maker); event PacketTimeout(IBCPacket packet, address maker); function commitAcksMemory( bytes[] memory acks ) internal pure returns (bytes32) { return mergeAck(keccak256(abi.encode(acks))); } function commitAcks( bytes[] calldata acks ) internal pure returns (bytes32) { return mergeAck(keccak256(abi.encode(acks))); } function commitAck( bytes calldata ack ) internal pure returns (bytes32) { return mergeAck(keccak256(abi.encodePacked(ack))); } function commitAckMemory( bytes memory ack ) internal pure returns (bytes32) { return mergeAck(keccak256(abi.encodePacked(ack))); } function commitPacketsMemory( IBCPacket[] memory packets ) internal pure returns (bytes32) { return keccak256(abi.encode(packets)); } function commitPackets( IBCPacket[] calldata packets ) internal pure returns (bytes32) { return keccak256(abi.encode(packets)); } function commitPacketMemory( IBCPacket memory packet ) internal pure returns (bytes32) { return keccak256(abi.encode(packet)); } function commitPacket( IBCPacket calldata packet ) internal pure returns (bytes32) { return keccak256(abi.encode(packet)); } function mergeAck( bytes32 ack ) internal pure returns (bytes32) { return COMMITMENT_MAGIC | ( ack & 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ); } } /** * @dev IBCPacket is a contract that implements [ICS-4](https://github.com/cosmos/ibc/tree/main/spec/core/ics-004-channel-and-packet-semantics). */ abstract contract IBCPacketImpl is IBCStore, IIBCPacket { function batchSend( IBCMsgs.MsgBatchSend calldata msg_ ) external override { uint256 l = msg_.packets.length; // No reason to batch less than 2 packets as they are already individually committed. if (l < 2) { revert IBCErrors.ErrNotEnoughPackets(); } for (uint256 i = 0; i < l; i++) { IBCPacket calldata packet = msg_.packets[i]; // If the channel mismatch, the commitment will be zero bytes32 commitment = commitments[IBCCommitment .batchPacketsCommitmentKey( msg_.sourceChannelId, IBCPacketLib.commitPacket(packet) )]; // Every packet must have been previously sent to be batched if (commitment != IBCPacketLib.COMMITMENT_MAGIC) { revert IBCErrors.ErrPacketCommitmentNotFound(); } } commitments[IBCCommitment.batchPacketsCommitmentKey( msg_.sourceChannelId, IBCPacketLib.commitPackets(msg_.packets) )] = IBCPacketLib.COMMITMENT_MAGIC; } function batchAcks( IBCMsgs.MsgBatchAcks calldata msg_ ) external override { uint256 l = msg_.packets.length; // No reason to batch less than 2 packets as they are already individually committed. if (l < 2) { revert IBCErrors.ErrNotEnoughPackets(); } for (uint256 i = 0; i < l; i++) { IBCPacket calldata packet = msg_.packets[i]; bytes calldata ack = msg_.acks[i]; // If the channel mismatch, the commitment will be zero. bytes32 commitment = commitments[IBCCommitment .batchReceiptsCommitmentKey( msg_.sourceChannelId, IBCPacketLib.commitPacket(packet) )]; // Can't batch an empty ack. if ( commitment == IBCPacketLib.COMMITMENT_NULL || commitment == IBCPacketLib.COMMITMENT_MAGIC ) { revert IBCErrors.ErrAcknowledgementIsEmpty(); } // Of course the ack must match. if (commitment != IBCPacketLib.commitAck(ack)) { revert IBCErrors.ErrCommittedAckNotPresent(); } } commitments[IBCCommitment.batchReceiptsCommitmentKey( msg_.sourceChannelId, IBCPacketLib.commitPackets(msg_.packets) )] = IBCPacketLib.commitAcks(msg_.acks); } function sendPacket( uint32 sourceChannel, uint64 timeoutHeight, uint64 timeoutTimestamp, bytes calldata data ) external override returns (IBCPacket memory) { if (timeoutTimestamp == 0 && timeoutHeight == 0) { revert IBCErrors.ErrTimeoutMustBeSet(); } if (!authenticateChannelOwner(sourceChannel)) { revert IBCErrors.ErrUnauthorized(); } IBCChannel storage channel = ensureChannelState(sourceChannel); IBCPacket memory packet = IBCPacket({ sourceChannelId: sourceChannel, destinationChannelId: channel.counterpartyChannelId, data: data, timeoutHeight: timeoutHeight, timeoutTimestamp: timeoutTimestamp }); bytes32 commitmentKey = IBCCommitment.batchPacketsCommitmentKey( sourceChannel, IBCPacketLib.commitPacketMemory(packet) ); if (commitments[commitmentKey] != IBCPacketLib.COMMITMENT_NULL) { revert IBCErrors.ErrPacketAlreadyExist(); } commitments[commitmentKey] = IBCPacketLib.COMMITMENT_MAGIC; emit IBCPacketLib.PacketSend(packet); return packet; } function setPacketReceive( bytes32 commitmentKey ) internal returns (bool) { bool alreadyReceived = commitments[commitmentKey] != IBCPacketLib.COMMITMENT_NULL; if (!alreadyReceived) { commitments[commitmentKey] = IBCPacketLib.COMMITMENT_MAGIC; } return alreadyReceived; } function processReceive( IBCPacket[] calldata packets, address maker, bytes[] calldata makerMsgs, uint64 proofHeight, bytes calldata proof, bool intent ) internal { uint256 l = packets.length; if (l == 0) { revert IBCErrors.ErrNotEnoughPackets(); } uint32 sourceChannelId = packets[0].sourceChannelId; uint32 destinationChannelId = packets[0].destinationChannelId; IBCChannel storage channel = ensureChannelState(destinationChannelId); uint32 clientId = ensureConnectionState(channel.connectionId); if (!intent) { bytes32 proofCommitmentKey; if (l == 1) { proofCommitmentKey = IBCCommitment.batchPacketsCommitmentKey( sourceChannelId, IBCPacketLib.commitPacket(packets[0]) ); } else { proofCommitmentKey = IBCCommitment.batchPacketsCommitmentKey( sourceChannelId, IBCPacketLib.commitPackets(packets) ); } if ( !verifyCommitment( clientId, proofHeight, proof, proofCommitmentKey, IBCPacketLib.COMMITMENT_MAGIC ) ) { revert IBCErrors.ErrInvalidProof(); } } IIBCModule module = lookupModuleByChannel(destinationChannelId); for (uint256 i = 0; i < l; i++) { IBCPacket calldata packet = packets[i]; // Check packet height timeout if ( packet.timeoutHeight > 0 && (block.number >= packet.timeoutHeight) ) { revert IBCErrors.ErrHeightTimeout(); } // Check packet timestamp timeout // For some reason cosmos is using nanos, we try to follow their convention to avoid friction uint64 currentTimestamp = uint64(block.timestamp * 1e9); if ( packet.timeoutTimestamp != 0 && (currentTimestamp >= packet.timeoutTimestamp) ) { revert IBCErrors.ErrTimestampTimeout(); } bytes32 commitmentKey = IBCCommitment.batchReceiptsCommitmentKey( destinationChannelId, IBCPacketLib.commitPacket(packet) ); if (!setPacketReceive(commitmentKey)) { bytes memory acknowledgement; bytes calldata makerMsg = makerMsgs[i]; if (intent) { acknowledgement = module.onRecvIntentPacket(packet, maker, makerMsg); emit IBCPacketLib.IntentPacketRecv(packet, maker, makerMsg); } else { acknowledgement = module.onRecvPacket(packet, maker, makerMsg); emit IBCPacketLib.PacketRecv(packet, maker, makerMsg); } if (acknowledgement.length > 0) { _writeAcknowledgement(commitmentKey, acknowledgement); emit IBCPacketLib.WriteAck(packet, acknowledgement); } } } } function recvPacket( IBCMsgs.MsgPacketRecv calldata msg_ ) external { processReceive( msg_.packets, msg_.relayer, msg_.relayerMsgs, msg_.proofHeight, msg_.proof, false ); } function recvIntentPacket( IBCMsgs.MsgIntentPacketRecv calldata msg_ ) external override { processReceive( msg_.packets, msg_.marketMaker, msg_.marketMakerMsgs, 0, msg_.emptyProof, true ); } function _writeAcknowledgement( bytes32 commitmentKey, bytes memory acknowledgement ) internal { bytes32 commitment = commitments[commitmentKey]; if (commitment == IBCPacketLib.COMMITMENT_NULL) { revert IBCErrors.ErrPacketNotReceived(); } if (commitment != IBCPacketLib.COMMITMENT_MAGIC) { revert IBCErrors.ErrAcknowledgementAlreadyExists(); } commitments[commitmentKey] = IBCPacketLib.commitAckMemory(acknowledgement); } function writeAcknowledgement( IBCPacket calldata packet, bytes memory acknowledgement ) external override { if (acknowledgement.length == 0) { revert IBCErrors.ErrAcknowledgementIsEmpty(); } if (!authenticateChannelOwner(packet.destinationChannelId)) { revert IBCErrors.ErrUnauthorized(); } ensureChannelState(packet.destinationChannelId); bytes32 commitmentKey = IBCCommitment.batchReceiptsCommitmentKey( packet.destinationChannelId, IBCPacketLib.commitPacket(packet) ); _writeAcknowledgement(commitmentKey, acknowledgement); emit IBCPacketLib.WriteAck(packet, acknowledgement); } function acknowledgePacket( IBCMsgs.MsgPacketAcknowledgement calldata msg_ ) external override { uint256 l = msg_.packets.length; if (l == 0) { revert IBCErrors.ErrNotEnoughPackets(); } uint32 sourceChannelId = msg_.packets[0].sourceChannelId; uint32 destinationChannelId = msg_.packets[0].destinationChannelId; IBCChannel storage channel = ensureChannelState(sourceChannelId); uint32 clientId = ensureConnectionState(channel.connectionId); bytes32 commitmentKey; bytes32 commitmentValue; if (l == 1) { commitmentKey = IBCCommitment.batchReceiptsCommitmentKey( destinationChannelId, IBCPacketLib.commitPacket(msg_.packets[0]) ); commitmentValue = IBCPacketLib.commitAck(msg_.acknowledgements[0]); } else { commitmentKey = IBCCommitment.batchReceiptsCommitmentKey( destinationChannelId, IBCPacketLib.commitPackets(msg_.packets) ); commitmentValue = IBCPacketLib.commitAcks(msg_.acknowledgements); } if ( !verifyCommitment( clientId, msg_.proofHeight, msg_.proof, commitmentKey, commitmentValue ) ) { revert IBCErrors.ErrInvalidProof(); } IIBCModule module = lookupModuleByChannel(sourceChannelId); for (uint256 i = 0; i < l; i++) { IBCPacket calldata packet = msg_.packets[i]; deletePacketCommitment(sourceChannelId, packet); bytes calldata acknowledgement = msg_.acknowledgements[i]; module.onAcknowledgementPacket( packet, acknowledgement, msg_.relayer ); emit IBCPacketLib.PacketAck(packet, acknowledgement, msg_.relayer); } } function timeoutPacket( IBCMsgs.MsgPacketTimeout calldata msg_ ) external override { IBCPacket calldata packet = msg_.packet; uint32 sourceChannelId = packet.sourceChannelId; uint32 destinationChannelId = packet.destinationChannelId; IBCChannel storage channel = ensureChannelState(sourceChannelId); uint32 clientId = ensureConnectionState(channel.connectionId); ILightClient client = getClientInternal(clientId); uint64 proofTimestamp = client.getTimestampAtHeight(clientId, msg_.proofHeight); if (proofTimestamp == 0) { revert IBCErrors.ErrLatestTimestampNotFound(); } bytes32 commitmentKey = IBCCommitment.batchReceiptsCommitmentKey( destinationChannelId, IBCPacketLib.commitPacket(packet) ); if ( !verifyAbsentCommitment( clientId, msg_.proofHeight, msg_.proof, commitmentKey ) ) { revert IBCErrors.ErrInvalidProof(); } IIBCModule module = lookupModuleByChannel(sourceChannelId); deletePacketCommitment(sourceChannelId, packet); if (packet.timeoutTimestamp == 0 && packet.timeoutHeight == 0) { revert IBCErrors.ErrTimeoutMustBeSet(); } if ( packet.timeoutTimestamp > 0 && packet.timeoutTimestamp > proofTimestamp ) { revert IBCErrors.ErrTimeoutTimestampNotReached(); } if (packet.timeoutHeight > 0 && packet.timeoutHeight > msg_.proofHeight) { revert IBCErrors.ErrTimeoutHeightNotReached(); } module.onTimeoutPacket(packet, msg_.relayer); emit IBCPacketLib.PacketTimeout(packet, msg_.relayer); } function verifyCommitment( uint32 clientId, uint64 height, bytes calldata proof, bytes32 path, bytes32 commitment ) internal virtual returns (bool) { return getClientInternal(clientId).verifyMembership( clientId, height, proof, abi.encodePacked(path), abi.encodePacked(commitment) ); } function verifyAbsentCommitment( uint32 clientId, uint64 height, bytes calldata proof, bytes32 path ) internal virtual returns (bool) { return getClientInternal(clientId).verifyNonMembership( clientId, height, proof, abi.encodePacked(path) ); } function deletePacketCommitment( uint32 sourceChannelId, IBCPacket calldata packet ) internal { bytes32 commitmentKey = IBCCommitment.batchPacketsCommitmentKey( sourceChannelId, IBCPacketLib.commitPacket(packet) ); bytes32 commitment = commitments[commitmentKey]; if (commitment != IBCPacketLib.COMMITMENT_MAGIC) { revert IBCErrors.ErrPacketCommitmentNotFound(); } delete commitments[commitmentKey]; } }
// 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; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.20; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeacon { /** * @dev Must return an address that can be used as a delegate call target. * * {UpgradeableBeacon} will check that this address is a contract. */ function implementation() external view returns (address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol) pragma solidity ^0.8.20; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev The ETH balance of the account is not enough to perform the operation. */ error AddressInsufficientBalance(address account); /** * @dev There's no code at `target` (it is not a contract). */ error AddressEmptyCode(address target); /** * @dev A call to an address target failed. The target may have reverted. */ error FailedInnerCall(); /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { if (address(this).balance < amount) { revert AddressInsufficientBalance(address(this)); } (bool success, ) = recipient.call{value: amount}(""); if (!success) { revert FailedInnerCall(); } } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason or custom error, it is bubbled * up by this function (like regular Solidity function calls). However, if * the call reverted with no returned reason, this function reverts with a * {FailedInnerCall} error. * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { if (address(this).balance < value) { revert AddressInsufficientBalance(address(this)); } (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an * unsuccessful call. */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata ) internal view returns (bytes memory) { if (!success) { _revert(returndata); } else { // only check if target is a contract if the call was successful and the return data is empty // otherwise we already know that it was a contract if (returndata.length == 0 && target.code.length == 0) { revert AddressEmptyCode(target); } return returndata; } } /** * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the * revert reason or with a default {FailedInnerCall} error. */ function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) { if (!success) { _revert(returndata); } else { return returndata; } } /** * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}. */ function _revert(bytes memory returndata) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert FailedInnerCall(); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol) // This file was procedurally generated from scripts/generate/templates/StorageSlot.js. pragma solidity ^0.8.20; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ```solidity * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(newImplementation.code.length > 0); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } struct StringSlot { string value; } struct BytesSlot { bytes value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` with member `value` located at `slot`. */ function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` representation of the string storage pointer `store`. */ function getStringSlot(string storage store) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } /** * @dev Returns an `BytesSlot` with member `value` located at `slot`. */ function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`. */ function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } }
pragma solidity ^0.8.27; enum IBCConnectionState { Unspecified, Init, TryOpen, Open } struct IBCConnection { IBCConnectionState state; uint32 clientId; uint32 counterpartyClientId; uint32 counterpartyConnectionId; } enum IBCChannelState { Unspecified, Init, TryOpen, Open, Closed } struct IBCChannel { IBCChannelState state; uint32 connectionId; uint32 counterpartyChannelId; bytes counterpartyPortId; string version; } struct IBCPacket { uint32 sourceChannelId; uint32 destinationChannelId; bytes data; uint64 timeoutHeight; uint64 timeoutTimestamp; } library IBCErrors { error ErrClientTypeAlreadyExists(); error ErrClientTypeNotFound(); error ErrInvalidProof(); error ErrInvalidConnectionState(); error ErrInvalidChannelState(); error ErrUnauthorized(); error ErrLatestTimestampNotFound(); error ErrTimeoutMustBeSet(); error ErrHeightTimeout(); error ErrTimestampTimeout(); error ErrAcknowledgementIsEmpty(); error ErrPacketNotReceived(); error ErrAcknowledgementAlreadyExists(); error ErrPacketCommitmentNotFound(); error ErrTimeoutHeightNotReached(); error ErrTimeoutTimestampNotReached(); error ErrNotEnoughPackets(); error ErrCommittedAckNotPresent(); error ErrClientNotFound(); error ErrModuleNotFound(); error ErrPacketAlreadyExist(); }
pragma solidity ^0.8.27; import "../Types.sol"; struct ConsensusStateUpdate { bytes32 clientStateCommitment; bytes32 consensusStateCommitment; uint64 height; } /** * @dev This defines an interface for Light Client contract can be integrated with ibc-solidity. * You can register the Light Client contract that implements this through `registerClient` on IBCHandler. */ interface ILightClient { /** * @dev createClient creates a new client with the given state. * If succeeded, it returns a commitment for the initial state. */ function createClient( uint32 clientId, bytes calldata clientStateBytes, bytes calldata consensusStateBytes ) external returns ( ConsensusStateUpdate memory update, string memory counterpartyChainId ); /** * @dev getTimestampAtHeight returns the timestamp of the consensus state at the given height. */ function getTimestampAtHeight( uint32 clientId, uint64 height ) external view returns (uint64); /** * @dev getLatestHeight returns the latest height of the client state corresponding to `clientId`. */ function getLatestHeight( uint32 clientId ) external view returns (uint64 height); /** * @dev updateClient updates the client corresponding to `clientId`. * If succeeded, it returns a commitment for the updated state. * If there are no updates for consensus state, this function should returns an empty array as `updates`. * * NOTE: updateClient is intended to perform the followings: * 1. verify a given client message(e.g. header) * 2. check misbehaviour such like duplicate block height * 3. if misbehaviour is found, update state accordingly and return * 4. update state(s) with the client message * 5. persist the state(s) on the host */ function updateClient( uint32 clientId, bytes calldata clientMessageBytes ) external returns (ConsensusStateUpdate memory update); /** * @dev misbehaviour is used for submitting a misbehaviour to `clientId`. * If succeeded, the client should freeze itself to prevent getting further updates. */ function misbehaviour( uint32 clientId, bytes calldata clientMessageBytes ) external; /** * @dev verifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the specified height. * The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). */ function verifyMembership( uint32 clientId, uint64 height, bytes calldata proof, bytes calldata path, bytes calldata value ) external returns (bool); /** * @dev verifyNonMembership is a generic proof verification method which verifies the absence of a given CommitmentPath at a specified height. * The caller is expected to construct the full CommitmentPath from a CommitmentPrefix and a standardized path (as defined in ICS 24). */ function verifyNonMembership( uint32 clientId, uint64 height, bytes calldata proof, bytes calldata path ) external returns (bool); /** * @dev getClientState returns the clientState corresponding to `clientId`. */ function getClientState( uint32 clientId ) external view returns (bytes memory); /** * @dev getConsensusState returns the consensusState corresponding to `clientId` and `height`. */ function getConsensusState( uint32 clientId, uint64 height ) external view returns (bytes memory); /** * @dev isFrozen returns whether the `clientId` is frozen or not. */ function isFrozen( uint32 clientId ) external view returns (bool); }
pragma solidity ^0.8.27; import "../Types.sol"; /** * @dev IBCMsgs provides datagram types in [ICS-26](https://github.com/cosmos/ibc/tree/main/spec/core/ics-026-routing-module#datagram-handlers-write) */ library IBCMsgs { struct MsgCreateClient { string clientType; bytes clientStateBytes; bytes consensusStateBytes; address relayer; } struct MsgUpdateClient { uint32 clientId; bytes clientMessage; address relayer; } struct MsgConnectionOpenInit { uint32 clientId; uint32 counterpartyClientId; address relayer; } struct MsgConnectionOpenTry { uint32 counterpartyClientId; uint32 counterpartyConnectionId; uint32 clientId; bytes proofInit; uint64 proofHeight; address relayer; } struct MsgConnectionOpenAck { uint32 connectionId; uint32 counterpartyConnectionId; bytes proofTry; uint64 proofHeight; address relayer; } struct MsgConnectionOpenConfirm { uint32 connectionId; bytes proofAck; uint64 proofHeight; address relayer; } struct MsgChannelOpenInit { address portId; bytes counterpartyPortId; uint32 connectionId; string version; address relayer; } struct MsgChannelOpenTry { address portId; IBCChannel channel; string counterpartyVersion; bytes proofInit; uint64 proofHeight; address relayer; } struct MsgChannelOpenAck { uint32 channelId; string counterpartyVersion; uint32 counterpartyChannelId; bytes proofTry; uint64 proofHeight; address relayer; } struct MsgChannelOpenConfirm { uint32 channelId; bytes proofAck; uint64 proofHeight; address relayer; } struct MsgChannelCloseInit { uint32 channelId; address relayer; } struct MsgChannelCloseConfirm { uint32 channelId; bytes proofInit; uint64 proofHeight; address relayer; } struct MsgPacketRecv { IBCPacket[] packets; bytes[] relayerMsgs; address relayer; bytes proof; uint64 proofHeight; } struct MsgPacketAcknowledgement { IBCPacket[] packets; bytes[] acknowledgements; bytes proof; uint64 proofHeight; address relayer; } struct MsgPacketTimeout { IBCPacket packet; bytes proof; uint64 proofHeight; address relayer; } struct MsgIntentPacketRecv { IBCPacket[] packets; bytes[] marketMakerMsgs; address marketMaker; bytes emptyProof; } struct MsgBatchSend { uint32 sourceChannelId; IBCPacket[] packets; } struct MsgBatchAcks { uint32 sourceChannelId; IBCPacket[] packets; bytes[] acks; } struct MsgMisbehaviour { uint32 clientId; bytes clientMessage; } }
pragma solidity ^0.8.27; library IBCCommitment { uint256 public constant CLIENT_STATE = 0x00; uint256 public constant CONSENSUS_STATE = 0x01; uint256 public constant CONNECTIONS = 0x02; uint256 public constant CHANNELS = 0x03; uint256 public constant PACKETS = 0x04; uint256 public constant PACKET_ACKS = 0x05; function clientStatePath( uint32 clientId ) internal pure returns (bytes memory) { return abi.encode(CLIENT_STATE, clientId); } function consensusStatePath( uint32 clientId, uint64 height ) internal pure returns (bytes memory) { return abi.encode(CONSENSUS_STATE, clientId, height); } function connectionPath( uint32 connectionId ) internal pure returns (bytes memory) { return abi.encode(CONNECTIONS, connectionId); } function channelPath( uint32 channelId ) internal pure returns (bytes memory) { return abi.encode(CHANNELS, channelId); } function batchPacketsCommitmentPath( uint32 channelId, bytes32 batchHash ) internal pure returns (bytes memory) { return abi.encode(PACKETS, channelId, batchHash); } function batchReceiptsCommitmentPath( uint32 channelId, bytes32 batchHash ) internal pure returns (bytes memory) { return abi.encode(PACKET_ACKS, channelId, batchHash); } // Key generators for Commitment mapping function clientStateCommitmentKey( uint32 clientId ) internal pure returns (bytes32) { return keccak256(clientStatePath(clientId)); } function consensusStateCommitmentKey( uint32 clientId, uint64 height ) internal pure returns (bytes32) { return keccak256(consensusStatePath(clientId, height)); } function connectionCommitmentKey( uint32 connectionId ) internal pure returns (bytes32) { return keccak256(connectionPath(connectionId)); } function channelCommitmentKey( uint32 channelId ) internal pure returns (bytes32) { return keccak256(channelPath(channelId)); } function batchPacketsCommitmentKey( uint32 channelId, bytes32 batchHash ) internal pure returns (bytes32) { return keccak256(batchPacketsCommitmentPath(channelId, batchHash)); } function batchReceiptsCommitmentKey( uint32 channelId, bytes32 batchHash ) internal pure returns (bytes32) { return keccak256(batchReceiptsCommitmentPath(channelId, batchHash)); } }
pragma solidity ^0.8.27; import "./ILightClient.sol"; import "../25-handler/IBCMsgs.sol"; interface IIBCClient { /** * @dev registerClient registers a new client type into the client registry */ function registerClient( string calldata clientType, ILightClient client ) external; /** * @dev createClient creates a new client state and populates it with a given consensus state */ function createClient( IBCMsgs.MsgCreateClient calldata msg_ ) external returns (uint32 clientId); /** * @dev updateClient updates the consensus state and the state root from a provided header */ function updateClient( IBCMsgs.MsgUpdateClient calldata msg_ ) external; /** * @dev misbehaviour submits a misbehaviour to the client for it to take action if it is correct */ function misbehaviour( IBCMsgs.MsgMisbehaviour calldata msg_ ) external; }
pragma solidity ^0.8.27; import "../25-handler/IBCMsgs.sol"; interface IIBCConnection { /* Handshake functions */ /** * @dev connectionOpenInit initialises a connection attempt on chain A. The generated connection identifier * is returned. */ function connectionOpenInit( IBCMsgs.MsgConnectionOpenInit calldata msg_ ) external returns (uint32); /** * @dev connectionOpenTry relays notice of a connection attempt on chain A to chain B (this * code is executed on chain B). */ function connectionOpenTry( IBCMsgs.MsgConnectionOpenTry calldata msg_ ) external returns (uint32); /** * @dev connectionOpenAck relays acceptance of a connection open attempt from chain B back * to chain A (this code is executed on chain A). */ function connectionOpenAck( IBCMsgs.MsgConnectionOpenAck calldata msg_ ) external; /** * @dev connectionOpenConfirm confirms opening of a connection on chain A to chain B, after * which the connection is open on both chains (this code is executed on chain B). */ function connectionOpenConfirm( IBCMsgs.MsgConnectionOpenConfirm calldata msg_ ) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import {LibBytes} from "./LibBytes.sol"; /// @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) /// /// @dev Note: /// For performance and bytecode compactness, most of the string operations are restricted to /// byte strings (7-bit ASCII), except where otherwise specified. /// Usage of byte string operations on charsets with runes spanning two or more bytes /// can lead to undefined behavior. library LibString { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STRUCTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Goated string storage struct that totally MOGs, no cap, fr. /// Uses less gas and bytecode than Solidity's native string storage. It's meta af. /// Packs length with the first 31 bytes if <255 bytes, so it’s mad tight. struct StringStorage { bytes32 _spacer; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The length of the output is too small to contain all the hex digits. error HexLengthInsufficient(); /// @dev The length of the string is more than 32 bytes. error TooBigForSmallString(); /// @dev The input string must be a 7-bit ASCII. error StringNot7BitASCII(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The constant returned when the `search` is not found in the string. uint256 internal constant NOT_FOUND = type(uint256).max; /// @dev Lookup for '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'. uint128 internal constant ALPHANUMERIC_7_BIT_ASCII = 0x7fffffe07fffffe03ff000000000000; /// @dev Lookup for 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'. uint128 internal constant LETTERS_7_BIT_ASCII = 0x7fffffe07fffffe0000000000000000; /// @dev Lookup for 'abcdefghijklmnopqrstuvwxyz'. uint128 internal constant LOWERCASE_7_BIT_ASCII = 0x7fffffe000000000000000000000000; /// @dev Lookup for 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. uint128 internal constant UPPERCASE_7_BIT_ASCII = 0x7fffffe0000000000000000; /// @dev Lookup for '0123456789'. uint128 internal constant DIGITS_7_BIT_ASCII = 0x3ff000000000000; /// @dev Lookup for '0123456789abcdefABCDEF'. uint128 internal constant HEXDIGITS_7_BIT_ASCII = 0x7e0000007e03ff000000000000; /// @dev Lookup for '01234567'. uint128 internal constant OCTDIGITS_7_BIT_ASCII = 0xff000000000000; /// @dev Lookup for '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'. uint128 internal constant PRINTABLE_7_BIT_ASCII = 0x7fffffffffffffffffffffff00003e00; /// @dev Lookup for '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'. uint128 internal constant PUNCTUATION_7_BIT_ASCII = 0x78000001f8000001fc00fffe00000000; /// @dev Lookup for ' \t\n\r\x0b\x0c'. uint128 internal constant WHITESPACE_7_BIT_ASCII = 0x100003e00; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STRING STORAGE OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Sets the value of the string storage `$` to `s`. function set(StringStorage storage $, string memory s) internal { LibBytes.set(bytesStorage($), bytes(s)); } /// @dev Sets the value of the string storage `$` to `s`. function setCalldata(StringStorage storage $, string calldata s) internal { LibBytes.setCalldata(bytesStorage($), bytes(s)); } /// @dev Sets the value of the string storage `$` to the empty string. function clear(StringStorage storage $) internal { delete $._spacer; } /// @dev Returns whether the value stored is `$` is the empty string "". function isEmpty(StringStorage storage $) internal view returns (bool) { return uint256($._spacer) & 0xff == uint256(0); } /// @dev Returns the length of the value stored in `$`. function length(StringStorage storage $) internal view returns (uint256) { return LibBytes.length(bytesStorage($)); } /// @dev Returns the value stored in `$`. function get(StringStorage storage $) internal view returns (string memory) { return string(LibBytes.get(bytesStorage($))); } /// @dev Helper to cast `$` to a `BytesStorage`. function bytesStorage(StringStorage storage $) internal pure returns (LibBytes.BytesStorage storage casted) { /// @solidity memory-safe-assembly assembly { casted.slot := $.slot } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* DECIMAL OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the base 10 decimal representation of `value`. function toString(uint256 value) internal pure returns (string memory result) { /// @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. result := add(mload(0x40), 0x80) mstore(0x40, add(result, 0x20)) // Allocate memory. mstore(result, 0) // Zeroize the slot after the string. let end := result // Cache the end of the memory to calculate the length later. 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 {} { result := add(result, w) // `sub(result, 1)`. // Store the character to the pointer. // The ASCII index of the '0' character is 48. mstore8(result, add(48, mod(temp, 10))) temp := div(temp, 10) // Keep dividing `temp` until zero. if iszero(temp) { break } } let n := sub(end, result) result := sub(result, 0x20) // Move the pointer 32 bytes back to make room for the length. mstore(result, n) // Store the length. } } /// @dev Returns the base 10 decimal representation of `value`. function toString(int256 value) internal pure returns (string memory result) { if (value >= 0) return toString(uint256(value)); unchecked { result = toString(~uint256(value) + 1); } /// @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 n := mload(result) // Load the string length. mstore(result, 0x2d) // Store the '-' character. result := sub(result, 1) // Move back the string pointer by a byte. mstore(result, add(n, 1)) // Update the string length. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HEXADECIMAL OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the hexadecimal representation of `value`, /// left-padded to an input length of `byteCount` bytes. /// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte, /// giving a total length of `byteCount * 2 + 2` bytes. /// Reverts if `byteCount` is too small for the output to contain all the digits. function toHexString(uint256 value, uint256 byteCount) internal pure returns (string memory result) { result = toHexStringNoPrefix(value, byteCount); /// @solidity memory-safe-assembly assembly { let n := add(mload(result), 2) // Compute the length. mstore(result, 0x3078) // Store the "0x" prefix. result := sub(result, 2) // Move the pointer. mstore(result, n) // Store the length. } } /// @dev Returns the hexadecimal representation of `value`, /// left-padded to an input length of `byteCount` bytes. /// The output is not prefixed with "0x" and is encoded using 2 hexadecimal digits per byte, /// giving a total length of `byteCount * 2` bytes. /// Reverts if `byteCount` is too small for the output to contain all the digits. function toHexStringNoPrefix(uint256 value, uint256 byteCount) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { // We need 0x20 bytes for the trailing zeros padding, `byteCount * 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. result := add(mload(0x40), and(add(shl(1, byteCount), 0x42), not(0x1f))) mstore(0x40, add(result, 0x20)) // Allocate memory. mstore(result, 0) // Zeroize the slot after the string. let end := result // Cache the end to calculate the length later. // Store "0123456789abcdef" in scratch space. mstore(0x0f, 0x30313233343536373839616263646566) let start := sub(result, add(byteCount, byteCount)) 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 {} { result := add(result, w) // `sub(result, 2)`. mstore8(add(result, 1), mload(and(temp, 15))) mstore8(result, mload(and(shr(4, temp), 15))) temp := shr(8, temp) if iszero(xor(result, start)) { break } } if temp { mstore(0x00, 0x2194895a) // `HexLengthInsufficient()`. revert(0x1c, 0x04) } let n := sub(end, result) result := sub(result, 0x20) mstore(result, n) // Store the length. } } /// @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 result) { result = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let n := add(mload(result), 2) // Compute the length. mstore(result, 0x3078) // Store the "0x" prefix. result := sub(result, 2) // Move the pointer. mstore(result, n) // Store 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 result) { result = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let o := eq(byte(0, mload(add(result, 0x20))), 0x30) // Whether leading zero is present. let n := add(mload(result), 2) // Compute the length. mstore(add(result, o), 0x3078) // Store the "0x" prefix, accounting for leading zero. result := sub(add(result, o), 2) // Move the pointer, accounting for leading zero. mstore(result, sub(n, o)) // Store 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 result) { result = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let o := eq(byte(0, mload(add(result, 0x20))), 0x30) // Whether leading zero is present. let n := mload(result) // Get the length. result := add(result, o) // Move the pointer, accounting for leading zero. mstore(result, sub(n, o)) // Store 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 result) { /// @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. result := add(mload(0x40), 0x80) mstore(0x40, add(result, 0x20)) // Allocate memory. mstore(result, 0) // Zeroize the slot after the string. let end := result // Cache the end to calculate the length later. mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup. 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 {} { result := add(result, w) // `sub(result, 2)`. mstore8(add(result, 1), mload(and(temp, 15))) mstore8(result, mload(and(shr(4, temp), 15))) temp := shr(8, temp) if iszero(temp) { break } } let n := sub(end, result) result := sub(result, 0x20) mstore(result, n) // Store the length. } } /// @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 result) { result = toHexString(value); /// @solidity memory-safe-assembly assembly { let mask := shl(6, div(not(0), 255)) // `0b010000000100000000 ...` let o := add(result, 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 result) { result = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let n := add(mload(result), 2) // Compute the length. mstore(result, 0x3078) // Store the "0x" prefix. result := sub(result, 2) // Move the pointer. mstore(result, n) // Store 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 result) { /// @solidity memory-safe-assembly assembly { result := mload(0x40) // Allocate 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(result, 0x80)) mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup. result := add(result, 2) mstore(result, 40) // Store the length. let o := add(result, 0x20) mstore(add(o, 40), 0) // Zeroize the slot after the string. 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 result) { result = toHexStringNoPrefix(raw); /// @solidity memory-safe-assembly assembly { let n := add(mload(result), 2) // Compute the length. mstore(result, 0x3078) // Store the "0x" prefix. result := sub(result, 2) // Move the pointer. mstore(result, n) // Store 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 result) { /// @solidity memory-safe-assembly assembly { let n := mload(raw) result := add(mload(0x40), 2) // Skip 2 bytes for the optional prefix. mstore(result, add(n, n)) // Store the length of the output. mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup. let o := add(result, 0x20) let end := add(raw, n) 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 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 { result := 1 let mask := shl(7, div(not(0), 255)) 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) } } } /// @dev Returns if this string is a 7-bit ASCII string, /// AND all characters are in the `allowed` lookup. /// Note: If `s` is empty, returns true regardless of `allowed`. function is7BitASCII(string memory s, uint128 allowed) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { result := 1 if mload(s) { let allowed_ := shr(128, shl(128, allowed)) let o := add(s, 0x20) for { let end := add(o, mload(s)) } 1 {} { result := and(result, shr(byte(0, mload(o)), allowed_)) o := add(o, 1) if iszero(and(result, lt(o, end))) { break } } } } } /// @dev Converts the bytes in the 7-bit ASCII string `s` to /// an allowed lookup for use in `is7BitASCII(s, allowed)`. /// To save runtime gas, you can cache the result in an immutable variable. function to7BitASCIIAllowedLookup(string memory s) internal pure returns (uint128 result) { /// @solidity memory-safe-assembly assembly { if mload(s) { let o := add(s, 0x20) for { let end := add(o, mload(s)) } 1 {} { result := or(result, shl(byte(0, mload(o)), 1)) o := add(o, 1) if iszero(lt(o, end)) { break } } if shr(128, result) { mstore(0x00, 0xc9807e0d) // `StringNot7BitASCII()`. revert(0x1c, 0x04) } } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* BYTE STRING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // For performance and bytecode compactness, byte string operations are restricted // to 7-bit ASCII strings. All offsets are byte offsets, not UTF character offsets. // Usage of byte string operations on charsets with runes spanning two or more bytes // can lead to undefined behavior. /// @dev Returns `subject` all occurrences of `needle` replaced with `replacement`. function replace(string memory subject, string memory needle, string memory replacement) internal pure returns (string memory) { return string(LibBytes.replace(bytes(subject), bytes(needle), bytes(replacement))); } /// @dev Returns the byte index of the first location of `needle` in `subject`, /// needleing from left to right, starting from `from`. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found. function indexOf(string memory subject, string memory needle, uint256 from) internal pure returns (uint256) { return LibBytes.indexOf(bytes(subject), bytes(needle), from); } /// @dev Returns the byte index of the first location of `needle` in `subject`, /// needleing from left to right. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found. function indexOf(string memory subject, string memory needle) internal pure returns (uint256) { return LibBytes.indexOf(bytes(subject), bytes(needle), 0); } /// @dev Returns the byte index of the first location of `needle` in `subject`, /// needleing from right to left, starting from `from`. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found. function lastIndexOf(string memory subject, string memory needle, uint256 from) internal pure returns (uint256) { return LibBytes.lastIndexOf(bytes(subject), bytes(needle), from); } /// @dev Returns the byte index of the first location of `needle` in `subject`, /// needleing from right to left. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found. function lastIndexOf(string memory subject, string memory needle) internal pure returns (uint256) { return LibBytes.lastIndexOf(bytes(subject), bytes(needle), type(uint256).max); } /// @dev Returns true if `needle` is found in `subject`, false otherwise. function contains(string memory subject, string memory needle) internal pure returns (bool) { return LibBytes.contains(bytes(subject), bytes(needle)); } /// @dev Returns whether `subject` starts with `needle`. function startsWith(string memory subject, string memory needle) internal pure returns (bool) { return LibBytes.startsWith(bytes(subject), bytes(needle)); } /// @dev Returns whether `subject` ends with `needle`. function endsWith(string memory subject, string memory needle) internal pure returns (bool) { return LibBytes.endsWith(bytes(subject), bytes(needle)); } /// @dev Returns `subject` repeated `times`. function repeat(string memory subject, uint256 times) internal pure returns (string memory) { return string(LibBytes.repeat(bytes(subject), times)); } /// @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) { return string(LibBytes.slice(bytes(subject), start, end)); } /// @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) { return string(LibBytes.slice(bytes(subject), start, type(uint256).max)); } /// @dev Returns all the indices of `needle` in `subject`. /// The indices are byte offsets. function indicesOf(string memory subject, string memory needle) internal pure returns (uint256[] memory) { return LibBytes.indicesOf(bytes(subject), bytes(needle)); } /// @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) { bytes[] memory a = LibBytes.split(bytes(subject), bytes(delimiter)); /// @solidity memory-safe-assembly assembly { result := a } } /// @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) { return string(LibBytes.concat(bytes(a), bytes(b))); } /// @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 n := mload(subject) if n { result := mload(0x40) let o := add(result, 0x20) let d := sub(subject, result) let flags := shl(add(70, shl(5, toUpper)), 0x3ffffff) for { let end := add(o, n) } 1 {} { let b := byte(0, mload(add(d, o))) mstore8(o, xor(and(shr(b, flags), 0x20), b)) o := add(o, 1) if eq(o, end) { break } } mstore(result, n) // Store the length. mstore(o, 0) // Zeroize the slot after the string. mstore(0x40, add(o, 0x20)) // Allocate memory. } } } /// @dev Returns a string from a small bytes32 string. /// `s` must be null-terminated, or behavior will be undefined. function fromSmallString(bytes32 s) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { result := mload(0x40) let n := 0 for {} byte(n, s) { n := add(n, 1) } {} // Scan for '\0'. mstore(result, n) // Store the length. let o := add(result, 0x20) mstore(o, s) // Store the bytes of the string. mstore(add(o, n), 0) // Zeroize the slot after the string. mstore(0x40, add(result, 0x40)) // Allocate memory. } } /// @dev Returns the small string, with all bytes after the first null byte zeroized. function normalizeSmallString(bytes32 s) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { for {} byte(result, s) { result := add(result, 1) } {} // Scan for '\0'. mstore(0x00, s) mstore(result, 0x00) result := mload(0x00) } } /// @dev Returns the string as a normalized null-terminated small string. function toSmallString(string memory s) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { result := mload(s) if iszero(lt(result, 33)) { mstore(0x00, 0xec92f9a3) // `TooBigForSmallString()`. revert(0x1c, 0x04) } result := shl(shl(3, sub(32, result)), mload(add(s, result))) } } /// @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 { result := mload(0x40) let end := add(s, mload(s)) let o := add(result, 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(o, c) o := add(o, 1) continue } let t := shr(248, mload(c)) mstore(o, mload(and(t, 0x1f))) o := add(o, shr(5, t)) } mstore(o, 0) // Zeroize the slot after the string. mstore(result, sub(o, add(result, 0x20))) // Store the length. mstore(0x40, add(o, 0x20)) // Allocate 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 { result := mload(0x40) let o := add(result, 0x20) if addDoubleQuotes { mstore8(o, 34) o := add(1, o) } // 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 { let end := add(s, mload(s)) } 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(o, c) o := add(o, 1) continue } mstore8(o, 0x5c) // "\\". mstore8(add(o, 1), c) o := add(o, 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(o, mload(0x19)) // "\\u00XX". o := add(o, 6) continue } mstore8(o, 0x5c) // "\\". mstore8(add(o, 1), mload(add(c, 8))) o := add(o, 2) } if addDoubleQuotes { mstore8(o, 34) o := add(1, o) } mstore(o, 0) // Zeroize the slot after the string. mstore(result, sub(o, add(result, 0x20))) // Store the length. mstore(0x40, add(o, 0x20)) // Allocate 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 Encodes `s` so that it can be safely used in a URI, /// just like `encodeURIComponent` in JavaScript. /// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent /// See: https://datatracker.ietf.org/doc/html/rfc2396 /// See: https://datatracker.ietf.org/doc/html/rfc3986 function encodeURIComponent(string memory s) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { result := mload(0x40) // Store "0123456789ABCDEF" in scratch space. // Uppercased to be consistent with JavaScript's implementation. mstore(0x0f, 0x30313233343536373839414243444546) let o := add(result, 0x20) for { let end := add(s, mload(s)) } iszero(eq(s, end)) {} { s := add(s, 1) let c := and(mload(s), 0xff) // If not in `[0-9A-Z-a-z-_.!~*'()]`. if iszero(and(1, shr(c, 0x47fffffe87fffffe03ff678200000000))) { mstore8(o, 0x25) // '%'. mstore8(add(o, 1), mload(and(shr(4, c), 15))) mstore8(add(o, 2), mload(and(c, 15))) o := add(o, 3) continue } mstore8(o, c) o := add(o, 1) } mstore(result, sub(o, add(result, 0x20))) // Store the length. mstore(o, 0) // Zeroize the slot after the string. mstore(0x40, add(o, 0x20)) // Allocate memory. } } /// @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`, where `b` is a null-terminated small string. 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 m := not(shl(7, div(not(iszero(b)), 255))) // `0x7f7f ...`. let x := not(or(m, or(b, add(m, and(b, m))))) let r := 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)))) // forgefmt: disable-next-item result := gt(eq(mload(a), add(iszero(x), xor(31, shr(3, r)))), xor(shr(add(8, r), b), shr(add(8, r), mload(add(a, 0x20))))) } } /// @dev Returns 0 if `a == b`, -1 if `a < b`, +1 if `a > b`. /// If `a` == b[:a.length]`, and `a.length < b.length`, returns -1. function cmp(string memory a, string memory b) internal pure returns (int256) { return LibBytes.cmp(bytes(a), bytes(b)); } /// @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 { result := mload(0x40) // Grab the free memory pointer. mstore(0x40, add(result, 0x40)) // Allocate 2 words (1 for the length, 1 for the bytes). mstore(result, 0) // Zeroize the length slot. mstore(add(result, 0x1f), packed) // Store the length and bytes. mstore(add(add(result, 0x20), mload(result)), 0) // Right pad with zeroes. } } /// @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 aLen := mload(a) // We don't need to zero right pad the strings, // since this is our own custom non-standard packing scheme. result := mul( or( // Load the length and the bytes of `a` and `b`. shl(shl(3, sub(0x1f, aLen)), mload(add(a, aLen))), mload(sub(add(b, 0x1e), aLen))), // `totalLen != 0 && totalLen < 31`. Abuses underflow. // Assumes that the lengths are valid and within the block gas limit. lt(sub(add(aLen, 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 { resultA := mload(0x40) // Grab the free memory pointer. 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 retUnpaddedSize := 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, retUnpaddedSize), 0) mstore(retStart, 0x20) // Store the return offset. // End the transaction, returning the string. return(retStart, and(not(0x1f), add(0x1f, retUnpaddedSize))) } } }
pragma solidity ^0.8.27; import "../25-handler/IBCMsgs.sol"; interface IIBCChannel { /** * @dev channelOpenInit is called by a module to initiate a channel opening handshake with a module on another chain. */ function channelOpenInit( IBCMsgs.MsgChannelOpenInit calldata msg_ ) external returns (uint32); /** * @dev channelOpenTry is called by a module to accept the first step of a channel opening handshake initiated by a module on another chain. */ function channelOpenTry( IBCMsgs.MsgChannelOpenTry calldata msg_ ) external returns (uint32); /** * @dev channelOpenAck is called by the handshake-originating module to acknowledge the acceptance of the initial request by the counterparty module on the other chain. */ function channelOpenAck( IBCMsgs.MsgChannelOpenAck calldata msg_ ) external; /** * @dev channelOpenConfirm is called by the counterparty module to close their end of the channel, since the other end has been closed. */ function channelOpenConfirm( IBCMsgs.MsgChannelOpenConfirm calldata msg_ ) external; /** * @dev channelCloseInit is called by either module to close their end of the channel. Once closed, channels cannot be reopened. */ function channelCloseInit( IBCMsgs.MsgChannelCloseInit calldata msg_ ) external; /** * @dev channelCloseConfirm is called by the counterparty module to close their end of the * channel, since the other end has been closed. */ function channelCloseConfirm( IBCMsgs.MsgChannelCloseConfirm calldata msg_ ) external; }
pragma solidity ^0.8.27; library Hex { error ErrInvalidHexAddress(); // Convert 32 hexadecimal digits into 16 bytes. function hexToBytes16( bytes32 h ) internal pure returns (bytes16 b) { unchecked { // Ensure all chars below 128 if ( h & 0x8080808080808080808080808080808080808080808080808080808080808080 != 0 ) { revert ErrInvalidHexAddress(); } // Subtract '0' from every char h = bytes32( uint256(h) - 0x3030303030303030303030303030303030303030303030303030303030303030 ); // Ensure all chars still below 128, i.e. no underflow in the previous line if ( h & 0x8080808080808080808080808080808080808080808080808080808080808080 != 0 ) { revert ErrInvalidHexAddress(); } // Calculate mask for chars that originally were above '9' bytes32 ndm = bytes32( ( ( ( uint256(h) + 0x7676767676767676767676767676767676767676767676767676767676767676 ) & 0x8080808080808080808080808080808080808080808080808080808080808080 ) >> 7 ) * 0xFF ); // Subtract 7 ('A' - '0') from every char that originally was above '9' h = bytes32( uint256(h) - uint256( ndm & 0x0707070707070707070707070707070707070707070707070707070707070707 ) ); // Ensure all chars still below 128, i.e. no underflow in the previous line if ( h & 0x8080808080808080808080808080808080808080808080808080808080808080 != 0 ) { revert ErrInvalidHexAddress(); } // Ensure chars that originally were above '9' are now above 9 if ( ( uint256(h) - uint256( ndm & 0x0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A ) ) & 0x8080808080808080808080808080808080808080808080808080808080808080 != 0 ) { revert ErrInvalidHexAddress(); } // Calculate Mask for chars that originally were above 'F' bytes32 lcm = bytes32( ( ( ( uint256(h) + 0x7070707070707070707070707070707070707070707070707070707070707070 ) & 0x8080808080808080808080808080808080808080808080808080808080808080 ) >> 7 ) * 0xFF ); // Subtract 32 ('a' - 'A') from all chars that oroginally were above 'F' h = bytes32( uint256(h) - uint256( lcm & 0x2020202020202020202020202020202020202020202020202020202020202020 ) ); // Ensure chars that originally were above 'F' are now above 9 if ( ( uint256(h) - uint256( lcm & 0x0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A ) ) & 0x8080808080808080808080808080808080808080808080808080808080808080 != 0 ) { revert ErrInvalidHexAddress(); } // Ensure all chars are below 16 if ( h & 0xF0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0 != 0 ) { revert ErrInvalidHexAddress(); } // 0x0A0B0C0D... -> 0xAB00CD00... h = ( ( h & 0x0F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F00 ) << 4 ) | ( ( h & 0x000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F ) << 8 ); // 0xAA00BB00CC00DD00... -> 0xAABB0000CCDD0000... h = ( h & 0xFF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000 ) | ( ( h & 0x0000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF00 ) << 8 ); // 0xAAAA0000BBBB0000CCCC0000DDDD0000... -> 0xAAAABBBB00000000CCCCDDDD00000000... h = ( h & 0xFFFF000000000000FFFF000000000000FFFF000000000000FFFF000000000000 ) | ( ( h & 0x00000000FFFF000000000000FFFF000000000000FFFF000000000000FFFF0000 ) << 16 ); // 0xAAAAAAAA00000000BBBBBBBB00000000CCCCCCCC00000000DDDDDDDD00000000 -> 0xAAAAAAAABBBBBBBB0000000000000000CCCCCCCCDDDDDDDD0000000000000000 h = ( h & 0xFFFFFFFF000000000000000000000000FFFFFFFF000000000000000000000000 ) | ( ( h & 0x0000000000000000FFFFFFFF000000000000000000000000FFFFFFFF00000000 ) << 32 ); // 0xAAAAAAAAAAAAAAAA0000000000000000BBBBBBBBBBBBBBBB0000000000000000 -> 0xAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBB00000000000000000000000000000000 h = ( h & 0xFFFFFFFFFFFFFFFF000000000000000000000000000000000000000000000000 ) | ( ( h & 0x00000000000000000000000000000000FFFFFFFFFFFFFFFF0000000000000000 ) << 64 ); // Trim to 16 bytes b = bytes16(h); } } function hexToAddress( string memory s ) internal pure returns (address) { if (bytes(s).length != 42) { revert ErrInvalidHexAddress(); } bytes2 prefix; bytes32 leftHex; bytes32 rightHex; assembly { prefix := mload(add(s, 0x20)) leftHex := mload(add(s, 0x22)) rightHex := mload(add(s, 0x2A)) } if (prefix != "0x") { revert ErrInvalidHexAddress(); } bytes16 left = hexToBytes16(leftHex); bytes16 right = hexToBytes16(rightHex); return address(bytes20(left) | (bytes20(right) >> 32)); } function atoi( bytes1 b ) internal pure returns (uint8 res) { if (b >= "0" && b <= "9") { return uint8(b) - uint8(bytes1("0")); } else if (b >= "A" && b <= "F") { return 10 + uint8(b) - uint8(bytes1("A")); } else if (b >= "a" && b <= "f") { return 10 + uint8(b) - uint8(bytes1("a")); } return uint8(b); } function hexToUint256( string memory s ) internal pure returns (uint256) { bytes memory b = bytes(s); uint256 number; for (uint256 i = 2; i < b.length; i++) { number = number << 4; number |= atoi(b[i]); } return number; } }
pragma solidity ^0.8.27; import "../25-handler/IBCMsgs.sol"; interface IIBCPacket { /** * @dev sendPacket is called by a module in order to send an IBC packet on a channel. * The packet sequence generated for the packet to be sent is returned. An error * is returned if one occurs. */ function sendPacket( uint32 sourceChannel, uint64 timeoutHeight, uint64 timeoutTimestamp, bytes calldata data ) external returns (IBCPacket memory packet); /** * @dev recvPacket is called by a module in order to receive & process an IBC packet * sent on the corresponding channel end on the counterparty chain. */ function recvPacket( IBCMsgs.MsgPacketRecv calldata msg_ ) external; /** * @dev recvIntentPacket is called by a module in order to receive & process an IBC intent packet * for an IBC packet sent on the corresponding channel end on the counterparty chain. * Note that no verification is done by the handler, the protocol must ensure that the market maker fullfilling the intent executes the expected effects. */ function recvIntentPacket( IBCMsgs.MsgIntentPacketRecv calldata msg_ ) external; /** * @dev writeAcknowledgement writes the packet execution acknowledgement to the state, * which will be verified by the counterparty chain using AcknowledgePacket. */ function writeAcknowledgement( IBCPacket calldata packet, bytes memory acknowledgement ) external; /** * @dev AcknowledgePacket is called by a module to process the acknowledgement of a * packet previously sent by the calling module on a channel to a counterparty * module on the counterparty chain. Its intended usage is within the ante * handler. AcknowledgePacket will clean up the packet commitment, * which is no longer necessary since the packet has been received and acted upon. * It will also increment NextSequenceAck in case of ORDERED channels. */ function acknowledgePacket( IBCMsgs.MsgPacketAcknowledgement calldata msg_ ) external; /** * @dev timeoutPacket is called by a module in order to receive & process an IBC packet * sent on the corresponding channel end on the counterparty chain. */ function timeoutPacket( IBCMsgs.MsgPacketTimeout calldata msg_ ) external; /** * @dev batchSend is called by a module in order to commit multiple IBC packets that have been previously sent. * An error occur if any of the packets wasn't sent. * If successful, a new commitment is registered for the batch. */ function batchSend( IBCMsgs.MsgBatchSend calldata msg_ ) external; /** * @dev batchAcks is called by a module in order to commit multiple IBC packets acknowledgements. * An error occur if any of the packets wasn't received. * If successful, a new commitment is registered for the batch. */ function batchAcks( IBCMsgs.MsgBatchAcks calldata msg_ ) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Library for byte related operations. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibBytes.sol) library LibBytes { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STRUCTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Goated bytes storage struct that totally MOGs, no cap, fr. /// Uses less gas and bytecode than Solidity's native bytes storage. It's meta af. /// Packs length with the first 31 bytes if <255 bytes, so it’s mad tight. struct BytesStorage { bytes32 _spacer; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The constant returned when the `search` is not found in the bytes. uint256 internal constant NOT_FOUND = type(uint256).max; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* BYTE STORAGE OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Sets the value of the bytes storage `$` to `s`. function set(BytesStorage storage $, bytes memory s) internal { /// @solidity memory-safe-assembly assembly { let n := mload(s) let packed := or(0xff, shl(8, n)) for { let i := 0 } 1 {} { if iszero(gt(n, 0xfe)) { i := 0x1f packed := or(n, shl(8, mload(add(s, i)))) if iszero(gt(n, i)) { break } } let o := add(s, 0x20) mstore(0x00, $.slot) for { let p := keccak256(0x00, 0x20) } 1 {} { sstore(add(p, shr(5, i)), mload(add(o, i))) i := add(i, 0x20) if iszero(lt(i, n)) { break } } break } sstore($.slot, packed) } } /// @dev Sets the value of the bytes storage `$` to `s`. function setCalldata(BytesStorage storage $, bytes calldata s) internal { /// @solidity memory-safe-assembly assembly { let packed := or(0xff, shl(8, s.length)) for { let i := 0 } 1 {} { if iszero(gt(s.length, 0xfe)) { i := 0x1f packed := or(s.length, shl(8, shr(8, calldataload(s.offset)))) if iszero(gt(s.length, i)) { break } } mstore(0x00, $.slot) for { let p := keccak256(0x00, 0x20) } 1 {} { sstore(add(p, shr(5, i)), calldataload(add(s.offset, i))) i := add(i, 0x20) if iszero(lt(i, s.length)) { break } } break } sstore($.slot, packed) } } /// @dev Sets the value of the bytes storage `$` to the empty bytes. function clear(BytesStorage storage $) internal { delete $._spacer; } /// @dev Returns whether the value stored is `$` is the empty bytes "". function isEmpty(BytesStorage storage $) internal view returns (bool) { return uint256($._spacer) & 0xff == uint256(0); } /// @dev Returns the length of the value stored in `$`. function length(BytesStorage storage $) internal view returns (uint256 result) { result = uint256($._spacer); /// @solidity memory-safe-assembly assembly { let n := and(0xff, result) result := or(mul(shr(8, result), eq(0xff, n)), mul(n, iszero(eq(0xff, n)))) } } /// @dev Returns the value stored in `$`. function get(BytesStorage storage $) internal view returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { result := mload(0x40) let o := add(result, 0x20) let packed := sload($.slot) let n := shr(8, packed) for { let i := 0 } 1 {} { if iszero(eq(or(packed, 0xff), packed)) { mstore(o, packed) n := and(0xff, packed) i := 0x1f if iszero(gt(n, i)) { break } } mstore(0x00, $.slot) for { let p := keccak256(0x00, 0x20) } 1 {} { mstore(add(o, i), sload(add(p, shr(5, i)))) i := add(i, 0x20) if iszero(lt(i, n)) { break } } break } mstore(result, n) // Store the length of the memory. mstore(add(o, n), 0) // Zeroize the slot after the bytes. mstore(0x40, add(add(o, n), 0x20)) // Allocate memory. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* BYTES OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns `subject` all occurrences of `needle` replaced with `replacement`. function replace(bytes memory subject, bytes memory needle, bytes memory replacement) internal pure returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { result := mload(0x40) let needleLen := mload(needle) let replacementLen := mload(replacement) let d := sub(result, subject) // Memory difference. let i := add(subject, 0x20) // Subject bytes pointer. mstore(0x00, add(i, mload(subject))) // End of subject. if iszero(gt(needleLen, mload(subject))) { let subjectSearchEnd := add(sub(mload(0x00), needleLen), 1) let h := 0 // The hash of `needle`. if iszero(lt(needleLen, 0x20)) { h := keccak256(add(needle, 0x20), needleLen) } let s := mload(add(needle, 0x20)) for { let m := shl(3, sub(0x20, and(needleLen, 0x1f))) } 1 {} { let t := mload(i) // Whether the first `needleLen % 32` bytes of `subject` and `needle` matches. if iszero(shr(m, xor(t, s))) { if h { if iszero(eq(keccak256(i, needleLen), h)) { mstore(add(i, d), t) i := add(i, 1) if iszero(lt(i, subjectSearchEnd)) { break } continue } } // Copy the `replacement` one word at a time. for { let j := 0 } 1 {} { mstore(add(add(i, d), j), mload(add(add(replacement, 0x20), j))) j := add(j, 0x20) if iszero(lt(j, replacementLen)) { break } } d := sub(add(d, replacementLen), needleLen) if needleLen { i := add(i, needleLen) if iszero(lt(i, subjectSearchEnd)) { break } continue } } mstore(add(i, d), t) i := add(i, 1) if iszero(lt(i, subjectSearchEnd)) { break } } } let end := mload(0x00) let n := add(sub(d, add(result, 0x20)), end) // Copy the rest of the bytes one word at a time. for {} lt(i, end) { i := add(i, 0x20) } { mstore(add(i, d), mload(i)) } let o := add(i, d) mstore(o, 0) // Zeroize the slot after the bytes. mstore(0x40, add(o, 0x20)) // Allocate memory. mstore(result, n) // Store the length. } } /// @dev Returns the byte index of the first location of `needle` in `subject`, /// needleing from left to right, starting from `from`. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found. function indexOf(bytes memory subject, bytes memory needle, uint256 from) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := not(0) // Initialize to `NOT_FOUND`. for { let subjectLen := mload(subject) } 1 {} { if iszero(mload(needle)) { result := from if iszero(gt(from, subjectLen)) { break } result := subjectLen break } let needleLen := mload(needle) let subjectStart := add(subject, 0x20) subject := add(subjectStart, from) let end := add(sub(add(subjectStart, subjectLen), needleLen), 1) let m := shl(3, sub(0x20, and(needleLen, 0x1f))) let s := mload(add(needle, 0x20)) if iszero(and(lt(subject, end), lt(from, subjectLen))) { break } if iszero(lt(needleLen, 0x20)) { for { let h := keccak256(add(needle, 0x20), needleLen) } 1 {} { if iszero(shr(m, xor(mload(subject), s))) { if eq(keccak256(subject, needleLen), 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 `needle` in `subject`, /// needleing from left to right. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found. function indexOf(bytes memory subject, bytes memory needle) internal pure returns (uint256) { return indexOf(subject, needle, 0); } /// @dev Returns the byte index of the first location of `needle` in `subject`, /// needleing from right to left, starting from `from`. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found. function lastIndexOf(bytes memory subject, bytes memory needle, uint256 from) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { for {} 1 {} { result := not(0) // Initialize to `NOT_FOUND`. let needleLen := mload(needle) if gt(needleLen, mload(subject)) { break } let w := result let fromMax := sub(mload(subject), needleLen) 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(needle, 0x20), needleLen) } 1 {} { if eq(keccak256(subject, needleLen), 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 `needle` in `subject`, /// needleing from right to left. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found. function lastIndexOf(bytes memory subject, bytes memory needle) internal pure returns (uint256) { return lastIndexOf(subject, needle, type(uint256).max); } /// @dev Returns true if `needle` is found in `subject`, false otherwise. function contains(bytes memory subject, bytes memory needle) internal pure returns (bool) { return indexOf(subject, needle) != NOT_FOUND; } /// @dev Returns whether `subject` starts with `needle`. function startsWith(bytes memory subject, bytes memory needle) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let n := mload(needle) // Just using keccak256 directly is actually cheaper. let t := eq(keccak256(add(subject, 0x20), n), keccak256(add(needle, 0x20), n)) result := lt(gt(n, mload(subject)), t) } } /// @dev Returns whether `subject` ends with `needle`. function endsWith(bytes memory subject, bytes memory needle) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let n := mload(needle) let notInRange := gt(n, mload(subject)) // `subject + 0x20 + max(subject.length - needle.length, 0)`. let t := add(add(subject, 0x20), mul(iszero(notInRange), sub(mload(subject), n))) // Just using keccak256 directly is actually cheaper. result := gt(eq(keccak256(t, n), keccak256(add(needle, 0x20), n)), notInRange) } } /// @dev Returns `subject` repeated `times`. function repeat(bytes memory subject, uint256 times) internal pure returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { let l := mload(subject) // Subject length. if iszero(or(iszero(times), iszero(l))) { result := mload(0x40) subject := add(subject, 0x20) let o := add(result, 0x20) for {} 1 {} { // Copy the `subject` one word at a time. for { let j := 0 } 1 {} { mstore(add(o, j), mload(add(subject, j))) j := add(j, 0x20) if iszero(lt(j, l)) { break } } o := add(o, l) times := sub(times, 1) if iszero(times) { break } } mstore(o, 0) // Zeroize the slot after the bytes. mstore(0x40, add(o, 0x20)) // Allocate memory. mstore(result, sub(o, add(result, 0x20))) // Store the length. } } } /// @dev Returns a copy of `subject` sliced from `start` to `end` (exclusive). /// `start` and `end` are byte offsets. function slice(bytes memory subject, uint256 start, uint256 end) internal pure returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { let l := mload(subject) // Subject length. if iszero(gt(l, end)) { end := l } if iszero(gt(l, start)) { start := l } if lt(start, end) { result := mload(0x40) let n := sub(end, start) let i := add(subject, start) let w := not(0x1f) // Copy the `subject` one word at a time, backwards. for { let j := and(add(n, 0x1f), w) } 1 {} { mstore(add(result, j), mload(add(i, j))) j := add(j, w) // `sub(j, 0x20)`. if iszero(j) { break } } let o := add(add(result, 0x20), n) mstore(o, 0) // Zeroize the slot after the bytes. mstore(0x40, add(o, 0x20)) // Allocate memory. mstore(result, n) // Store the length. } } } /// @dev Returns a copy of `subject` sliced from `start` to the end of the bytes. /// `start` is a byte offset. function slice(bytes memory subject, uint256 start) internal pure returns (bytes memory result) { result = slice(subject, start, type(uint256).max); } /// @dev Returns a copy of `subject` sliced from `start` to `end` (exclusive). /// `start` and `end` are byte offsets. Faster than Solidity's native slicing. function sliceCalldata(bytes calldata subject, uint256 start, uint256 end) internal pure returns (bytes calldata result) { /// @solidity memory-safe-assembly assembly { end := xor(end, mul(xor(end, subject.length), lt(subject.length, end))) start := xor(start, mul(xor(start, subject.length), lt(subject.length, start))) result.offset := add(subject.offset, start) result.length := mul(lt(start, end), sub(end, start)) } } /// @dev Returns a copy of `subject` sliced from `start` to the end of the bytes. /// `start` is a byte offset. Faster than Solidity's native slicing. function sliceCalldata(bytes calldata subject, uint256 start) internal pure returns (bytes calldata result) { /// @solidity memory-safe-assembly assembly { start := xor(start, mul(xor(start, subject.length), lt(subject.length, start))) result.offset := add(subject.offset, start) result.length := mul(lt(start, subject.length), sub(subject.length, start)) } } /// @dev Reduces the size of `subject` to `n`. /// If `n` is greater than the size of `subject`, this will be a no-op. function truncate(bytes memory subject, uint256 n) internal pure returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { result := subject mstore(mul(lt(n, mload(result)), result), n) } } /// @dev Returns a copy of `subject`, with the length reduced to `n`. /// If `n` is greater than the size of `subject`, this will be a no-op. function truncatedCalldata(bytes calldata subject, uint256 n) internal pure returns (bytes calldata result) { /// @solidity memory-safe-assembly assembly { result.offset := subject.offset result.length := xor(n, mul(xor(n, subject.length), lt(subject.length, n))) } } /// @dev Returns all the indices of `needle` in `subject`. /// The indices are byte offsets. function indicesOf(bytes memory subject, bytes memory needle) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { let searchLen := mload(needle) if iszero(gt(searchLen, mload(subject))) { result := mload(0x40) let i := add(subject, 0x20) let o := add(result, 0x20) let subjectSearchEnd := add(sub(add(i, mload(subject)), searchLen), 1) let h := 0 // The hash of `needle`. if iszero(lt(searchLen, 0x20)) { h := keccak256(add(needle, 0x20), searchLen) } let s := mload(add(needle, 0x20)) for { let m := shl(3, sub(0x20, and(searchLen, 0x1f))) } 1 {} { let t := mload(i) // Whether the first `searchLen % 32` bytes of `subject` and `needle` matches. if iszero(shr(m, xor(t, s))) { if h { if iszero(eq(keccak256(i, searchLen), h)) { i := add(i, 1) if iszero(lt(i, subjectSearchEnd)) { break } continue } } mstore(o, sub(i, add(subject, 0x20))) // Append to `result`. o := add(o, 0x20) i := add(i, searchLen) // Advance `i` by `searchLen`. if searchLen { if iszero(lt(i, subjectSearchEnd)) { break } continue } } i := add(i, 1) if iszero(lt(i, subjectSearchEnd)) { break } } mstore(result, shr(5, sub(o, add(result, 0x20)))) // Store the length of `result`. // Allocate memory for result. // We allocate one more word, so this array can be recycled for {split}. mstore(0x40, add(o, 0x20)) } } } /// @dev Returns a arrays of bytess based on the `delimiter` inside of the `subject` bytes. function split(bytes memory subject, bytes memory delimiter) internal pure returns (bytes[] 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)) for { let prevIndex := 0 } 1 {} { let index := mload(indexPtr) mstore(indexPtr, 0x60) if iszero(eq(index, prevIndex)) { let element := mload(0x40) let l := sub(index, prevIndex) mstore(element, l) // Store the length of the element. // Copy the `subject` one word at a time, backwards. for { let o := and(add(l, 0x1f), w) } 1 {} { mstore(add(element, o), mload(add(add(subject, prevIndex), o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } mstore(add(add(element, 0x20), l), 0) // Zeroize the slot after the bytes. // Allocate memory for the length and the bytes, rounded up to a multiple of 32. mstore(0x40, add(element, and(add(l, 0x3f), w))) mstore(indexPtr, element) // Store the `element` into the array. } 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 bytes of `a` and `b`. /// Cheaper than `bytes.concat()` and does not de-align the free memory pointer. function concat(bytes memory a, bytes memory b) internal pure returns (bytes memory result) { /// @solidity memory-safe-assembly assembly { result := mload(0x40) let w := not(0x1f) let aLen := mload(a) // Copy `a` one word at a time, backwards. for { let o := and(add(aLen, 0x20), w) } 1 {} { mstore(add(result, o), mload(add(a, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } let bLen := mload(b) let output := add(result, aLen) // Copy `b` one word at a time, backwards. for { let o := and(add(bLen, 0x20), w) } 1 {} { mstore(add(output, o), mload(add(b, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } let totalLen := add(aLen, bLen) let last := add(add(result, 0x20), totalLen) mstore(last, 0) // Zeroize the slot after the bytes. mstore(result, totalLen) // Store the length. mstore(0x40, add(last, 0x20)) // Allocate memory. } } /// @dev Returns whether `a` equals `b`. function eq(bytes memory a, bytes 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`, where `b` is a null-terminated small bytes. function eqs(bytes 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 m := not(shl(7, div(not(iszero(b)), 255))) // `0x7f7f ...`. let x := not(or(m, or(b, add(m, and(b, m))))) let r := 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)))) // forgefmt: disable-next-item result := gt(eq(mload(a), add(iszero(x), xor(31, shr(3, r)))), xor(shr(add(8, r), b), shr(add(8, r), mload(add(a, 0x20))))) } } /// @dev Returns 0 if `a == b`, -1 if `a < b`, +1 if `a > b`. /// If `a` == b[:a.length]`, and `a.length < b.length`, returns -1. function cmp(bytes memory a, bytes memory b) internal pure returns (int256 result) { /// @solidity memory-safe-assembly assembly { let aLen := mload(a) let bLen := mload(b) let n := and(xor(aLen, mul(xor(aLen, bLen), lt(bLen, aLen))), not(0x1f)) if n { for { let i := 0x20 } 1 {} { let x := mload(add(a, i)) let y := mload(add(b, i)) if iszero(or(xor(x, y), eq(i, n))) { i := add(i, 0x20) continue } result := sub(gt(x, y), lt(x, y)) break } } // forgefmt: disable-next-item if iszero(result) { let l := 0x201f1e1d1c1b1a191817161514131211100f0e0d0c0b0a090807060504030201 let x := and(mload(add(add(a, 0x20), n)), shl(shl(3, byte(sub(aLen, n), l)), not(0))) let y := and(mload(add(add(b, 0x20), n)), shl(shl(3, byte(sub(bLen, n), l)), not(0))) result := sub(gt(x, y), lt(x, y)) if iszero(result) { result := sub(gt(aLen, bLen), lt(aLen, bLen)) } } } } /// @dev Directly returns `a` without copying. function directReturn(bytes memory a) internal pure { assembly { // Assumes that the bytes does not start from the scratch space. let retStart := sub(a, 0x20) let retUnpaddedSize := add(mload(a), 0x40) // Right pad with zeroes. Just in case the bytes is produced // by a method that doesn't zero right pad. mstore(add(retStart, retUnpaddedSize), 0) mstore(retStart, 0x20) // Store the return offset. // End the transaction, returning the bytes. return(retStart, and(not(0x1f), add(0x1f, retUnpaddedSize))) } } /// @dev Directly returns `a` with minimal copying. function directReturn(bytes[] memory a) internal pure { assembly { let n := mload(a) // `a.length`. let o := add(a, 0x20) // Start of elements in `a`. let u := a // Highest memory slot. let w := not(0x1f) for { let i := 0 } iszero(eq(i, n)) { i := add(i, 1) } { let c := add(o, shl(5, i)) // Location of pointer to `a[i]`. let s := mload(c) // `a[i]`. let l := mload(s) // `a[i].length`. let r := and(l, 0x1f) // `a[i].length % 32`. let z := add(0x20, and(l, w)) // Offset of last word in `a[i]` from `s`. // If `s` comes before `o`, or `s` is not zero right padded. if iszero(lt(lt(s, o), or(iszero(r), iszero(shl(shl(3, r), mload(add(s, z))))))) { let m := mload(0x40) mstore(m, l) // Copy `a[i].length`. for {} 1 {} { mstore(add(m, z), mload(add(s, z))) // Copy `a[i]`, backwards. z := add(z, w) // `sub(z, 0x20)`. if iszero(z) { break } } let e := add(add(m, 0x20), l) mstore(e, 0) // Zeroize the slot after the copied bytes. mstore(0x40, add(e, 0x20)) // Allocate memory. s := m } mstore(c, sub(s, o)) // Convert to calldata offset. let t := add(l, add(s, 0x20)) if iszero(lt(t, u)) { u := t } } let retStart := add(a, w) // Assumes `a` doesn't start from scratch space. mstore(retStart, 0x20) // Store the return offset. return(retStart, add(0x40, sub(u, retStart))) // End the transaction. } } /// @dev Returns the word at `offset`, without any bounds checks. /// To load an address, you can use `address(bytes20(load(a, offset)))`. function load(bytes memory a, uint256 offset) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { result := mload(add(add(a, 0x20), offset)) } } /// @dev Returns the word at `offset`, without any bounds checks. /// To load an address, you can use `address(bytes20(loadCalldata(a, offset)))`. function loadCalldata(bytes calldata a, uint256 offset) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { result := calldataload(add(a.offset, offset)) } } /// @dev Returns empty calldata bytes. For silencing the compiler. function emptyCalldata() internal pure returns (bytes calldata result) { /// @solidity memory-safe-assembly assembly { result.length := 0 } } }
{ "remappings": [ "@openzeppelin-foundry-upgradeable/=libs/@openzeppelin-foundry-upgradeable/", "@openzeppelin-upgradeable/=libs/@openzeppelin-upgradeable/", "@openzeppelin/=libs/@openzeppelin/", "forge-std/=libs/forge-std/", "solady/=libs/solady/", "solidity-bytes-utils/=libs/solidity-bytes-utils/contracts/", "solidity-stringutils/=libs/solidity-stringutils/" ], "optimizer": { "enabled": true, "runs": 1000, "details": { "cse": true, "constantOptimizer": true, "yul": true } }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "viaIR": true, "libraries": {} }
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ErrInfiniteGame","type":"error"},{"inputs":[],"name":"ErrInvalidAck","type":"error"},{"inputs":[],"name":"ErrNotIBC","type":"error"},{"inputs":[],"name":"ErrNotImplemented","type":"error"},{"inputs":[],"name":"ErrOnlyZKGM","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"anonymous":false,"inputs":[],"name":"Acknowledged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"ping","type":"bool"}],"name":"Ring","type":"event"},{"anonymous":false,"inputs":[],"name":"TimedOut","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"channelId","type":"uint32"},{"indexed":false,"internalType":"bytes","name":"sender","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"message","type":"bytes"}],"name":"Zkgoblim","type":"event"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ibcAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IIBCPacket","name":"_ibcHandler","type":"address"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"uint64","name":"_timeout","type":"uint64"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"ping","type":"bool"}],"internalType":"struct PingPongPacket","name":"packet","type":"tuple"},{"internalType":"uint32","name":"channelId","type":"uint32"},{"internalType":"uint64","name":"localTimeout","type":"uint64"}],"name":"initiate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"sourceChannelId","type":"uint32"},{"internalType":"uint32","name":"destinationChannelId","type":"uint32"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint64","name":"timeoutHeight","type":"uint64"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"}],"internalType":"struct IBCPacket","name":"","type":"tuple"},{"internalType":"bytes","name":"acknowledgement","type":"bytes"},{"internalType":"address","name":"","type":"address"}],"name":"onAcknowledgementPacket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"address","name":"","type":"address"}],"name":"onChanCloseConfirm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"address","name":"","type":"address"}],"name":"onChanCloseInit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"channelId","type":"uint32"},{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"string","name":"","type":"string"},{"internalType":"address","name":"","type":"address"}],"name":"onChanOpenAck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"channelId","type":"uint32"},{"internalType":"address","name":"","type":"address"}],"name":"onChanOpenConfirm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"string","name":"","type":"string"},{"internalType":"address","name":"","type":"address"}],"name":"onChanOpenInit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"string","name":"","type":"string"},{"internalType":"string","name":"","type":"string"},{"internalType":"address","name":"","type":"address"}],"name":"onChanOpenTry","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"sourceChannelId","type":"uint32"},{"internalType":"uint32","name":"destinationChannelId","type":"uint32"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint64","name":"timeoutHeight","type":"uint64"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"}],"internalType":"struct IBCPacket","name":"","type":"tuple"},{"internalType":"address","name":"","type":"address"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onRecvIntentPacket","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"sourceChannelId","type":"uint32"},{"internalType":"uint32","name":"destinationChannelId","type":"uint32"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint64","name":"timeoutHeight","type":"uint64"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"}],"internalType":"struct IBCPacket","name":"packet","type":"tuple"},{"internalType":"address","name":"","type":"address"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onRecvPacket","outputs":[{"internalType":"bytes","name":"acknowledgement","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"sourceChannelId","type":"uint32"},{"internalType":"uint32","name":"destinationChannelId","type":"uint32"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint64","name":"timeoutHeight","type":"uint64"},{"internalType":"uint64","name":"timeoutTimestamp","type":"uint64"}],"internalType":"struct IBCPacket","name":"","type":"tuple"},{"internalType":"address","name":"","type":"address"}],"name":"onTimeoutPacket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"channelId","type":"uint32"},{"internalType":"bytes","name":"sender","type":"bytes"},{"internalType":"bytes","name":"message","type":"bytes"}],"name":"onZkgm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"zkgm","type":"address"}],"name":"setZkgm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"}]
Contract Creation Code
60a080604052346100ea57306080527ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c166100d9576002600160401b03196001600160401b03821601610073575b60405161152190816100f082396080518181816108b8015261099c0152f35b6001600160401b0319166001600160401b039081177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a13880610054565b63f92ee8a960e01b60005260046000fd5b600080fdfe6080604052600436101561001257600080fd5b60003560e01c8063087cca7f14610cb157806313312a7e14610c3957806327e756d414610932578063423b7df614610c0e5780634f1ef2861461094d5780635209209d1461093257806352d1902d1461089d578063578392c5146103885780635c4a461c146108595780635c975abb14610817578063696a9bf4146107f0578063715018a61461074a5780637879ec31146105215780638da5cb5b146104db578063986753951461048d578063ad3cb1cc1461042a578063b44d3be8146103dd578063c2c0030b14610388578063d9ee84fb14610293578063da6a798614610229578063f2fde38b146101fe5763f33d71751461010e57600080fd5b346101f95760603660031901126101f95760043567ffffffffffffffff81116101f95760a09060031990360301126101f95760243567ffffffffffffffff81116101f95761016361017b913690600401610e73565b61016b610e5d565b50610174611363565b369161105e565b602081519101206040516020810190600160f81b8252600181526101a0602182611020565b519020036101cf577f6d45fcb3ac6f90804e961e6f86b28ebf0d54b90becc071e931a4bd59cacec052600080a1005b7f1e4e37ab0000000000000000000000000000000000000000000000000000000060005260046000fd5b600080fd5b346101f95760203660031901126101f95761022761021a610e47565b6102226113a1565b611297565b005b346101f95760403660031901126101f95760043567ffffffffffffffff81116101f95760a09060031990360301126101f957610263610e31565b5061026c611363565b7f2994e1140d9b387c958be4b4ee3692c84ef8b6864b02d4714bde9ea686a5414d600080a1005b346101f95760603660031901126101f9576102ac610f50565b60243567ffffffffffffffff81116101f9576102cc903690600401610e73565b909160443567ffffffffffffffff81116101f9576102ee903690600401610e73565b93906001600160a01b0360015416330361035e577f4593e827c9c8914553f95fb1411f338b68198b8e83f072449f46ba8a9c43308e9461034b6103599363ffffffff96604051978897168752606060208801526060870191611276565b918483036040860152611276565b0390a1005b7f41e565c40000000000000000000000000000000000000000000000000000000060005260046000fd5b346101f95760403660031901126101f9576103a1610f50565b506103aa610e31565b506103b3611363565b7ff1c8ae4a0000000000000000000000000000000000000000000000000000000060005260046000fd5b346101f95760203660031901126101f9576001600160a01b036103fe610e47565b6104066113a1565b1673ffffffffffffffffffffffffffffffffffffffff196001541617600155600080f35b346101f95760003660031901126101f957610489604080519061044d8183611020565b600582527f352e302e30000000000000000000000000000000000000000000000000000000602083015251918291602083526020830190610f2b565b0390f35b346101f9573660031901606081126101f9576020136101f9576040516104b281610fee565b6004359081151582036101f9576102279181526104cd610f63565b6104d5611095565b916110d2565b346101f95760003660031901126101f95760206001600160a01b037f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c1993005416604051908152f35b346101f95760603660031901126101f9576004356001600160a01b0381168091036101f95761054e610e31565b90610557611095565b907ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c16159367ffffffffffffffff821680159081610742575b6001149081610738575b15908161072f575b506107055767ffffffffffffffff1982166001177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00556105fa91856106c6575b506105f2611402565b610222611402565b77ffffffff00000000000000000000000000000000000000007fffffffffffffffff0000000000000000000000000000000000000000000000006000549360c01b169216171760005561064957005b68ff0000000000000000197ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054167ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00557fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602060405160018152a1005b68ffffffffffffffffff191668010000000000000001177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0055856105e9565b7ff92ee8a90000000000000000000000000000000000000000000000000000000060005260046000fd5b905015866105a9565b303b1591506105a1565b869150610597565b346101f95760003660031901126101f9576107636113a1565b60006001600160a01b037f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c1993005473ffffffffffffffffffffffffffffffffffffffff1981167f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b346101f95760003660031901126101f95760206001600160a01b0360005416604051908152f35b346101f95760003660031901126101f957602060ff7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f0330054166040519015158152f35b346101f95761086736610ea1565b50505050610873611363565b7f68b3ecb60000000000000000000000000000000000000000000000000000000060005260046000fd5b346101f95760003660031901126101f9576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036109085760206040517f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8152f35b7fe07c8dba0000000000000000000000000000000000000000000000000000000060005260046000fd5b346101f95761094036610f89565b5050505050610227611363565b60403660031901126101f957610961610e47565b60243567ffffffffffffffff81116101f957366023820112156101f95761099290369060248160040135910161105e565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016803014908115610bd9575b50610908576109d46113a1565b6001600160a01b038216916040517f52d1902d000000000000000000000000000000000000000000000000000000008152602081600481875afa60009181610ba5575b50610a315783634c9c8ce360e01b60005260045260246000fd5b807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc859203610b785750813b15610b64578073ffffffffffffffffffffffffffffffffffffffff197f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5416177f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2815115610b315760008083602061022795519101845af43d15610b29573d91610b0c83611042565b92610b1a6040519485611020565b83523d6000602085013e61145b565b60609161145b565b505034610b3a57005b7fb398979f0000000000000000000000000000000000000000000000000000000060005260046000fd5b634c9c8ce360e01b60005260045260246000fd5b7faa1d49a40000000000000000000000000000000000000000000000000000000060005260045260246000fd5b9091506020813d602011610bd1575b81610bc160209383611020565b810103126101f957519085610a17565b3d9150610bb4565b90506001600160a01b037f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54161415836109c7565b346101f95760403660031901126101f957610c27610f50565b50610c30610e31565b50610227611363565b346101f95760c03660031901126101f957610c52610f50565b50610c5b610f63565b50610c64610f76565b5060643567ffffffffffffffff81116101f957610c85903690600401610e73565b505060843567ffffffffffffffff81116101f957610ca7903690600401610e73565b5050610c30610e1b565b346101f957610cbf36610ea1565b505050610cca611363565b6040810135601e19823603018112156101f957810180359067ffffffffffffffff82116101f95760200181360381136101f957610d0891369161105e565b6000604051610d1681610fee565b526020818051810103126101f957602001518015158091036101f9577f79ee09378f342f8ca76fdc4df724919954622285ad2e3b271daee3823e397efc602060405192610d6284610fee565b808452604051908152a1633b9aca004202428104633b9aca001442151715610e055767ffffffffffffffff60005460c01c9116019067ffffffffffffffff8211610e0557516040519260209115610db885610fee565b8452013563ffffffff811681036101f957610dd2926110d2565b610489604051600160f81b602082015260018152610df1602182611020565b604051918291602083526020830190610f2b565b634e487b7160e01b600052601160045260246000fd5b60a435906001600160a01b03821682036101f957565b602435906001600160a01b03821682036101f957565b600435906001600160a01b03821682036101f957565b604435906001600160a01b03821682036101f957565b9181601f840112156101f95782359167ffffffffffffffff83116101f957602083818601950101116101f957565b60606003198201126101f95760043567ffffffffffffffff81116101f95760a081830360031901126101f957600401916024356001600160a01b03811681036101f957916044359067ffffffffffffffff82116101f957610f0491600401610e73565b9091565b60005b838110610f1b5750506000910152565b8181015183820152602001610f0b565b90602091610f4481518092818552858086019101610f08565b601f01601f1916010190565b6004359063ffffffff821682036101f957565b6024359063ffffffff821682036101f957565b6044359063ffffffff821682036101f957565b60806003198201126101f95760043563ffffffff811681036101f9579160243563ffffffff811681036101f957916044359067ffffffffffffffff82116101f957610fd691600401610e73565b90916064356001600160a01b03811681036101f95790565b6020810190811067ffffffffffffffff82111761100a57604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff82111761100a57604052565b67ffffffffffffffff811161100a57601f01601f191660200190565b92919261106a82611042565b916110786040519384611020565b8294818452818301116101f9578281602093846000960137010152565b6044359067ffffffffffffffff821682036101f957565b519063ffffffff821682036101f957565b519067ffffffffffffffff821682036101f957565b9167ffffffffffffffff9263ffffffff600080946111606001600160a01b038354169451151560405190602082015260208152611110604082611020565b604051988997889687957fe5cbff79000000000000000000000000000000000000000000000000000000008752166004860152856024860152166044840152608060648401526084830190610f2b565b03925af1801561126a576111715750565b3d806000833e6111818183611020565b8101906020818303126101f95780519067ffffffffffffffff82116101f957019060a0828203126101f9576040519160a0830183811067ffffffffffffffff82111761100a576040526111d3816110ac565b83526111e1602082016110ac565b6020840152604081015167ffffffffffffffff81116101f95781019082601f830112156101f95781519061121482611042565b936112226040519586611020565b828552602083850101116101f9578361124960809593611265956020808997019101610f08565b604086015261125a606082016110bd565b6060860152016110bd565b910152565b6040513d6000823e3d90fd5b908060209392818452848401376000828201840152601f01601f1916010190565b6001600160a01b03168015611334576001600160a01b037f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300548273ffffffffffffffffffffffffffffffffffffffff198216177f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b7f1e4fbdf700000000000000000000000000000000000000000000000000000000600052600060045260246000fd5b6001600160a01b0360005416330361137757565b7fe54f8f9d0000000000000000000000000000000000000000000000000000000060005260046000fd5b6001600160a01b037f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300541633036113d457565b7f118cdaa7000000000000000000000000000000000000000000000000000000006000523360045260246000fd5b60ff7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460401c161561143157565b7fd7e6bcf80000000000000000000000000000000000000000000000000000000060005260046000fd5b9061149a575080511561147057805190602001fd5b7f1425ea420000000000000000000000000000000000000000000000000000000060005260046000fd5b815115806114e2575b6114ab575090565b6001600160a01b03907f9996b315000000000000000000000000000000000000000000000000000000006000521660045260246000fd5b50803b156114a356fea26469706673582212202239515f734db7c18cc6a830d78b7e1c24562134b7ff1e4737ebb42db1bbfeea64736f6c634300081b0033
Deployed Bytecode
0x6080604052600436101561001257600080fd5b60003560e01c8063087cca7f14610cb157806313312a7e14610c3957806327e756d414610932578063423b7df614610c0e5780634f1ef2861461094d5780635209209d1461093257806352d1902d1461089d578063578392c5146103885780635c4a461c146108595780635c975abb14610817578063696a9bf4146107f0578063715018a61461074a5780637879ec31146105215780638da5cb5b146104db578063986753951461048d578063ad3cb1cc1461042a578063b44d3be8146103dd578063c2c0030b14610388578063d9ee84fb14610293578063da6a798614610229578063f2fde38b146101fe5763f33d71751461010e57600080fd5b346101f95760603660031901126101f95760043567ffffffffffffffff81116101f95760a09060031990360301126101f95760243567ffffffffffffffff81116101f95761016361017b913690600401610e73565b61016b610e5d565b50610174611363565b369161105e565b602081519101206040516020810190600160f81b8252600181526101a0602182611020565b519020036101cf577f6d45fcb3ac6f90804e961e6f86b28ebf0d54b90becc071e931a4bd59cacec052600080a1005b7f1e4e37ab0000000000000000000000000000000000000000000000000000000060005260046000fd5b600080fd5b346101f95760203660031901126101f95761022761021a610e47565b6102226113a1565b611297565b005b346101f95760403660031901126101f95760043567ffffffffffffffff81116101f95760a09060031990360301126101f957610263610e31565b5061026c611363565b7f2994e1140d9b387c958be4b4ee3692c84ef8b6864b02d4714bde9ea686a5414d600080a1005b346101f95760603660031901126101f9576102ac610f50565b60243567ffffffffffffffff81116101f9576102cc903690600401610e73565b909160443567ffffffffffffffff81116101f9576102ee903690600401610e73565b93906001600160a01b0360015416330361035e577f4593e827c9c8914553f95fb1411f338b68198b8e83f072449f46ba8a9c43308e9461034b6103599363ffffffff96604051978897168752606060208801526060870191611276565b918483036040860152611276565b0390a1005b7f41e565c40000000000000000000000000000000000000000000000000000000060005260046000fd5b346101f95760403660031901126101f9576103a1610f50565b506103aa610e31565b506103b3611363565b7ff1c8ae4a0000000000000000000000000000000000000000000000000000000060005260046000fd5b346101f95760203660031901126101f9576001600160a01b036103fe610e47565b6104066113a1565b1673ffffffffffffffffffffffffffffffffffffffff196001541617600155600080f35b346101f95760003660031901126101f957610489604080519061044d8183611020565b600582527f352e302e30000000000000000000000000000000000000000000000000000000602083015251918291602083526020830190610f2b565b0390f35b346101f9573660031901606081126101f9576020136101f9576040516104b281610fee565b6004359081151582036101f9576102279181526104cd610f63565b6104d5611095565b916110d2565b346101f95760003660031901126101f95760206001600160a01b037f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c1993005416604051908152f35b346101f95760603660031901126101f9576004356001600160a01b0381168091036101f95761054e610e31565b90610557611095565b907ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c16159367ffffffffffffffff821680159081610742575b6001149081610738575b15908161072f575b506107055767ffffffffffffffff1982166001177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00556105fa91856106c6575b506105f2611402565b610222611402565b77ffffffff00000000000000000000000000000000000000007fffffffffffffffff0000000000000000000000000000000000000000000000006000549360c01b169216171760005561064957005b68ff0000000000000000197ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054167ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00557fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602060405160018152a1005b68ffffffffffffffffff191668010000000000000001177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0055856105e9565b7ff92ee8a90000000000000000000000000000000000000000000000000000000060005260046000fd5b905015866105a9565b303b1591506105a1565b869150610597565b346101f95760003660031901126101f9576107636113a1565b60006001600160a01b037f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c1993005473ffffffffffffffffffffffffffffffffffffffff1981167f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b346101f95760003660031901126101f95760206001600160a01b0360005416604051908152f35b346101f95760003660031901126101f957602060ff7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f0330054166040519015158152f35b346101f95761086736610ea1565b50505050610873611363565b7f68b3ecb60000000000000000000000000000000000000000000000000000000060005260046000fd5b346101f95760003660031901126101f9576001600160a01b037f0000000000000000000000003ceb9022e3df13de45a48b97914972bf036c191f1630036109085760206040517f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8152f35b7fe07c8dba0000000000000000000000000000000000000000000000000000000060005260046000fd5b346101f95761094036610f89565b5050505050610227611363565b60403660031901126101f957610961610e47565b60243567ffffffffffffffff81116101f957366023820112156101f95761099290369060248160040135910161105e565b6001600160a01b037f0000000000000000000000003ceb9022e3df13de45a48b97914972bf036c191f16803014908115610bd9575b50610908576109d46113a1565b6001600160a01b038216916040517f52d1902d000000000000000000000000000000000000000000000000000000008152602081600481875afa60009181610ba5575b50610a315783634c9c8ce360e01b60005260045260246000fd5b807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc859203610b785750813b15610b64578073ffffffffffffffffffffffffffffffffffffffff197f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5416177f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2815115610b315760008083602061022795519101845af43d15610b29573d91610b0c83611042565b92610b1a6040519485611020565b83523d6000602085013e61145b565b60609161145b565b505034610b3a57005b7fb398979f0000000000000000000000000000000000000000000000000000000060005260046000fd5b634c9c8ce360e01b60005260045260246000fd5b7faa1d49a40000000000000000000000000000000000000000000000000000000060005260045260246000fd5b9091506020813d602011610bd1575b81610bc160209383611020565b810103126101f957519085610a17565b3d9150610bb4565b90506001600160a01b037f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54161415836109c7565b346101f95760403660031901126101f957610c27610f50565b50610c30610e31565b50610227611363565b346101f95760c03660031901126101f957610c52610f50565b50610c5b610f63565b50610c64610f76565b5060643567ffffffffffffffff81116101f957610c85903690600401610e73565b505060843567ffffffffffffffff81116101f957610ca7903690600401610e73565b5050610c30610e1b565b346101f957610cbf36610ea1565b505050610cca611363565b6040810135601e19823603018112156101f957810180359067ffffffffffffffff82116101f95760200181360381136101f957610d0891369161105e565b6000604051610d1681610fee565b526020818051810103126101f957602001518015158091036101f9577f79ee09378f342f8ca76fdc4df724919954622285ad2e3b271daee3823e397efc602060405192610d6284610fee565b808452604051908152a1633b9aca004202428104633b9aca001442151715610e055767ffffffffffffffff60005460c01c9116019067ffffffffffffffff8211610e0557516040519260209115610db885610fee565b8452013563ffffffff811681036101f957610dd2926110d2565b610489604051600160f81b602082015260018152610df1602182611020565b604051918291602083526020830190610f2b565b634e487b7160e01b600052601160045260246000fd5b60a435906001600160a01b03821682036101f957565b602435906001600160a01b03821682036101f957565b600435906001600160a01b03821682036101f957565b604435906001600160a01b03821682036101f957565b9181601f840112156101f95782359167ffffffffffffffff83116101f957602083818601950101116101f957565b60606003198201126101f95760043567ffffffffffffffff81116101f95760a081830360031901126101f957600401916024356001600160a01b03811681036101f957916044359067ffffffffffffffff82116101f957610f0491600401610e73565b9091565b60005b838110610f1b5750506000910152565b8181015183820152602001610f0b565b90602091610f4481518092818552858086019101610f08565b601f01601f1916010190565b6004359063ffffffff821682036101f957565b6024359063ffffffff821682036101f957565b6044359063ffffffff821682036101f957565b60806003198201126101f95760043563ffffffff811681036101f9579160243563ffffffff811681036101f957916044359067ffffffffffffffff82116101f957610fd691600401610e73565b90916064356001600160a01b03811681036101f95790565b6020810190811067ffffffffffffffff82111761100a57604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff82111761100a57604052565b67ffffffffffffffff811161100a57601f01601f191660200190565b92919261106a82611042565b916110786040519384611020565b8294818452818301116101f9578281602093846000960137010152565b6044359067ffffffffffffffff821682036101f957565b519063ffffffff821682036101f957565b519067ffffffffffffffff821682036101f957565b9167ffffffffffffffff9263ffffffff600080946111606001600160a01b038354169451151560405190602082015260208152611110604082611020565b604051988997889687957fe5cbff79000000000000000000000000000000000000000000000000000000008752166004860152856024860152166044840152608060648401526084830190610f2b565b03925af1801561126a576111715750565b3d806000833e6111818183611020565b8101906020818303126101f95780519067ffffffffffffffff82116101f957019060a0828203126101f9576040519160a0830183811067ffffffffffffffff82111761100a576040526111d3816110ac565b83526111e1602082016110ac565b6020840152604081015167ffffffffffffffff81116101f95781019082601f830112156101f95781519061121482611042565b936112226040519586611020565b828552602083850101116101f9578361124960809593611265956020808997019101610f08565b604086015261125a606082016110bd565b6060860152016110bd565b910152565b6040513d6000823e3d90fd5b908060209392818452848401376000828201840152601f01601f1916010190565b6001600160a01b03168015611334576001600160a01b037f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300548273ffffffffffffffffffffffffffffffffffffffff198216177f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b7f1e4fbdf700000000000000000000000000000000000000000000000000000000600052600060045260246000fd5b6001600160a01b0360005416330361137757565b7fe54f8f9d0000000000000000000000000000000000000000000000000000000060005260046000fd5b6001600160a01b037f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300541633036113d457565b7f118cdaa7000000000000000000000000000000000000000000000000000000006000523360045260246000fd5b60ff7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460401c161561143157565b7fd7e6bcf80000000000000000000000000000000000000000000000000000000060005260046000fd5b9061149a575080511561147057805190602001fd5b7f1425ea420000000000000000000000000000000000000000000000000000000060005260046000fd5b815115806114e2575b6114ab575090565b6001600160a01b03907f9996b315000000000000000000000000000000000000000000000000000000006000521660045260246000fd5b50803b156114a356fea26469706673582212202239515f734db7c18cc6a830d78b7e1c24562134b7ff1e4737ebb42db1bbfeea64736f6c634300081b0033
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.