Transactions
Token Transfers
Internal Transactions
Coin Balance History
Logs
Code
Read Contract
Write Contract
- Contract name:
- PKPHelper
- Optimization enabled
- false
- Compiler version
- v0.8.17+commit.8df45f5f
- Verified at
- 2023-04-27T22:51:36.221411Z
Constructor Arguments
0000000000000000000000008f75a53f65e31dd0d2e40d0827becaae2299d1110000000000000000000000004aed2f242e806c58758677059340e29e6b5b7619
Arg [0] (address) : 0x8f75a53f65e31dd0d2e40d0827becaae2299d111
Arg [1] (address) : 0x4aed2f242e806c58758677059340e29e6b5b7619
contracts/lit-node/PKPHelper.sol
//SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.17; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { PKPPermissions } from "./PKPPermissions.sol"; import { PKPNFT } from "./PKPNFT.sol"; import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol"; import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; // TODO: tests for the mintGrantAndBurn function, withdraw function, some of the setters, transfer function, freeMint and freeMintGrantAndBurn /// @title Programmable Keypair NFT /// /// @dev This is the contract for the PKP NFTs /// /// Simply put, whomever owns a PKP NFT can ask that PKP to sign a message. /// The owner can also grant signing permissions to other eth addresses /// or lit actions contract PKPHelper is Ownable, IERC721Receiver { /* ========== STATE VARIABLES ========== */ PKPNFT public pkpNFT; PKPPermissions public pkpPermissions; /* ========== CONSTRUCTOR ========== */ constructor(address _pkpNft, address _pkpPermissions) { pkpNFT = PKPNFT(_pkpNft); pkpPermissions = PKPPermissions(_pkpPermissions); } /* ========== VIEWS ========== */ /* ========== MUTATIVE FUNCTIONS ========== */ function mintNextAndAddAuthMethods( uint256 keyType, uint256[] memory permittedAuthMethodTypes, bytes[] memory permittedAuthMethodIds, bytes[] memory permittedAuthMethodPubkeys, uint256[][] memory permittedAuthMethodScopes, bool addPkpEthAddressAsPermittedAddress, bool sendPkpToItself ) public payable returns (uint256) { return mintNextAndAddAuthMethodsWithTypes( keyType, new bytes[](0), // permitted ipfs CIDs new uint256[][](0), // permitted ipfs CIDs scopes new address[](0), // permitted addresses new uint256[][](0), // permitted addresses scopes permittedAuthMethodTypes, permittedAuthMethodIds, permittedAuthMethodPubkeys, permittedAuthMethodScopes, addPkpEthAddressAsPermittedAddress, sendPkpToItself ); } function mintNextAndAddAuthMethodsWithTypes( uint256 keyType, bytes[] memory permittedIpfsCIDs, uint256[][] memory permittedIpfsCIDScopes, address[] memory permittedAddresses, uint256[][] memory permittedAddressScopes, uint256[] memory permittedAuthMethodTypes, bytes[] memory permittedAuthMethodIds, bytes[] memory permittedAuthMethodPubkeys, uint256[][] memory permittedAuthMethodScopes, bool addPkpEthAddressAsPermittedAddress, bool sendPkpToItself ) public payable returns (uint256) { // mint the nft and forward the funds uint256 tokenId = pkpNFT.mintNext{ value: msg.value }(keyType); // sanity checking array lengths require( permittedIpfsCIDs.length == permittedIpfsCIDScopes.length, "PKPHelper: ipfs cid and scope array lengths must match" ); require( permittedAddresses.length == permittedAddressScopes.length, "PKPHelper: address and scope array lengths must match" ); require( permittedAuthMethodTypes.length == permittedAuthMethodIds.length, "PKPHelper: auth method type and id array lengths must match" ); require( permittedAuthMethodTypes.length == permittedAuthMethodPubkeys.length, "PKPHelper: auth method type and pubkey array lengths must match" ); require( permittedAuthMethodTypes.length == permittedAuthMethodScopes.length, "PKPHelper: auth method type and scopes array lengths must match" ); // permit the action if (permittedIpfsCIDs.length != 0) { for (uint256 i = 0; i < permittedIpfsCIDs.length; i++) { pkpPermissions.addPermittedAction( tokenId, permittedIpfsCIDs[i], permittedIpfsCIDScopes[i] ); } } // permit the address if (permittedAddresses.length != 0) { for (uint256 i = 0; i < permittedAddresses.length; i++) { pkpPermissions.addPermittedAddress( tokenId, permittedAddresses[i], permittedAddressScopes[i] ); } } // permit the auth method if (permittedAuthMethodTypes.length != 0) { for (uint256 i = 0; i < permittedAuthMethodTypes.length; i++) { pkpPermissions.addPermittedAuthMethod( tokenId, PKPPermissions.AuthMethod( permittedAuthMethodTypes[i], permittedAuthMethodIds[i], permittedAuthMethodPubkeys[i] ), permittedAuthMethodScopes[i] ); } } address pkpEthAddress = pkpPermissions.getEthAddress(tokenId); // add the pkp eth address as a permitted address if (addPkpEthAddressAsPermittedAddress) { pkpPermissions.addPermittedAddress( tokenId, pkpEthAddress, new uint256[](0) ); } if (sendPkpToItself) { pkpNFT.safeTransferFrom(address(this), pkpEthAddress, tokenId); } else { pkpNFT.safeTransferFrom(address(this), msg.sender, tokenId); } return tokenId; } function setPkpNftAddress(address newPkpNftAddress) public onlyOwner { pkpNFT = PKPNFT(newPkpNftAddress); } function setPkpPermissionsAddress( address newPkpPermissionsAddress ) public onlyOwner { pkpPermissions = PKPPermissions(newPkpPermissionsAddress); } function onERC721Received( address /* operator */, address /* from */, uint256 /* tokenId */, bytes calldata /* data */ ) external view override returns (bytes4) { // only accept transfers from the pkpNft contract require( msg.sender == address(pkpNFT), "PKPHelper: only accepts transfers from the PKPNFT contract" ); return this.onERC721Received.selector; } }
@openzeppelin/contracts/token/ERC721/ERC721.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; import "./IERC721.sol"; import "./IERC721Receiver.sol"; import "./extensions/IERC721Metadata.sol"; import "../../utils/Address.sol"; import "../../utils/Context.sol"; import "../../utils/Strings.sol"; import "../../utils/introspection/ERC165.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: address zero is not a valid owner"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: invalid token ID"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { _requireMinted(tokenId); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overridden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not token owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { _requireMinted(tokenId); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner nor approved"); _safeTransfer(from, to, tokenId, data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { address owner = ERC721.ownerOf(tokenId); return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); _afterTokenTransfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); _afterTokenTransfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits an {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Reverts if the `tokenId` has not been minted yet. */ function _requireMinted(uint256 tokenId) internal view virtual { require(_exists(tokenId), "ERC721: invalid token ID"); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { /// @solidity memory-safe-assembly assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} }
hardhat/console.sol
// SPDX-License-Identifier: MIT pragma solidity >= 0.4.22 <0.9.0; library console { address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67); function _sendLogPayload(bytes memory payload) private view { uint256 payloadLength = payload.length; address consoleAddress = CONSOLE_ADDRESS; assembly { let payloadStart := add(payload, 32) let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0) } } function log() internal view { _sendLogPayload(abi.encodeWithSignature("log()")); } function logInt(int256 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(int256)", p0)); } function logUint(uint256 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256)", p0)); } function logString(string memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(string)", p0)); } function logBool(bool p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool)", p0)); } function logAddress(address p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(address)", p0)); } function logBytes(bytes memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes)", p0)); } function logBytes1(bytes1 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0)); } function logBytes2(bytes2 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0)); } function logBytes3(bytes3 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0)); } function logBytes4(bytes4 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0)); } function logBytes5(bytes5 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0)); } function logBytes6(bytes6 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0)); } function logBytes7(bytes7 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0)); } function logBytes8(bytes8 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0)); } function logBytes9(bytes9 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0)); } function logBytes10(bytes10 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0)); } function logBytes11(bytes11 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0)); } function logBytes12(bytes12 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0)); } function logBytes13(bytes13 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0)); } function logBytes14(bytes14 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0)); } function logBytes15(bytes15 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0)); } function logBytes16(bytes16 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0)); } function logBytes17(bytes17 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0)); } function logBytes18(bytes18 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0)); } function logBytes19(bytes19 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0)); } function logBytes20(bytes20 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0)); } function logBytes21(bytes21 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0)); } function logBytes22(bytes22 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0)); } function logBytes23(bytes23 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0)); } function logBytes24(bytes24 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0)); } function logBytes25(bytes25 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0)); } function logBytes26(bytes26 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0)); } function logBytes27(bytes27 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0)); } function logBytes28(bytes28 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0)); } function logBytes29(bytes29 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0)); } function logBytes30(bytes30 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0)); } function logBytes31(bytes31 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0)); } function logBytes32(bytes32 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0)); } function log(uint256 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256)", p0)); } function log(string memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(string)", p0)); } function log(bool p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool)", p0)); } function log(address p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(address)", p0)); } function log(uint256 p0, uint256 p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256)", p0, p1)); } function log(uint256 p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string)", p0, p1)); } function log(uint256 p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool)", p0, p1)); } function log(uint256 p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address)", p0, p1)); } function log(string memory p0, uint256 p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256)", p0, p1)); } function log(string memory p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1)); } function log(string memory p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1)); } function log(string memory p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1)); } function log(bool p0, uint256 p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256)", p0, p1)); } function log(bool p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1)); } function log(bool p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1)); } function log(bool p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1)); } function log(address p0, uint256 p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256)", p0, p1)); } function log(address p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1)); } function log(address p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1)); } function log(address p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1)); } function log(uint256 p0, uint256 p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256)", p0, p1, p2)); } function log(uint256 p0, uint256 p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string)", p0, p1, p2)); } function log(uint256 p0, uint256 p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool)", p0, p1, p2)); } function log(uint256 p0, uint256 p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address)", p0, p1, p2)); } function log(uint256 p0, string memory p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256)", p0, p1, p2)); } function log(uint256 p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,string)", p0, p1, p2)); } function log(uint256 p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool)", p0, p1, p2)); } function log(uint256 p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,address)", p0, p1, p2)); } function log(uint256 p0, bool p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256)", p0, p1, p2)); } function log(uint256 p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string)", p0, p1, p2)); } function log(uint256 p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool)", p0, p1, p2)); } function log(uint256 p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address)", p0, p1, p2)); } function log(uint256 p0, address p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256)", p0, p1, p2)); } function log(uint256 p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,string)", p0, p1, p2)); } function log(uint256 p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool)", p0, p1, p2)); } function log(uint256 p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,address)", p0, p1, p2)); } function log(string memory p0, uint256 p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256)", p0, p1, p2)); } function log(string memory p0, uint256 p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,string)", p0, p1, p2)); } function log(string memory p0, uint256 p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool)", p0, p1, p2)); } function log(string memory p0, uint256 p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,address)", p0, p1, p2)); } function log(string memory p0, string memory p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint256)", p0, p1, p2)); } function log(string memory p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2)); } function log(string memory p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2)); } function log(string memory p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2)); } function log(string memory p0, bool p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256)", p0, p1, p2)); } function log(string memory p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2)); } function log(string memory p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2)); } function log(string memory p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2)); } function log(string memory p0, address p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint256)", p0, p1, p2)); } function log(string memory p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2)); } function log(string memory p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2)); } function log(string memory p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2)); } function log(bool p0, uint256 p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256)", p0, p1, p2)); } function log(bool p0, uint256 p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string)", p0, p1, p2)); } function log(bool p0, uint256 p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool)", p0, p1, p2)); } function log(bool p0, uint256 p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address)", p0, p1, p2)); } function log(bool p0, string memory p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256)", p0, p1, p2)); } function log(bool p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2)); } function log(bool p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2)); } function log(bool p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2)); } function log(bool p0, bool p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256)", p0, p1, p2)); } function log(bool p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2)); } function log(bool p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2)); } function log(bool p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2)); } function log(bool p0, address p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256)", p0, p1, p2)); } function log(bool p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2)); } function log(bool p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2)); } function log(bool p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2)); } function log(address p0, uint256 p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256)", p0, p1, p2)); } function log(address p0, uint256 p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,string)", p0, p1, p2)); } function log(address p0, uint256 p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool)", p0, p1, p2)); } function log(address p0, uint256 p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,address)", p0, p1, p2)); } function log(address p0, string memory p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint256)", p0, p1, p2)); } function log(address p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2)); } function log(address p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2)); } function log(address p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2)); } function log(address p0, bool p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256)", p0, p1, p2)); } function log(address p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2)); } function log(address p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2)); } function log(address p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2)); } function log(address p0, address p1, uint256 p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint256)", p0, p1, p2)); } function log(address p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2)); } function log(address p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2)); } function log(address p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2)); } function log(uint256 p0, uint256 p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,string)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,bool)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,address)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,string)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,bool)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,address)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,string)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,bool)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,address)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,string)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,bool)", p0, p1, p2, p3)); } function log(uint256 p0, uint256 p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,address)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,string)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,bool)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,address)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,string)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,bool)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,address)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,string)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,bool)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,address)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,string)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,bool)", p0, p1, p2, p3)); } function log(uint256 p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,address)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,string)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,bool)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,address)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,string)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,bool)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,address)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,string)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,bool)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,address)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,string)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,bool)", p0, p1, p2, p3)); } function log(uint256 p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,address)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,string)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,bool)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,address)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,string)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,bool)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,address)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,string)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,bool)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,address)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,uint256)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,string)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,bool)", p0, p1, p2, p3)); } function log(uint256 p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,address)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,uint256)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,string)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,address)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,uint256)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,string)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,address)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,uint256)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,uint256)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,string)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint256 p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,uint256)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint256)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint256)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint256)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,uint256)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint256)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint256)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint256)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,uint256)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint256)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint256)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint256)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,uint256)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,string)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,bool)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,address)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,uint256)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,string)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,bool)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,address)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,uint256)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,string)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,address)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,uint256)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,string)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,bool)", p0, p1, p2, p3)); } function log(bool p0, uint256 p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,uint256)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint256)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint256)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint256)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,uint256)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint256)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint256)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint256)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,uint256)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint256)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint256)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint256)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,uint256)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,string)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,bool)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,address)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,uint256)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,string)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,bool)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,address)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,uint256)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,string)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,bool)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,address)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,uint256)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,string)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,bool)", p0, p1, p2, p3)); } function log(address p0, uint256 p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,uint256)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint256)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint256)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint256)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,uint256)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint256)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint256)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint256)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3)); } function log(address p0, address p1, uint256 p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,uint256)", p0, p1, p2, p3)); } function log(address p0, address p1, uint256 p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,string)", p0, p1, p2, p3)); } function log(address p0, address p1, uint256 p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, uint256 p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,address)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint256)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint256)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, uint256 p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint256)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3)); } }
@openzeppelin/contracts/utils/Strings.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @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; } }
solidity-bytes-utils/contracts/BytesLib.sol
// SPDX-License-Identifier: Unlicense /* * @title Solidity Bytes Arrays Utils * @author Gonçalo Sá <goncalo.sa@consensys.net> * * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity. * The library lets you concatenate, slice and type cast bytes arrays both in memory and storage. */ pragma solidity >=0.8.0 <0.9.0; library BytesLib { function concat( bytes memory _preBytes, bytes memory _postBytes ) internal pure returns (bytes memory) { bytes memory tempBytes; assembly { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // Store the length of the first bytes array at the beginning of // the memory for tempBytes. let length := mload(_preBytes) mstore(tempBytes, length) // Maintain a memory counter for the current write location in the // temp bytes array by adding the 32 bytes for the array length to // the starting location. let mc := add(tempBytes, 0x20) // Stop copying when the memory counter reaches the length of the // first bytes array. let end := add(mc, length) for { // Initialize a copy counter to the start of the _preBytes data, // 32 bytes into its memory. let cc := add(_preBytes, 0x20) } lt(mc, end) { // Increase both counters by 32 bytes each iteration. mc := add(mc, 0x20) cc := add(cc, 0x20) } { // Write the _preBytes data into the tempBytes memory 32 bytes // at a time. mstore(mc, mload(cc)) } // Add the length of _postBytes to the current length of tempBytes // and store it as the new length in the first 32 bytes of the // tempBytes memory. length := mload(_postBytes) mstore(tempBytes, add(length, mload(tempBytes))) // Move the memory counter back from a multiple of 0x20 to the // actual end of the _preBytes data. mc := end // Stop copying when the memory counter reaches the new combined // length of the arrays. end := add(mc, length) for { let cc := add(_postBytes, 0x20) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } // Update the free-memory pointer by padding our last write location // to 32 bytes: add 31 bytes to the end of tempBytes to move to the // next 32 byte block, then round down to the nearest multiple of // 32. If the sum of the length of the two arrays is zero then add // one before rounding down to leave a blank 32 bytes (the length block with 0). mstore(0x40, and( add(add(end, iszero(add(length, mload(_preBytes)))), 31), not(31) // Round down to the nearest 32 bytes. )) } return tempBytes; } function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal { assembly { // Read the first 32 bytes of _preBytes storage, which is the length // of the array. (We don't need to use the offset into the slot // because arrays use the entire slot.) let fslot := sload(_preBytes.slot) // Arrays of 31 bytes or less have an even value in their slot, // while longer arrays have an odd value. The actual length is // the slot divided by two for odd values, and the lowest order // byte divided by two for even values. // If the slot is even, bitwise and the slot with 255 and divide by // two to get the length. If the slot is odd, bitwise and the slot // with -1 and divide by two. let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2) let mlength := mload(_postBytes) let newlength := add(slength, mlength) // slength can contain both the length and contents of the array // if length < 32 bytes so let's prepare for that // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage switch add(lt(slength, 32), lt(newlength, 32)) case 2 { // Since the new array still fits in the slot, we just need to // update the contents of the slot. // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length sstore( _preBytes.slot, // all the modifications to the slot are inside this // next block add( // we can just add to the slot contents because the // bytes we want to change are the LSBs fslot, add( mul( div( // load the bytes from memory mload(add(_postBytes, 0x20)), // zero all bytes to the right exp(0x100, sub(32, mlength)) ), // and now shift left the number of bytes to // leave space for the length in the slot exp(0x100, sub(32, newlength)) ), // increase length by the double of the memory // bytes length mul(mlength, 2) ) ) ) } case 1 { // The stored value fits in the slot, but the combined value // will exceed it. // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) let sc := add(keccak256(0x0, 0x20), div(slength, 32)) // save new length sstore(_preBytes.slot, add(mul(newlength, 2), 1)) // The contents of the _postBytes array start 32 bytes into // the structure. Our first read should obtain the `submod` // bytes that can fit into the unused space in the last word // of the stored array. To get this, we read 32 bytes starting // from `submod`, so the data we read overlaps with the array // contents by `submod` bytes. Masking the lowest-order // `submod` bytes allows us to add that value directly to the // stored value. let submod := sub(32, slength) let mc := add(_postBytes, submod) let end := add(_postBytes, mlength) let mask := sub(exp(0x100, submod), 1) sstore( sc, add( and( fslot, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00 ), and(mload(mc), mask) ) ) for { mc := add(mc, 0x20) sc := add(sc, 1) } lt(mc, end) { sc := add(sc, 1) mc := add(mc, 0x20) } { sstore(sc, mload(mc)) } mask := exp(0x100, sub(mc, end)) sstore(sc, mul(div(mload(mc), mask), mask)) } default { // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) // Start copying to the last used word of the stored array. let sc := add(keccak256(0x0, 0x20), div(slength, 32)) // save new length sstore(_preBytes.slot, add(mul(newlength, 2), 1)) // Copy over the first `submod` bytes of the new data as in // case 1 above. let slengthmod := mod(slength, 32) let mlengthmod := mod(mlength, 32) let submod := sub(32, slengthmod) let mc := add(_postBytes, submod) let end := add(_postBytes, mlength) let mask := sub(exp(0x100, submod), 1) sstore(sc, add(sload(sc), and(mload(mc), mask))) for { sc := add(sc, 1) mc := add(mc, 0x20) } lt(mc, end) { sc := add(sc, 1) mc := add(mc, 0x20) } { sstore(sc, mload(mc)) } mask := exp(0x100, sub(mc, end)) sstore(sc, mul(div(mload(mc), mask), mask)) } } } function slice( bytes memory _bytes, uint256 _start, uint256 _length ) internal pure returns (bytes memory) { require(_length + 31 >= _length, "slice_overflow"); require(_bytes.length >= _start + _length, "slice_outOfBounds"); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) //zero out the 32 bytes slice we are about to return //we need to do it because Solidity does not garbage collect mstore(tempBytes, 0) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) { require(_bytes.length >= _start + 20, "toAddress_outOfBounds"); address tempAddress; assembly { tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000) } return tempAddress; } function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) { require(_bytes.length >= _start + 1 , "toUint8_outOfBounds"); uint8 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x1), _start)) } return tempUint; } function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) { require(_bytes.length >= _start + 2, "toUint16_outOfBounds"); uint16 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x2), _start)) } return tempUint; } function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) { require(_bytes.length >= _start + 4, "toUint32_outOfBounds"); uint32 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x4), _start)) } return tempUint; } function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) { require(_bytes.length >= _start + 8, "toUint64_outOfBounds"); uint64 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x8), _start)) } return tempUint; } function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) { require(_bytes.length >= _start + 12, "toUint96_outOfBounds"); uint96 tempUint; assembly { tempUint := mload(add(add(_bytes, 0xc), _start)) } return tempUint; } function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) { require(_bytes.length >= _start + 16, "toUint128_outOfBounds"); uint128 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x10), _start)) } return tempUint; } function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) { require(_bytes.length >= _start + 32, "toUint256_outOfBounds"); uint256 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x20), _start)) } return tempUint; } function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) { require(_bytes.length >= _start + 32, "toBytes32_outOfBounds"); bytes32 tempBytes32; assembly { tempBytes32 := mload(add(add(_bytes, 0x20), _start)) } return tempBytes32; } function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) { bool success = true; assembly { let length := mload(_preBytes) // if lengths don't match the arrays are not equal switch eq(length, mload(_postBytes)) case 1 { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 let mc := add(_preBytes, 0x20) let end := add(mc, length) for { let cc := add(_postBytes, 0x20) // the next line is the loop condition: // while(uint256(mc < end) + cb == 2) } eq(add(lt(mc, end), cb), 2) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { // if any of these checks fails then arrays are not equal if iszero(eq(mload(mc), mload(cc))) { // unsuccess: success := 0 cb := 0 } } } default { // unsuccess: success := 0 } } return success; } function equalStorage( bytes storage _preBytes, bytes memory _postBytes ) internal view returns (bool) { bool success = true; assembly { // we know _preBytes_offset is 0 let fslot := sload(_preBytes.slot) // Decode the length of the stored array like in concatStorage(). let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2) let mlength := mload(_postBytes) // if lengths don't match the arrays are not equal switch eq(slength, mlength) case 1 { // slength can contain both the length and contents of the array // if length < 32 bytes so let's prepare for that // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage if iszero(iszero(slength)) { switch lt(slength, 32) case 1 { // blank the last byte which is the length fslot := mul(div(fslot, 0x100), 0x100) if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) { // unsuccess: success := 0 } } default { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) let sc := keccak256(0x0, 0x20) let mc := add(_postBytes, 0x20) let end := add(mc, mlength) // the next line is the loop condition: // while(uint256(mc < end) + cb == 2) for {} eq(add(lt(mc, end), cb), 2) { sc := add(sc, 1) mc := add(mc, 0x20) } { if iszero(eq(sload(sc), mload(mc))) { // unsuccess: success := 0 cb := 0 } } } } } default { // unsuccess: success := 0 } } return success; } }
@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); }
contracts/lit-node/PKPPermissions.sol
//SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.17; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { BitMaps } from "@openzeppelin/contracts/utils/structs/BitMaps.sol"; import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; import { PKPNFT } from "./PKPNFT.sol"; import "solidity-bytes-utils/contracts/BytesLib.sol"; import "hardhat/console.sol"; contract PKPPermissions is Ownable { using EnumerableSet for EnumerableSet.AddressSet; using EnumerableSet for EnumerableSet.Bytes32Set; using EnumerableSet for EnumerableSet.UintSet; using BytesLib for bytes; using BitMaps for BitMaps.BitMap; /* ========== STATE VARIABLES ========== */ PKPNFT public pkpNFT; enum AuthMethodType { NULLMETHOD, // 0 ADDRESS, // 1 ACTION, // 2 WEBAUTHN, // 3 DISCORD, // 4 GOOGLE, // 5 GOOGLE_JWT // 6 } struct AuthMethod { uint256 authMethodType; // 1 = address, 2 = action, 3 = WebAuthn, 4 = Discord, 5 = Google, 6 = Google JWT. Not doing this in an enum so that we can add more auth methods in the future without redeploying. bytes id; // the id of the auth method. For address, this is an eth address. For action, this is an IPFS CID. For WebAuthn, this is the credentialId. For Discord, this is the user's Discord ID. For Google, this is the user's Google ID. bytes userPubkey; // the user's pubkey. This is used for WebAuthn. } // map the keccack256(uncompressed pubkey) -> set of auth methods mapping(uint256 => EnumerableSet.UintSet) permittedAuthMethods; // map the keccack256(uncompressed pubkey) -> auth_method_id -> scope id mapping(uint256 => mapping(uint256 => BitMaps.BitMap)) permittedAuthMethodScopes; // map the keccack256(authMethodType, userId) -> the actual AuthMethod struct mapping(uint256 => AuthMethod) public authMethods; // map the AuthMethod hash to the pubkeys that it's allowed to sign for // this makes it possible to be given a discord id and then lookup all the pubkeys that are allowed to sign for that discord id mapping(uint256 => EnumerableSet.UintSet) authMethodToPkpIds; // map the keccack256(uncompressed pubkey) -> (group => merkle tree root hash) mapping(uint256 => mapping(uint256 => bytes32)) private _rootHashes; /* ========== CONSTRUCTOR ========== */ constructor(address _pkpNft) { pkpNFT = PKPNFT(_pkpNft); } /* ========== Modifier ========== */ modifier onlyPKPOwner(uint256 tokenId) { // check that user is allowed to set this address nftOwner = pkpNFT.ownerOf(tokenId); require(msg.sender == nftOwner, "Not PKP NFT owner"); _; } /* ========== VIEWS ========== */ /// get the eth address for the keypair, as long as it's an ecdsa keypair function getEthAddress(uint256 tokenId) public view returns (address) { return pkpNFT.getEthAddress(tokenId); } /// includes the 0x04 prefix so you can pass this directly to ethers.utils.computeAddress function getPubkey(uint256 tokenId) public view returns (bytes memory) { return pkpNFT.getPubkey(tokenId); } function getAuthMethodId( uint256 authMethodType, bytes memory id ) public pure returns (uint256) { return uint256(keccak256(abi.encode(authMethodType, id))); } /// get the user's pubkey given their authMethodType and userId function getUserPubkeyForAuthMethod( uint256 authMethodType, bytes calldata id ) external view returns (bytes memory) { uint256 authMethodId = getAuthMethodId(authMethodType, id); AuthMethod memory am = authMethods[authMethodId]; return am.userPubkey; } function getTokenIdsForAuthMethod( uint256 authMethodType, bytes calldata id ) external view returns (uint256[] memory) { uint256 authMethodId = getAuthMethodId(authMethodType, id); uint256 pkpIdsLength = authMethodToPkpIds[authMethodId].length(); uint256[] memory allPkpIds = new uint256[](pkpIdsLength); for (uint256 i = 0; i < pkpIdsLength; i++) { allPkpIds[i] = authMethodToPkpIds[authMethodId].at(i); } return allPkpIds; } function getPermittedAuthMethods( uint256 tokenId ) external view returns (AuthMethod[] memory) { uint256 permittedAuthMethodsLength = permittedAuthMethods[tokenId] .length(); AuthMethod[] memory allPermittedAuthMethods = new AuthMethod[]( permittedAuthMethodsLength ); for (uint256 i = 0; i < permittedAuthMethodsLength; i++) { uint256 authMethodHash = permittedAuthMethods[tokenId].at(i); allPermittedAuthMethods[i] = authMethods[authMethodHash]; } return allPermittedAuthMethods; } function getPermittedAuthMethodScopes( uint256 tokenId, uint256 authMethodType, bytes calldata id, uint256 maxScopeId ) public view returns (bool[] memory) { uint256 authMethodId = getAuthMethodId(authMethodType, id); BitMaps.BitMap storage permittedScopesBitMap = permittedAuthMethodScopes[tokenId][ authMethodId ]; bool[] memory allScopes = new bool[](maxScopeId); for (uint256 i = 0; i < maxScopeId; i++) { allScopes[i] = permittedScopesBitMap.get(i); } return allScopes; } function getPermittedActions( uint256 tokenId ) public view returns (bytes[] memory) { uint256 permittedAuthMethodsLength = permittedAuthMethods[tokenId] .length(); // count the number of auth methods that are actions uint256 permittedActionsLength = 0; for (uint256 i = 0; i < permittedAuthMethodsLength; i++) { uint256 authMethodHash = permittedAuthMethods[tokenId].at(i); AuthMethod memory am = authMethods[authMethodHash]; if (am.authMethodType == uint256(AuthMethodType.ACTION)) { permittedActionsLength++; } } bytes[] memory allPermittedActions = new bytes[]( permittedActionsLength ); uint256 permittedActionsIndex = 0; for (uint256 i = 0; i < permittedAuthMethodsLength; i++) { uint256 authMethodHash = permittedAuthMethods[tokenId].at(i); AuthMethod memory am = authMethods[authMethodHash]; if (am.authMethodType == uint256(AuthMethodType.ACTION)) { allPermittedActions[permittedActionsIndex] = am.id; permittedActionsIndex++; } } return allPermittedActions; } function getPermittedAddresses( uint256 tokenId ) public view returns (address[] memory) { uint256 permittedAuthMethodsLength = permittedAuthMethods[tokenId] .length(); // count the number of auth methods that are addresses uint256 permittedAddressLength = 0; for (uint256 i = 0; i < permittedAuthMethodsLength; i++) { uint256 authMethodHash = permittedAuthMethods[tokenId].at(i); AuthMethod memory am = authMethods[authMethodHash]; if (am.authMethodType == uint256(AuthMethodType.ADDRESS)) { permittedAddressLength++; } } bool tokenExists = pkpNFT.exists(tokenId); address[] memory allPermittedAddresses; uint256 permittedAddressIndex = 0; if (tokenExists) { // token is not burned, so add the owner address allPermittedAddresses = new address[](permittedAddressLength + 1); // always add nft owner in first slot address nftOwner = pkpNFT.ownerOf(tokenId); allPermittedAddresses[0] = nftOwner; permittedAddressIndex++; } else { // token is burned, so don't add the owner address allPermittedAddresses = new address[](permittedAddressLength); } for (uint256 i = 0; i < permittedAuthMethodsLength; i++) { uint256 authMethodHash = permittedAuthMethods[tokenId].at(i); AuthMethod memory am = authMethods[authMethodHash]; if (am.authMethodType == uint256(AuthMethodType.ADDRESS)) { address parsed; bytes memory id = am.id; // address was packed using abi.encodedPacked(address), so you need to pad left to get the correct bytes back assembly { parsed := div( mload(add(id, 32)), 0x1000000000000000000000000 ) } allPermittedAddresses[permittedAddressIndex] = parsed; permittedAddressIndex++; } } return allPermittedAddresses; } /// get if a user is permitted to use a given pubkey. returns true if it is permitted to use the pubkey in the permittedAuthMethods[tokenId] struct. function isPermittedAuthMethod( uint256 tokenId, uint256 authMethodType, bytes memory id ) public view returns (bool) { uint256 authMethodId = getAuthMethodId(authMethodType, id); bool permitted = permittedAuthMethods[tokenId].contains(authMethodId); if (!permitted) { return false; } return true; } function isPermittedAuthMethodScopePresent( uint256 tokenId, uint256 authMethodType, bytes calldata id, uint256 scopeId ) public view returns (bool) { uint256 authMethodId = getAuthMethodId(authMethodType, id); bool present = permittedAuthMethodScopes[tokenId][authMethodId].get( scopeId ); return present; } function isPermittedAction( uint256 tokenId, bytes calldata ipfsCID ) public view returns (bool) { return isPermittedAuthMethod( tokenId, uint256(AuthMethodType.ACTION), ipfsCID ); } function isPermittedAddress( uint256 tokenId, address user ) public view returns (bool) { return isPermittedAuthMethod( tokenId, uint256(AuthMethodType.ADDRESS), abi.encodePacked(user) ) || pkpNFT.ownerOf(tokenId) == user; } /* ========== MUTATIVE FUNCTIONS ========== */ /// Add a permitted auth method for a given pubkey function addPermittedAuthMethod( uint256 tokenId, AuthMethod memory authMethod, uint256[] calldata scopes ) public onlyPKPOwner(tokenId) { uint256 authMethodId = getAuthMethodId( authMethod.authMethodType, authMethod.id ); // we need to ensure that someone with the same auth method type and id can't add a different pubkey require( authMethods[authMethodId].userPubkey.length == 0 || keccak256(authMethods[authMethodId].userPubkey) == keccak256(authMethod.userPubkey), "Cannot add a different pubkey for the same auth method type and id" ); authMethods[authMethodId] = authMethod; EnumerableSet.UintSet storage newPermittedAuthMethods = permittedAuthMethods[tokenId]; newPermittedAuthMethods.add(authMethodId); EnumerableSet.UintSet storage newPkpIds = authMethodToPkpIds[ authMethodId ]; newPkpIds.add(tokenId); for (uint256 i = 0; i < scopes.length; i++) { uint256 scopeId = scopes[i]; permittedAuthMethodScopes[tokenId][authMethodId].set(scopeId); emit PermittedAuthMethodScopeAdded( tokenId, authMethodId, authMethod.id, scopeId ); } emit PermittedAuthMethodAdded( tokenId, authMethod.authMethodType, authMethod.id, authMethod.userPubkey ); } // Remove a permitted auth method for a given pubkey function removePermittedAuthMethod( uint256 tokenId, uint256 authMethodType, bytes memory id ) public onlyPKPOwner(tokenId) { uint256 authMethodId = getAuthMethodId(authMethodType, id); EnumerableSet.UintSet storage newPermittedAuthMethods = permittedAuthMethods[tokenId]; newPermittedAuthMethods.remove(authMethodId); EnumerableSet.UintSet storage newPkpIds = authMethodToPkpIds[ authMethodId ]; newPkpIds.remove(tokenId); emit PermittedAuthMethodRemoved(tokenId, authMethodId, id); } function addPermittedAuthMethodScope( uint256 tokenId, uint256 authMethodType, bytes calldata id, uint256 scopeId ) public onlyPKPOwner(tokenId) { uint256 authMethodId = getAuthMethodId(authMethodType, id); permittedAuthMethodScopes[tokenId][authMethodId].set(scopeId); emit PermittedAuthMethodScopeAdded(tokenId, authMethodId, id, scopeId); } function removePermittedAuthMethodScope( uint256 tokenId, uint256 authMethodType, bytes calldata id, uint256 scopeId ) public onlyPKPOwner(tokenId) { uint256 authMethodId = getAuthMethodId(authMethodType, id); permittedAuthMethodScopes[tokenId][authMethodId].unset(scopeId); emit PermittedAuthMethodScopeRemoved( tokenId, authMethodType, id, scopeId ); } /// Add a permitted action for a given pubkey function addPermittedAction( uint256 tokenId, bytes calldata ipfsCID, uint256[] calldata scopes ) public { addPermittedAuthMethod( tokenId, AuthMethod(uint256(AuthMethodType.ACTION), ipfsCID, ""), scopes ); } function removePermittedAction( uint256 tokenId, bytes calldata ipfsCID ) public { removePermittedAuthMethod( tokenId, uint256(AuthMethodType.ACTION), ipfsCID ); } function addPermittedAddress( uint256 tokenId, address user, uint256[] calldata scopes ) public { addPermittedAuthMethod( tokenId, AuthMethod( uint256(AuthMethodType.ADDRESS), abi.encodePacked(user), "" ), scopes ); } function removePermittedAddress(uint256 tokenId, address user) public { removePermittedAuthMethod( tokenId, uint256(AuthMethodType.ADDRESS), abi.encodePacked(user) ); } function setPkpNftAddress(address newPkpNftAddress) public onlyOwner { pkpNFT = PKPNFT(newPkpNftAddress); } /** * Update the root hash of the merkle tree representing off-chain states for the PKP */ function setRootHash( uint256 tokenId, uint256 group, bytes32 root ) public onlyPKPOwner(tokenId) { _rootHashes[tokenId][group] = root; emit RootHashUpdated(tokenId, group, root); } /** * Verify the given leaf existing in the merkle tree */ function verifyState( uint256 tokenId, uint256 group, bytes32[] memory proof, bytes32 leaf ) public view returns (bool) { bytes32 root = _rootHashes[tokenId][group]; if (root == bytes32(0)) return false; return MerkleProof.verify(proof, root, leaf); } /** * Verify the given leaves existing in the merkle tree */ function verifyStates( uint256 tokenId, uint256 group, bytes32[] memory proof, bool[] memory proofFlags, bytes32[] memory leaves ) public view returns (bool) { bytes32 root = _rootHashes[tokenId][group]; if (root == bytes32(0)) return false; return MerkleProof.multiProofVerify(proof, proofFlags, root, leaves); } /* ========== EVENTS ========== */ event PermittedAuthMethodAdded( uint256 indexed tokenId, uint256 authMethodType, bytes id, bytes userPubkey ); event PermittedAuthMethodRemoved( uint256 indexed tokenId, uint256 authMethodType, bytes id ); event PermittedAuthMethodScopeAdded( uint256 indexed tokenId, uint256 authMethodType, bytes id, uint256 scopeId ); event PermittedAuthMethodScopeRemoved( uint256 indexed tokenId, uint256 authMethodType, bytes id, uint256 scopeId ); event RootHashUpdated( uint256 indexed tokenId, uint256 indexed group, bytes32 root ); }
@openzeppelin/contracts/access/AccessControl.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(uint160(account), 20), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } }
@openzeppelin/contracts/utils/cryptography/ECDSA.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.3) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } else if (error == RecoverError.InvalidSignatureV) { revert("ECDSA: invalid signature 'v' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } if (v != 27 && v != 28) { return (address(0), RecoverError.InvalidSignatureV); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } }
@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); }
@openzeppelin/contracts/token/ERC721/IERC721.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); }
@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); }
@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol) pragma solidity ^0.8.0; import "../ERC20.sol"; import "../../../utils/Context.sol"; /** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */ abstract contract ERC20Burnable is Context, ERC20 { /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public virtual { _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for ``accounts``'s tokens of at least * `amount`. */ function burnFrom(address account, uint256 amount) public virtual { _spendAllowance(account, _msgSender(), amount); _burn(account, amount); } }
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
contracts/lit-node/PKPNFT.sol
//SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.17; import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import { PubkeyRouter } from "./PubkeyRouter.sol"; import { PKPPermissions } from "./PKPPermissions.sol"; import { PKPNFTMetadata } from "./PKPNFTMetadata.sol"; import { ERC721Burnable } from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; import { ERC721Enumerable } from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; import { IERC721Enumerable } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol"; import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol"; import "hardhat/console.sol"; // TODO: tests for the mintGrantAndBurn function, withdraw function, some of the setters, transfer function, freeMint and freeMintGrantAndBurn /// @title Programmable Keypair NFT /// /// @dev This is the contract for the PKP NFTs /// /// Simply put, whomever owns a PKP NFT can ask that PKP to sign a message. /// The owner can also grant signing permissions to other eth addresses /// or lit actions contract PKPNFT is ERC721("Programmable Keypair", "PKP"), Ownable, ERC721Burnable, ERC721Enumerable, ReentrancyGuard { /* ========== STATE VARIABLES ========== */ PubkeyRouter public router; PKPPermissions public pkpPermissions; PKPNFTMetadata public pkpNftMetadata; uint256 public mintCost; address public freeMintSigner; // maps keytype to array of unminted routed token ids mapping(uint256 => uint256[]) public unmintedRoutedTokenIds; mapping(uint256 => bool) public redeemedFreeMintIds; /* ========== CONSTRUCTOR ========== */ constructor() { mintCost = 1; // 1 wei aka 0.000000000000000001 eth freeMintSigner = msg.sender; } /* ========== VIEWS ========== */ /// get the eth address for the keypair, as long as it's an ecdsa keypair function getEthAddress(uint256 tokenId) public view returns (address) { return router.getEthAddress(tokenId); } /// includes the 0x04 prefix so you can pass this directly to ethers.utils.computeAddress function getPubkey(uint256 tokenId) public view returns (bytes memory) { return router.getPubkey(tokenId); } /// throws if the sig is bad or msg doesn't match function freeMintSigTest( uint256 freeMintId, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s ) public view { bytes32 expectedHash = prefixed( keccak256(abi.encodePacked(address(this), freeMintId)) ); require( expectedHash == msgHash, "The msgHash is not a hash of the tokenId. Explain yourself!" ); // make sure it was actually signed by freeMintSigner address recovered = ecrecover(msgHash, v, r, s); require( recovered == freeMintSigner, "This freeMint was not signed by freeMintSigner. How embarassing." ); // prevent reuse require( redeemedFreeMintIds[freeMintId] == false, "This free mint ID has already been redeemed" ); } function supportsInterface( bytes4 interfaceId ) public view virtual override(ERC721, ERC721Enumerable) returns (bool) { return interfaceId == type(IERC721Enumerable).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || interfaceId == type(IERC721).interfaceId; } function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override(ERC721, ERC721Enumerable) { ERC721Enumerable._beforeTokenTransfer(from, to, tokenId); } function tokenURI( uint256 tokenId ) public view override returns (string memory) { console.log("getting token uri"); bytes memory pubKey = router.getPubkey(tokenId); console.log("got pubkey, getting eth address"); address ethAddress = router.getEthAddress(tokenId); console.log("calling tokenURI"); return pkpNftMetadata.tokenURI(tokenId, pubKey, ethAddress); } function getUnmintedRoutedTokenIdCount( uint256 keyType ) public view returns (uint256) { return unmintedRoutedTokenIds[keyType].length; } // Builds a prefixed hash to mimic the behavior of eth_sign. function prefixed(bytes32 hash) public pure returns (bytes32) { return keccak256( abi.encodePacked("\x19Ethereum Signed Message:\n32", hash) ); } function exists(uint256 tokenId) public view returns (bool) { return _exists(tokenId); } /* ========== MUTATIVE FUNCTIONS ========== */ function mintNext(uint256 keyType) public payable returns (uint256) { require(msg.value == mintCost, "You must pay exactly mint cost"); uint256 tokenId = _getNextTokenIdToMint(keyType); _mintWithoutValueCheck(tokenId, msg.sender); return tokenId; } function mintGrantAndBurnNext( uint256 keyType, bytes memory ipfsCID ) public payable returns (uint256) { require(msg.value == mintCost, "You must pay exactly mint cost"); uint256 tokenId = _getNextTokenIdToMint(keyType); _mintWithoutValueCheck(tokenId, address(this)); pkpPermissions.addPermittedAction(tokenId, ipfsCID, new uint256[](0)); _burn(tokenId); return tokenId; } function freeMintNext( uint256 keyType, uint256 freeMintId, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s ) public returns (uint256) { uint256 tokenId = _getNextTokenIdToMint(keyType); freeMint(freeMintId, tokenId, msgHash, v, r, s); return tokenId; } function freeMintGrantAndBurnNext( uint256 keyType, uint256 freeMintId, bytes memory ipfsCID, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s ) public returns (uint256) { uint256 tokenId = _getNextTokenIdToMint(keyType); freeMintGrantAndBurn(freeMintId, tokenId, ipfsCID, msgHash, v, r, s); return tokenId; } /// create a valid token for a given public key. function mintSpecific(uint256 tokenId) public onlyOwner { _mintWithoutValueCheck(tokenId, msg.sender); } /// mint a PKP, grant access to a Lit Action, and then burn the PKP /// this happens in a single txn, so it's provable that only that lit action /// has ever had access to use the PKP. /// this is useful in the context of something like a "prime number certification lit action" /// where you could just trust the sig that a number is prime. /// without this function, a user could mint a PKP, sign a bunch of junk, and then burn the /// PKP to make it looks like only the Lit Action can use it. function mintGrantAndBurnSpecific( uint256 tokenId, bytes memory ipfsCID ) public onlyOwner { _mintWithoutValueCheck(tokenId, address(this)); pkpPermissions.addPermittedAction(tokenId, ipfsCID, new uint256[](0)); _burn(tokenId); } function freeMint( uint256 freeMintId, uint256 tokenId, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s ) internal { // this will panic if the sig is bad freeMintSigTest(freeMintId, msgHash, v, r, s); _mintWithoutValueCheck(tokenId, msg.sender); redeemedFreeMintIds[freeMintId] = true; } function freeMintGrantAndBurn( uint256 freeMintId, uint256 tokenId, bytes memory ipfsCID, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s ) internal { // this will panic if the sig is bad freeMintSigTest(freeMintId, msgHash, v, r, s); _mintWithoutValueCheck(tokenId, address(this)); redeemedFreeMintIds[freeMintId] = true; pkpPermissions.addPermittedAction(tokenId, ipfsCID, new uint256[](0)); _burn(tokenId); } function _mintWithoutValueCheck(uint256 tokenId, address to) internal { require(router.isRouted(tokenId), "This PKP has not been routed yet"); if (to == address(this)) { // permit unsafe transfer only to this contract, because it's going to be burned _mint(to, tokenId); } else { _safeMint(to, tokenId); } emit PKPMinted(tokenId, getPubkey(tokenId)); } /// Take a tokenId off the stack function _getNextTokenIdToMint(uint256 keyType) internal returns (uint256) { require( unmintedRoutedTokenIds[keyType].length > 0, "There are no unminted routed token ids to mint" ); uint256 tokenId = unmintedRoutedTokenIds[keyType][ unmintedRoutedTokenIds[keyType].length - 1 ]; unmintedRoutedTokenIds[keyType].pop(); return tokenId; } function setRouterAddress(address routerAddress) public onlyOwner { router = PubkeyRouter(routerAddress); emit RouterAddressSet(routerAddress); } function setPkpNftMetadataAddress( address pkpNftMetadataAddress ) public onlyOwner { pkpNftMetadata = PKPNFTMetadata(pkpNftMetadataAddress); emit PkpNftMetadataAddressSet(pkpNftMetadataAddress); } function setPkpPermissionsAddress( address pkpPermissionsAddress ) public onlyOwner { pkpPermissions = PKPPermissions(pkpPermissionsAddress); emit PkpPermissionsAddressSet(pkpPermissionsAddress); } function setMintCost(uint256 newMintCost) public onlyOwner { mintCost = newMintCost; emit MintCostSet(newMintCost); } function setFreeMintSigner(address newFreeMintSigner) public onlyOwner { freeMintSigner = newFreeMintSigner; emit FreeMintSignerSet(newFreeMintSigner); } function withdraw() public onlyOwner nonReentrant { uint256 withdrawAmount = address(this).balance; (bool sent, ) = payable(msg.sender).call{ value: withdrawAmount }(""); require(sent); emit Withdrew(withdrawAmount); } /// Push a tokenId onto the stack function pkpRouted(uint256 tokenId, uint256 keyType) public { require( msg.sender == address(router), "Only the routing contract can call this function" ); unmintedRoutedTokenIds[keyType].push(tokenId); emit PkpRouted(tokenId, keyType); } /* ========== EVENTS ========== */ event RouterAddressSet(address indexed routerAddress); event PkpNftMetadataAddressSet(address indexed pkpNftMetadataAddress); event PkpPermissionsAddressSet(address indexed pkpPermissionsAddress); event MintCostSet(uint256 newMintCost); event FreeMintSignerSet(address indexed newFreeMintSigner); event Withdrew(uint256 amount); event PkpRouted(uint256 indexed tokenId, uint256 indexed keyType); event PKPMinted(uint256 indexed tokenId, bytes pubkey); }
@openzeppelin/contracts/utils/cryptography/MerkleProof.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/cryptography/MerkleProof.sol) pragma solidity ^0.8.0; /** * @dev These functions deal with verification of Merkle Tree proofs. * * The proofs can be generated using the JavaScript library * https://github.com/miguelmota/merkletreejs[merkletreejs]. * Note: the hashing algorithm should be keccak256 and pair sorting should be enabled. * * See `test/utils/cryptography/MerkleProof.test.js` for some examples. * * WARNING: You should avoid using leaf values that are 64 bytes long prior to * hashing, or use a hash function other than keccak256 for hashing leaves. * This is because the concatenation of a sorted pair of internal nodes in * the merkle tree could be reinterpreted as a leaf value. */ library MerkleProof { /** * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree * defined by `root`. For this, a `proof` must be provided, containing * sibling hashes on the branch from the leaf to the root of the tree. Each * pair of leaves and each pair of pre-images are assumed to be sorted. */ function verify( bytes32[] memory proof, bytes32 root, bytes32 leaf ) internal pure returns (bool) { return processProof(proof, leaf) == root; } /** * @dev Calldata version of {verify} * * _Available since v4.7._ */ function verifyCalldata( bytes32[] calldata proof, bytes32 root, bytes32 leaf ) internal pure returns (bool) { return processProofCalldata(proof, leaf) == root; } /** * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt * hash matches the root of the tree. When processing the proof, the pairs * of leafs & pre-images are assumed to be sorted. * * _Available since v4.4._ */ function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) { bytes32 computedHash = leaf; for (uint256 i = 0; i < proof.length; i++) { computedHash = _hashPair(computedHash, proof[i]); } return computedHash; } /** * @dev Calldata version of {processProof} * * _Available since v4.7._ */ function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) { bytes32 computedHash = leaf; for (uint256 i = 0; i < proof.length; i++) { computedHash = _hashPair(computedHash, proof[i]); } return computedHash; } /** * @dev Returns true if the `leaves` can be proved to be a part of a Merkle tree defined by * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}. * * _Available since v4.7._ */ function multiProofVerify( bytes32[] memory proof, bool[] memory proofFlags, bytes32 root, bytes32[] memory leaves ) internal pure returns (bool) { return processMultiProof(proof, proofFlags, leaves) == root; } /** * @dev Calldata version of {multiProofVerify} * * _Available since v4.7._ */ function multiProofVerifyCalldata( bytes32[] calldata proof, bool[] calldata proofFlags, bytes32 root, bytes32[] memory leaves ) internal pure returns (bool) { return processMultiProofCalldata(proof, proofFlags, leaves) == root; } /** * @dev Returns the root of a tree reconstructed from `leaves` and the sibling nodes in `proof`, * consuming from one or the other at each step according to the instructions given by * `proofFlags`. * * _Available since v4.7._ */ function processMultiProof( bytes32[] memory proof, bool[] memory proofFlags, bytes32[] memory leaves ) internal pure returns (bytes32 merkleRoot) { // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of // the merkle tree. uint256 leavesLen = leaves.length; uint256 totalHashes = proofFlags.length; // Check proof validity. require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof"); // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop". bytes32[] memory hashes = new bytes32[](totalHashes); uint256 leafPos = 0; uint256 hashPos = 0; uint256 proofPos = 0; // At each step, we compute the next hash using two values: // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we // get the next hash. // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the // `proof` array. for (uint256 i = 0; i < totalHashes; i++) { bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]; bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++]; hashes[i] = _hashPair(a, b); } if (totalHashes > 0) { return hashes[totalHashes - 1]; } else if (leavesLen > 0) { return leaves[0]; } else { return proof[0]; } } /** * @dev Calldata version of {processMultiProof} * * _Available since v4.7._ */ function processMultiProofCalldata( bytes32[] calldata proof, bool[] calldata proofFlags, bytes32[] memory leaves ) internal pure returns (bytes32 merkleRoot) { // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of // the merkle tree. uint256 leavesLen = leaves.length; uint256 totalHashes = proofFlags.length; // Check proof validity. require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof"); // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop". bytes32[] memory hashes = new bytes32[](totalHashes); uint256 leafPos = 0; uint256 hashPos = 0; uint256 proofPos = 0; // At each step, we compute the next hash using two values: // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we // get the next hash. // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the // `proof` array. for (uint256 i = 0; i < totalHashes; i++) { bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]; bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++]; hashes[i] = _hashPair(a, b); } if (totalHashes > 0) { return hashes[totalHashes - 1]; } else if (leavesLen > 0) { return leaves[0]; } else { return proof[0]; } } function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) { return a < b ? _efficientHash(a, b) : _efficientHash(b, a); } function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) { /// @solidity memory-safe-assembly assembly { mstore(0x00, a) mstore(0x20, b) value := keccak256(0x00, 0x40) } } }
contracts/lit-node/PKPNFTMetadata.sol
//SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.17; import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol"; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import "hardhat/console.sol"; /// @title Programmable Keypair NFT Metadata /// /// @dev This is the contract for the PKP NFTs /// /// Simply put, whomever owns a PKP NFT can ask that PKP to sign a message. /// The owner can also grant signing permissions to other eth addresses /// or lit actions contract PKPNFTMetadata { using Strings for uint256; /* ========== STATE VARIABLES ========== */ /* ========== CONSTRUCTOR ========== */ constructor() {} /* ========== VIEWS ========== */ function bytesToHex( bytes memory buffer ) public pure returns (string memory) { // Fixed buffer size for hexadecimal convertion bytes memory converted = new bytes(buffer.length * 2); bytes memory _base = "0123456789abcdef"; for (uint256 i = 0; i < buffer.length; i++) { converted[i * 2] = _base[uint8(buffer[i]) / _base.length]; converted[i * 2 + 1] = _base[uint8(buffer[i]) % _base.length]; } return string(abi.encodePacked("0x", converted)); } function tokenURI( uint256 tokenId, bytes memory pubKey, address ethAddress ) public pure returns (string memory) { string memory svgData = "<svg xmlns='http://www.w3.org/2000/svg' width='1080' height='1080' fill='none' xmlns:v='https://vecta.io/nano'><path d='M363.076 392.227s-.977 18.524-36.874 78.947c-41.576 70.018-45.481 151.978-3.017 220.4 89.521 144.245 332.481 141.52 422.556.089 34.832-54.707 44.816-117.479 32.924-181.248 0 0-28.819-133.144-127.237-217.099 1.553 1.308 5.369 19.122 6.101 26.722 2.241 23.354.045 47.838-7.787 70.062-5.746 16.33-13.711 30.467-27.178 41.368 0-3.811-.954-10.635-.976-12.918-.644-46.508-18.659-89.582-48.011-125.743-25.647-31.552-60.812-53.089-97.84-68.932.931 3.191 2.662 16.419 2.906 19.033 1.908 21.958 2.263 52.713-.621 74.649s-7.832 33.878-14.554 54.441c-10.184 31.175-24.05 54.285-41.621 82.004-3.24 5.096-12.913 19.078-18.082 26.146 0 0-8.897-56.191-40.667-87.921h-.022z' fill='#000'/><path d='M562.5 27.28l410.279 236.874c13.923 8.039 22.5 22.895 22.5 38.971v473.75c0 16.076-8.577 30.932-22.5 38.971L562.5 1052.72c-13.923 8.04-31.077 8.04-45 0L107.221 815.846c-13.923-8.039-22.5-22.895-22.5-38.971v-473.75a45 45 0 0 1 22.5-38.971L517.5 27.28a45 45 0 0 1 45 0z' stroke='#000' stroke-width='24.75'/></svg>"; string memory pubkeyStr = bytesToHex(pubKey); // console.log("pubkeyStr"); // console.log(pubkeyStr); string memory ethAddressStr = Strings.toHexString(ethAddress); // console.log("ethAddressStr"); // console.log(ethAddressStr); string memory tokenIdStr = Strings.toString(tokenId); string memory json = Base64.encode( bytes( string( abi.encodePacked( '{"name": "Lit PKP #', tokenIdStr, '", "description": "This NFT entitles the holder to use a Lit Protocol PKP, and to grant access to other users and Lit Actions to use this PKP", "image_data": "', bytes(svgData), '","attributes": [{"trait_type": "Public Key", "value": "', pubkeyStr, '"}, {"trait_type": "ETH Wallet Address", "value": "', ethAddressStr, '"}, {"trait_type": "Token ID", "value": "', tokenIdStr, '"}]}' ) ) ) ); return string(abi.encodePacked("data:application/json;base64,", json)); } }
@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Enumerable.sol) pragma solidity ^0.8.0; import "../ERC721.sol"; import "./IERC721Enumerable.sol"; /** * @dev This implements an optional extension of {ERC721} defined in the EIP that adds * enumerability of all the token ids in the contract as well as all token ids owned by each * account. */ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { // Mapping from owner to list of owned token IDs mapping(address => mapping(uint256 => uint256)) private _ownedTokens; // Mapping from token ID to index of the owner tokens list mapping(uint256 => uint256) private _ownedTokensIndex; // Array with all token ids, used for enumeration uint256[] private _allTokens; // Mapping from token id to position in the allTokens array mapping(uint256 => uint256) private _allTokensIndex; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) { return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); return _ownedTokens[owner][index]; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _allTokens.length; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds"); return _allTokens[index]; } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); if (from == address(0)) { _addTokenToAllTokensEnumeration(tokenId); } else if (from != to) { _removeTokenFromOwnerEnumeration(from, tokenId); } if (to == address(0)) { _removeTokenFromAllTokensEnumeration(tokenId); } else if (to != from) { _addTokenToOwnerEnumeration(to, tokenId); } } /** * @dev Private function to add a token to this extension's ownership-tracking data structures. * @param to address representing the new owner of the given token ID * @param tokenId uint256 ID of the token to be added to the tokens list of the given address */ function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { uint256 length = ERC721.balanceOf(to); _ownedTokens[to][length] = tokenId; _ownedTokensIndex[tokenId] = length; } /** * @dev Private function to add a token to this extension's token tracking data structures. * @param tokenId uint256 ID of the token to be added to the tokens list */ function _addTokenToAllTokensEnumeration(uint256 tokenId) private { _allTokensIndex[tokenId] = _allTokens.length; _allTokens.push(tokenId); } /** * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for * gas optimizations e.g. when performing a transfer operation (avoiding double writes). * This has O(1) time complexity, but alters the order of the _ownedTokens array. * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = ERC721.balanceOf(from) - 1; uint256 tokenIndex = _ownedTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary if (tokenIndex != lastTokenIndex) { uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index } // This also deletes the contents at the last position of the array delete _ownedTokensIndex[tokenId]; delete _ownedTokens[from][lastTokenIndex]; } /** * @dev Private function to remove a token from this extension's token tracking data structures. * This has O(1) time complexity, but alters the order of the _allTokens array. * @param tokenId uint256 ID of the token to be removed from the tokens list */ function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _allTokens.length - 1; uint256 tokenIndex = _allTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding // an 'if' statement (like in _removeTokenFromOwnerEnumeration) uint256 lastTokenId = _allTokens[lastTokenIndex]; _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index // This also deletes the contents at the last position of the array delete _allTokensIndex[tokenId]; _allTokens.pop(); } }
@openzeppelin/contracts/security/Pausable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/Context.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 Pausable is Context { /** * @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); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _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) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
@openzeppelin/contracts/utils/Base64.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Base64.sol) pragma solidity ^0.8.0; /** * @dev Provides a set of functions to operate with Base64 strings. * * _Available since v4.5._ */ library Base64 { /** * @dev Base64 Encoding/Decoding Table */ string internal constant _TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /** * @dev Converts a `bytes` to its Bytes64 `string` representation. */ function encode(bytes memory data) internal pure returns (string memory) { /** * Inspired by Brecht Devos (Brechtpd) implementation - MIT licence * https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol */ if (data.length == 0) return ""; // Loads the table into memory string memory table = _TABLE; // Encoding takes 3 bytes chunks of binary data from `bytes` data parameter // and split into 4 numbers of 6 bits. // The final Base64 length should be `bytes` data length multiplied by 4/3 rounded up // - `data.length + 2` -> Round up // - `/ 3` -> Number of 3-bytes chunks // - `4 *` -> 4 characters for each chunk string memory result = new string(4 * ((data.length + 2) / 3)); /// @solidity memory-safe-assembly assembly { // Prepare the lookup table (skip the first "length" byte) let tablePtr := add(table, 1) // Prepare result pointer, jump over length let resultPtr := add(result, 32) // Run over the input, 3 bytes at a time for { let dataPtr := data let endPtr := add(data, mload(data)) } lt(dataPtr, endPtr) { } { // Advance 3 bytes dataPtr := add(dataPtr, 3) let input := mload(dataPtr) // To write each character, shift the 3 bytes (18 bits) chunk // 4 times in blocks of 6 bits for each character (18, 12, 6, 0) // and apply logical AND with 0x3F which is the number of // the previous character in the ASCII table prior to the Base64 Table // The result is then added to the table to get the character to write, // and finally write it in the result pointer but with a left shift // of 256 (1 byte) - 8 (1 ASCII char) = 248 bits mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F)))) resultPtr := add(resultPtr, 1) // Advance mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F)))) resultPtr := add(resultPtr, 1) // Advance mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F)))) resultPtr := add(resultPtr, 1) // Advance mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F)))) resultPtr := add(resultPtr, 1) // Advance } // When data `bytes` is not exactly 3 bytes long // it is padded with `=` characters at the end switch mod(mload(data), 3) case 1 { mstore8(sub(resultPtr, 1), 0x3d) mstore8(sub(resultPtr, 2), 0x3d) } case 2 { mstore8(sub(resultPtr, 1), 0x3d) } } return result; } }
contracts/lit-node/PubkeyRouter.sol
//SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.17; import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import { PKPNFT } from "./PKPNFT.sol"; import { Staking } from "./Staking.sol"; import "solidity-bytes-utils/contracts/BytesLib.sol"; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "hardhat/console.sol"; // TODO: make the tests send PKPNFT into the constructor // TODO: test interaction between PKPNFT and this contract, like mint a keypair and see if you can access it // TODO: setRoutingData() for a batch of keys contract PubkeyRouter is AccessControl { using EnumerableSet for EnumerableSet.AddressSet; using EnumerableSet for EnumerableSet.Bytes32Set; using EnumerableSet for EnumerableSet.UintSet; using BytesLib for bytes; /* ========== TYPE DEFINITIONS ========== */ bytes32 public constant ADMIN_ROLE = keccak256("ADMIN"); // 0xdf8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec42 bytes32 public constant ROUTER_ROLE = keccak256("ROUTER"); // 0xeb4fd9f47c063b511700e1c8e94e2fa4088ffca1fdcef1e60edf1beecd1b2e64 /* ========== STATE VARIABLES ========== */ PKPNFT public pkpNFT; struct PubkeyRoutingData { bytes pubkey; address stakingContract; uint256 keyType; // 1 = BLS, 2 = ECDSA. Not doing this in an enum so we can add more keytypes in the future without redeploying. } struct Signature { bytes32 r; bytes32 s; uint8 v; } // map the keccack256(uncompressed pubkey) -> PubkeyRoutingData mapping(uint256 => PubkeyRoutingData) public pubkeys; // map the eth address to a pkp id mapping(address => uint256) public ethAddressToPkpId; /* ========== CONSTRUCTOR ========== */ constructor(address _pkpNft) { pkpNFT = PKPNFT(_pkpNft); _grantRole(ADMIN_ROLE, msg.sender); _grantRole(ROUTER_ROLE, msg.sender); _setRoleAdmin(ADMIN_ROLE, ADMIN_ROLE); _setRoleAdmin(ROUTER_ROLE, ADMIN_ROLE); } /* ========== VIEWS ========== */ /// get the routing data for a given key hash function getRoutingData( uint256 tokenId ) external view returns (PubkeyRoutingData memory) { return pubkeys[tokenId]; } /// get if a given pubkey has routing data associated with it or not function isRouted(uint256 tokenId) public view returns (bool) { PubkeyRoutingData memory prd = pubkeys[tokenId]; return prd.pubkey.length != 0 && prd.keyType != 0 && prd.stakingContract != address(0); } /// get the eth address for the keypair, as long as it's an ecdsa keypair function getEthAddress(uint256 tokenId) public view returns (address) { // only return addresses for ECDSA keys so that people don't // send funds to a BLS key that would be irretrieveably lost if (pubkeys[tokenId].keyType != 2) { return address(0); } return deriveEthAddressFromPubkey(pubkeys[tokenId].pubkey); } /// includes the 0x04 prefix so you can pass this directly to ethers.utils.computeAddress function getPubkey(uint256 tokenId) public view returns (bytes memory) { return pubkeys[tokenId].pubkey; } function deriveEthAddressFromPubkey( bytes memory pubkey ) public pure returns (address) { // remove 0x04 prefix bytes32 hashed = keccak256(pubkey.slice(1, 64)); return address(uint160(uint256(hashed))); } /* ========== MUTATIVE FUNCTIONS ========== */ /// register a pubkey and routing data for a given key hash // the person asking the nodes to generate the keys will collect signatures from them and then call this function to route the key // FIXME this is vulnerable to passing the same signature in 10 times. we don't check that the sigs are unique, or that they're from independent nodes. // FIXME this is also vulnerable to an attack where someone sets up their own staking contract with a threshold of 1 and then goes around claiming tokenIds and filling them with junk. we probably need to verify that the staking contract is legit. i'm not sure how to do that though. like we can check various things from the staking contract, that the staked token is the real Lit token, and that the user has staked a significant amount. But how do we know that staking contract isn't a custom fork that lies about all that stuff? Maybe we need a mapping of valid staking contracts somewhere, and when we deploy a new one we add it manually. function setRoutingData( uint256 tokenId, bytes memory pubkey, address stakingContractAddress, uint256 keyType, Signature[] memory signatures ) public { require( hasRole(ROUTER_ROLE, msg.sender), "PubkeyRouter: must have router role" ); Staking stakingContract = Staking(stakingContractAddress); require( signatures.length == stakingContract.getValidatorsInCurrentEpochLength(), "PubkeyRouter: incorrect number of signatures" ); require( tokenId == uint256(keccak256(pubkey)), "tokenId does not match hashed pubkey" ); require( !isRouted(tokenId), "PubkeyRouter: pubkey already has routing data" ); // check the signatures for (uint256 i = 0; i < signatures.length; i++) { Signature memory sig = signatures[i]; address signer = ECDSA.recover( ECDSA.toEthSignedMessageHash(pubkey), sig.v, sig.r, sig.s ); // console.log("signer: "); // console.log(signer); require( stakingContract.isActiveValidatorByNodeAddress(signer), "PubkeyRouter: signer is not active validator" ); } pubkeys[tokenId].pubkey = pubkey; pubkeys[tokenId].stakingContract = stakingContractAddress; pubkeys[tokenId].keyType = keyType; if (keyType == 2) { address pkpAddress = deriveEthAddressFromPubkey(pubkey); ethAddressToPkpId[pkpAddress] = tokenId; } pkpNFT.pkpRouted(tokenId, keyType); emit PubkeyRoutingDataSet( tokenId, pubkey, stakingContractAddress, keyType ); } // a batch version of the above function function setRoutingDataBatch( uint256[] memory tokenIds, bytes[] memory _pubkeys, address stakingContract, uint256 keyType, Signature[][] memory signatures ) public { require( tokenIds.length == _pubkeys.length && tokenIds.length == signatures.length, "PubkeyRouter: incorrect number of arguments" ); for (uint256 i = 0; i < tokenIds.length; i++) { setRoutingData( tokenIds[i], _pubkeys[i], stakingContract, keyType, signatures[i] ); } } /// Set the pubkey and routing data for a given key hash // this is only used by an admin in case of emergency. can prob be removed. function setRoutingDataAsAdmin( uint256 tokenId, bytes memory pubkey, address stakingContract, uint256 keyType ) public { require( hasRole(ADMIN_ROLE, msg.sender), "PubkeyRouter: must have admin role" ); pubkeys[tokenId].pubkey = pubkey; pubkeys[tokenId].stakingContract = stakingContract; pubkeys[tokenId].keyType = keyType; if (keyType == 2) { address pkpAddress = deriveEthAddressFromPubkey(pubkey); ethAddressToPkpId[pkpAddress] = tokenId; } pkpNFT.pkpRouted(tokenId, keyType); emit PubkeyRoutingDataSet(tokenId, pubkey, stakingContract, keyType); } function setPkpNftAddress(address newPkpNftAddress) public { require( hasRole(ADMIN_ROLE, msg.sender), "PubkeyRouter: must have admin role" ); pkpNFT = PKPNFT(newPkpNftAddress); emit PkpNftAddressSet(newPkpNftAddress); } /* ========== EVENTS ========== */ event PubkeyRoutingDataSet( uint256 indexed tokenId, bytes pubkey, address stakingContract, uint256 keyType ); event PkpNftAddressSet(address newPkpNftAddress); }
@openzeppelin/contracts/utils/Address.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @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, it is bubbled up by this * function (like regular Solidity function calls). * * 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. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @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`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // 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(errorMessage); } } } }
contracts/lit-node/Staking.sol
//SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.17; import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import { ERC20Burnable } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "hardhat/console.sol"; contract Staking is ReentrancyGuard, Pausable, Ownable { using EnumerableSet for EnumerableSet.AddressSet; /* ========== STATE VARIABLES ========== */ enum States { Active, NextValidatorSetLocked, ReadyForNextEpoch, Unlocked, Paused } // this enum is not used, and instead we use an integer so that // we can add more reasons after the contract is deployed. // This enum is kept in the comments here for reference. // enum KickReason { // NULLREASON, // 0 // UNRESPONSIVE, // 1 // BAD_ATTESTATION // 2 // } States public state = States.Active; ERC20Burnable public stakingToken; struct Epoch { uint256 epochLength; uint256 number; uint256 endBlock; // uint256 retries; // incremented upon failure to advance and subsequent unlock uint256 timeout; // timeout in blocks, where the nodes can be unlocked. } Epoch public epoch; uint256 public tokenRewardPerTokenPerEpoch; uint256 public minimumStake; uint256 public totalStaked; // tokens slashed when kicked uint256 public kickPenaltyPercent; EnumerableSet.AddressSet validatorsInCurrentEpoch; EnumerableSet.AddressSet validatorsInNextEpoch; EnumerableSet.AddressSet validatorsKickedFromNextEpoch; struct Validator { uint32 ip; uint128 ipv6; uint32 port; address nodeAddress; uint256 balance; uint256 reward; uint256 senderPubKey; uint256 receiverPubKey; } struct VoteToKickValidatorInNextEpoch { uint256 votes; mapping(address => bool) voted; } // list of all validators, even ones that are not in the current or next epoch // maps STAKER address to Validator struct mapping(address => Validator) public validators; // stakers join by staking, but nodes need to be able to vote to kick. // to avoid node operators having to run a hotwallet with their staking private key, // the node gets it's own private key that it can use to vote to kick, // or signal that the next epoch is ready. // this mapping lets you go from the nodeAddressto the stakingAddress. mapping(address => address) public nodeAddressToStakerAddress; // after the validator set is locked, nodes vote that they have successfully completed the PSS // operation. Once a threshold of nodes have voted that they are ready, then the epoch can advance mapping(address => bool) public readyForNextEpoch; // nodes can vote to kick another node. If a threshold of nodes vote to kick someone, they // are removed from the next validator set mapping(uint256 => mapping(address => VoteToKickValidatorInNextEpoch)) public votesToKickValidatorsInNextEpoch; // resolver contract address. the resolver contract is used to lookup other contract addresses. address public resolverContractAddress; /* ========== CONSTRUCTOR ========== */ constructor(address _stakingToken) { stakingToken = ERC20Burnable(_stakingToken); epoch = Epoch({ epochLength: 80, number: 1, endBlock: block.number + 1, retries: 0, timeout: 80 }); // 0.05 tokens per token staked meaning a 5% per epoch inflation rate tokenRewardPerTokenPerEpoch = (10 ** stakingToken.decimals()) / 20; // 1 token minimum stake minimumStake = 1 * (10 ** stakingToken.decimals()); kickPenaltyPercent = 0; } /* ========== VIEWS ========== */ function isActiveValidator(address account) external view returns (bool) { return validatorsInCurrentEpoch.contains(account); } function isActiveValidatorByNodeAddress( address account ) external view returns (bool) { return validatorsInCurrentEpoch.contains( nodeAddressToStakerAddress[account] ); } function rewardOf(address account) external view returns (uint256) { return validators[account].reward; } function balanceOf(address account) external view returns (uint256) { return validators[account].balance; } function getVotingStatusToKickValidator( uint256 epochNumber, address validatorStakerAddress, address voterStakerAddress ) external view returns (uint256, bool) { VoteToKickValidatorInNextEpoch storage votingStatus = votesToKickValidatorsInNextEpoch[ epochNumber ][validatorStakerAddress]; return (votingStatus.votes, votingStatus.voted[voterStakerAddress]); } function getValidatorsInCurrentEpoch() public view returns (address[] memory) { address[] memory values = new address[]( validatorsInCurrentEpoch.length() ); uint256 validatorLength = validatorsInCurrentEpoch.length(); for (uint256 i = 0; i < validatorLength; i++) { values[i] = validatorsInCurrentEpoch.at(i); } return values; } function getValidatorsInCurrentEpochLength() external view returns (uint256) { return validatorsInCurrentEpoch.length(); } function getValidatorsInNextEpoch() public view returns (address[] memory) { address[] memory values = new address[](validatorsInNextEpoch.length()); uint256 validatorLength = validatorsInNextEpoch.length(); for (uint256 i = 0; i < validatorLength; i++) { values[i] = validatorsInNextEpoch.at(i); } return values; } function getValidatorsStructs( address[] memory addresses ) public view returns (Validator[] memory) { Validator[] memory values = new Validator[](addresses.length); for (uint256 i = 0; i < addresses.length; i++) { values[i] = validators[addresses[i]]; } return values; } function getValidatorsStructsInCurrentEpoch() external view returns (Validator[] memory) { address[] memory addresses = getValidatorsInCurrentEpoch(); return getValidatorsStructs(addresses); } function getValidatorsStructsInNextEpoch() external view returns (Validator[] memory) { address[] memory addresses = getValidatorsInNextEpoch(); return getValidatorsStructs(addresses); } function isReadyForNextEpoch() public view returns (bool) { uint256 total = 0; uint256 validatorLength = validatorsInNextEpoch.length(); for (uint256 i = 0; i < validatorLength; i++) { if (readyForNextEpoch[validatorsInNextEpoch.at(i)]) { total++; } } if ((total >= validatorCountForConsensus())) { // 2/3 of validators must be ready return true; } return false; } function shouldKickValidator( address stakerAddress ) public view returns (bool) { VoteToKickValidatorInNextEpoch storage vk = votesToKickValidatorsInNextEpoch[epoch.number][ stakerAddress ]; if (vk.votes >= validatorCountForConsensus()) { // 2/3 of validators must vote return true; } return false; } // these could be checked with uint return value with the state getter, but included defensively in case more states are added. function validatorsInNextEpochAreLocked() public view returns (bool) { return state == States.NextValidatorSetLocked; } function validatorStateIsActive() public view returns (bool) { return state == States.Active; } function validatorStateIsUnlocked() public view returns (bool) { return state == States.Unlocked; } // currently set to 2/3. this could be changed to be configurable. function validatorCountForConsensus() public view returns (uint256) { if (validatorsInCurrentEpoch.length() <= 2) { return 1; } return (validatorsInCurrentEpoch.length() * 2) / 3; } /* ========== MUTATIVE FUNCTIONS ========== */ /// Lock in the validators for the next epoch function lockValidatorsForNextEpoch() public { require( block.number >= epoch.endBlock, "Enough blocks have not elapsed since the last epoch" ); require( state == States.Active || state == States.Unlocked, "Must be in active or unlocked state" ); state = States.NextValidatorSetLocked; emit StateChanged(state); } /// After proactive secret sharing is complete, the nodes may signal that they are ready for the next epoch. Note that this function is called by the node itself, and so msg.sender is the nodeAddress and not the stakerAddress. function signalReadyForNextEpoch() public { address stakerAddress = nodeAddressToStakerAddress[msg.sender]; require( state == States.NextValidatorSetLocked || state == States.ReadyForNextEpoch, "Must be in state NextValidatorSetLocked or ReadyForNextEpoch" ); // at the first epoch, validatorsInCurrentEpoch is empty if (epoch.number != 1) { require( validatorsInNextEpoch.contains(stakerAddress), "Validator is not in the next epoch" ); } readyForNextEpoch[stakerAddress] = true; emit ReadyForNextEpoch(stakerAddress); if (isReadyForNextEpoch()) { state = States.ReadyForNextEpoch; emit StateChanged(state); } } /// If the nodes fail to advance (e.g. because dkg failed), anyone can call to unlock and allow retry function unlockValidatorsForNextEpoch() public { // the deadline to advance is thus epoch.endBlock + epoch.timeout require( block.number >= epoch.endBlock + epoch.timeout, "Enough blocks have not elapsed since the last epoch" ); require( state == States.NextValidatorSetLocked, "Must be in NextValidatorSetLocked" ); uint256 validatorLength = validatorsInNextEpoch.length(); for (uint256 i = 0; i < validatorLength; i++) { readyForNextEpoch[validatorsInNextEpoch.at(i)] = false; } epoch.retries++; state = States.Unlocked; emit StateChanged(state); } /// Advance to the next Epoch. Rewards validators, adds the joiners, and removes the leavers function advanceEpoch() public { require( block.number >= epoch.endBlock, "Enough blocks have not elapsed since the last epoch" ); require( state == States.ReadyForNextEpoch, "Must be in ready for next epoch state" ); require( isReadyForNextEpoch() == true, "Not enough validators are ready for the next epoch" ); // reward the validators uint256 validatorLength = validatorsInCurrentEpoch.length(); for (uint256 i = 0; i < validatorLength; i++) { address validatorAddress = validatorsInCurrentEpoch.at(i); validators[validatorAddress].reward += (tokenRewardPerTokenPerEpoch * validators[validatorAddress].balance) / 10 ** stakingToken.decimals(); } // set the validators to the new validator set // ideally we could just do this: // validatorsInCurrentEpoch = validatorsInNextEpoch; // but solidity doesn't allow that, so we have to do it manually // clear out validators in current epoch while (validatorsInCurrentEpoch.length() > 0) { validatorsInCurrentEpoch.remove(validatorsInCurrentEpoch.at(0)); } // copy validators from next epoch to current epoch validatorLength = validatorsInNextEpoch.length(); for (uint256 i = 0; i < validatorLength; i++) { validatorsInCurrentEpoch.add(validatorsInNextEpoch.at(i)); // clear out readyForNextEpoch readyForNextEpoch[validatorsInNextEpoch.at(i)] = false; } epoch.number++; epoch.endBlock = block.number + epoch.epochLength; // not epoch.endBlock + state = States.Active; emit StateChanged(state); } /// Stake and request to join the validator set /// @param amount The amount of tokens to stake /// @param ip The IP address of the node /// @param port The port of the node function stakeAndJoin( uint256 amount, uint32 ip, uint128 ipv6, uint32 port, address nodeAddress, uint256 senderPubKey, uint256 receiverPubKey ) public whenNotPaused { stake(amount); requestToJoin( ip, ipv6, port, nodeAddress, senderPubKey, receiverPubKey ); } /// Stake tokens for a validator function stake(uint256 amount) public nonReentrant { require(amount > 0, "Cannot stake 0"); stakingToken.transferFrom(msg.sender, address(this), amount); validators[msg.sender].balance += amount; totalStaked += amount; emit Staked(msg.sender, amount); } function requestToJoin( uint32 ip, uint128 ipv6, uint32 port, address nodeAddress, uint256 senderPubKey, uint256 receiverPubKey ) public nonReentrant { uint256 amountStaked = validators[msg.sender].balance; require( amountStaked >= minimumStake, "Stake must be greater than or equal to minimumStake" ); require( state == States.Active || state == States.Unlocked || state == States.Paused, "Must be in Active or Unlocked state to request to join" ); // make sure they haven't been kicked require( validatorsKickedFromNextEpoch.contains(msg.sender) == false, "You cannot rejoin if you have been kicked until the next epoch" ); validators[msg.sender].ip = ip; validators[msg.sender].ipv6 = ipv6; validators[msg.sender].port = port; validators[msg.sender].nodeAddress = nodeAddress; validators[msg.sender].senderPubKey = senderPubKey; validators[msg.sender].receiverPubKey = receiverPubKey; nodeAddressToStakerAddress[nodeAddress] = msg.sender; validatorsInNextEpoch.add(msg.sender); emit RequestToJoin(msg.sender); } /// Withdraw staked tokens. This can only be done by users who are not active in the validator set. /// @param amount The amount of tokens to withdraw function withdraw(uint256 amount) public nonReentrant { require(amount > 0, "Cannot withdraw 0"); require( validatorsInCurrentEpoch.contains(msg.sender) == false, "Active validators cannot leave. Please use the leave() function and wait for the next epoch to leave" ); require( validators[msg.sender].balance >= amount, "Not enough tokens to withdraw" ); totalStaked = totalStaked - amount; validators[msg.sender].balance = validators[msg.sender].balance - amount; stakingToken.transfer(msg.sender, amount); emit Withdrawn(msg.sender, amount); } /// Request to leave in the next Epoch function requestToLeave() public nonReentrant { require( state == States.Active || state == States.Unlocked || state == States.Paused, "Must be in Active or Unlocked state to request to leave" ); if (validatorsInNextEpoch.contains(msg.sender)) { // remove them validatorsInNextEpoch.remove(msg.sender); } emit RequestToLeave(msg.sender); } /// Transfer any outstanding reward tokens function getReward() public nonReentrant { uint256 reward = validators[msg.sender].reward; if (reward > 0) { validators[msg.sender].reward = 0; stakingToken.transfer(msg.sender, reward); emit RewardPaid(msg.sender, reward); } } /// Exit staking and get any outstanding rewards function exit() public { withdraw(validators[msg.sender].balance); getReward(); } /// If more than the threshold of validators vote to kick someone, kick them. /// It's expected that this will be called by the node directly, so msg.sender will be the nodeAddress function kickValidatorInNextEpoch( address validatorStakerAddress, uint256 reason, bytes calldata data ) public nonReentrant { address stakerAddressOfSender = nodeAddressToStakerAddress[msg.sender]; require( stakerAddressOfSender != address(0), "Could not map your nodeAddress to your stakerAddress" ); require( validatorsInNextEpoch.contains(stakerAddressOfSender), "You must be a validator in the next epoch to kick someone from the next epoch" ); require( votesToKickValidatorsInNextEpoch[epoch.number][ validatorStakerAddress ].voted[stakerAddressOfSender] == false, "You can only vote to kick someone once per epoch" ); // Vote to kick votesToKickValidatorsInNextEpoch[epoch.number][validatorStakerAddress] .votes++; votesToKickValidatorsInNextEpoch[epoch.number][validatorStakerAddress] .voted[stakerAddressOfSender] = true; if ( validatorsInNextEpoch.contains(validatorStakerAddress) && shouldKickValidator(validatorStakerAddress) ) { // remove from next validator set validatorsInNextEpoch.remove(validatorStakerAddress); // block them from rejoining the next epoch validatorsKickedFromNextEpoch.add(validatorStakerAddress); // slash the stake uint256 amountToBurn = (validators[validatorStakerAddress].balance * kickPenaltyPercent) / 100; validators[validatorStakerAddress].balance -= amountToBurn; totalStaked -= amountToBurn; stakingToken.burn(amountToBurn); // shame them with an event emit ValidatorKickedFromNextEpoch( validatorStakerAddress, amountToBurn ); } emit VotedToKickValidatorInNextEpoch( stakerAddressOfSender, validatorStakerAddress, reason, data ); } /// Set the IP and port of your node /// @param ip The ip address of your node /// @param port The port of your node function setIpPortNodeAddressAndCommunicationPubKeys( uint32 ip, uint128 ipv6, uint32 port, address nodeAddress, uint256 senderPubKey, uint256 receiverPubKey ) public { validators[msg.sender].ip = ip; validators[msg.sender].ipv6 = ipv6; validators[msg.sender].port = port; validators[msg.sender].nodeAddress = nodeAddress; validators[msg.sender].senderPubKey = senderPubKey; validators[msg.sender].receiverPubKey = receiverPubKey; } function setEpochLength(uint256 newEpochLength) public onlyOwner { epoch.epochLength = newEpochLength; emit EpochLengthSet(newEpochLength); } function setEpochTimeout(uint256 newEpochTimeout) public onlyOwner { epoch.timeout = newEpochTimeout; emit EpochTimeoutSet(newEpochTimeout); } function setStakingToken(address newStakingTokenAddress) public onlyOwner { stakingToken = ERC20Burnable(newStakingTokenAddress); emit StakingTokenSet(newStakingTokenAddress); } function setTokenRewardPerTokenPerEpoch( uint256 newTokenRewardPerTokenPerEpoch ) public onlyOwner { tokenRewardPerTokenPerEpoch = newTokenRewardPerTokenPerEpoch; emit TokenRewardPerTokenPerEpochSet(newTokenRewardPerTokenPerEpoch); } function setMinimumStake(uint256 newMinimumStake) public onlyOwner { minimumStake = newMinimumStake; emit MinimumStakeSet(newMinimumStake); } function setKickPenaltyPercent( uint256 newKickPenaltyPercent ) public onlyOwner { kickPenaltyPercent = newKickPenaltyPercent; emit KickPenaltyPercentSet(newKickPenaltyPercent); } function setResolverContractAddress( address newResolverContractAddress ) public onlyOwner { resolverContractAddress = newResolverContractAddress; emit ResolverContractAddressSet(newResolverContractAddress); } function setEpochState(States newState) public onlyOwner { state = newState; emit StateChanged(newState); } function pauseEpoch() public onlyOwner { state = States.Paused; emit StateChanged(States.Paused); } function adminKickValidatorInNextEpoch( address validatorStakerAddress ) public nonReentrant onlyOwner { // remove from next validator set validatorsInNextEpoch.remove(validatorStakerAddress); // block them from rejoining the next epoch validatorsKickedFromNextEpoch.add(validatorStakerAddress); emit ValidatorKickedFromNextEpoch(validatorStakerAddress, 0); } function adminSlashValidator( address validatorStakerAddress, uint256 amountToBurn ) public nonReentrant onlyOwner { validators[validatorStakerAddress].balance -= amountToBurn; totalStaked -= amountToBurn; stakingToken.burn(amountToBurn); emit ValidatorKickedFromNextEpoch(validatorStakerAddress, amountToBurn); } /* ========== EVENTS ========== */ event Staked(address indexed staker, uint256 amount); event Withdrawn(address indexed staker, uint256 amount); event RewardPaid(address indexed staker, uint256 reward); event RewardsDurationUpdated(uint256 newDuration); event RequestToJoin(address indexed staker); event RequestToLeave(address indexed staker); event Recovered(address token, uint256 amount); event ReadyForNextEpoch(address indexed staker); event StateChanged(States newState); event VotedToKickValidatorInNextEpoch( address indexed reporter, address indexed validatorStakerAddress, uint256 indexed reason, bytes data ); event ValidatorKickedFromNextEpoch( address indexed staker, uint256 amountBurned ); // onlyOwner events event EpochLengthSet(uint256 newEpochLength); event EpochTimeoutSet(uint256 newEpochTimeout); event StakingTokenSet(address newStakingTokenAddress); event TokenRewardPerTokenPerEpochSet( uint256 newTokenRewardPerTokenPerEpoch ); event MinimumStakeSet(uint256 newMinimumStake); event KickPenaltyPercentSet(uint256 newKickPenaltyPercent); event ResolverContractAddressSet(address newResolverContractAddress); }
@openzeppelin/contracts/token/ERC20/ERC20.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
@openzeppelin/contracts/utils/structs/EnumerableSet.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol) pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { return _values(set._inner); } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values on the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing 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 { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
@openzeppelin/contracts/security/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/extensions/ERC721Burnable.sol) pragma solidity ^0.8.0; import "../ERC721.sol"; import "../../../utils/Context.sol"; /** * @title ERC721 Burnable Token * @dev ERC721 Token that can be burned (destroyed). */ abstract contract ERC721Burnable is Context, ERC721 { /** * @dev Burns `tokenId`. See {ERC721-_burn}. * * Requirements: * * - The caller must own `tokenId` or be an approved operator. */ function burn(uint256 tokenId) public virtual { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner nor approved"); _burn(tokenId); } }
@openzeppelin/contracts/utils/introspection/ERC165.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
@openzeppelin/contracts/utils/structs/BitMaps.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/structs/BitMaps.sol) pragma solidity ^0.8.0; /** * @dev Library for managing uint256 to bool mapping in a compact and efficient way, providing the keys are sequential. * Largelly inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor]. */ library BitMaps { struct BitMap { mapping(uint256 => uint256) _data; } /** * @dev Returns whether the bit at `index` is set. */ function get(BitMap storage bitmap, uint256 index) internal view returns (bool) { uint256 bucket = index >> 8; uint256 mask = 1 << (index & 0xff); return bitmap._data[bucket] & mask != 0; } /** * @dev Sets the bit at `index` to the boolean `value`. */ function setTo( BitMap storage bitmap, uint256 index, bool value ) internal { if (value) { set(bitmap, index); } else { unset(bitmap, index); } } /** * @dev Sets the bit at `index`. */ function set(BitMap storage bitmap, uint256 index) internal { uint256 bucket = index >> 8; uint256 mask = 1 << (index & 0xff); bitmap._data[bucket] |= mask; } /** * @dev Unsets the bit at `index`. */ function unset(BitMap storage bitmap, uint256 index) internal { uint256 bucket = index >> 8; uint256 mask = 1 << (index & 0xff); bitmap._data[bucket] &= ~mask; } }
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
@openzeppelin/contracts/access/IAccessControl.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_pkpNft","internalType":"address"},{"type":"address","name":"_pkpPermissions","internalType":"address"}]},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"mintNextAndAddAuthMethods","inputs":[{"type":"uint256","name":"keyType","internalType":"uint256"},{"type":"uint256[]","name":"permittedAuthMethodTypes","internalType":"uint256[]"},{"type":"bytes[]","name":"permittedAuthMethodIds","internalType":"bytes[]"},{"type":"bytes[]","name":"permittedAuthMethodPubkeys","internalType":"bytes[]"},{"type":"uint256[][]","name":"permittedAuthMethodScopes","internalType":"uint256[][]"},{"type":"bool","name":"addPkpEthAddressAsPermittedAddress","internalType":"bool"},{"type":"bool","name":"sendPkpToItself","internalType":"bool"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"mintNextAndAddAuthMethodsWithTypes","inputs":[{"type":"uint256","name":"keyType","internalType":"uint256"},{"type":"bytes[]","name":"permittedIpfsCIDs","internalType":"bytes[]"},{"type":"uint256[][]","name":"permittedIpfsCIDScopes","internalType":"uint256[][]"},{"type":"address[]","name":"permittedAddresses","internalType":"address[]"},{"type":"uint256[][]","name":"permittedAddressScopes","internalType":"uint256[][]"},{"type":"uint256[]","name":"permittedAuthMethodTypes","internalType":"uint256[]"},{"type":"bytes[]","name":"permittedAuthMethodIds","internalType":"bytes[]"},{"type":"bytes[]","name":"permittedAuthMethodPubkeys","internalType":"bytes[]"},{"type":"uint256[][]","name":"permittedAuthMethodScopes","internalType":"uint256[][]"},{"type":"bool","name":"addPkpEthAddressAsPermittedAddress","internalType":"bool"},{"type":"bool","name":"sendPkpToItself","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes4","name":"","internalType":"bytes4"}],"name":"onERC721Received","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"bytes","name":"","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract PKPNFT"}],"name":"pkpNFT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract PKPPermissions"}],"name":"pkpPermissions","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setPkpNftAddress","inputs":[{"type":"address","name":"newPkpNftAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setPkpPermissionsAddress","inputs":[{"type":"address","name":"newPkpPermissionsAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]}]
Contract Creation Code
0x60806040523480156200001157600080fd5b50604051620024f3380380620024f3833981810160405281019062000037919062000217565b620000576200004b620000e160201b60201c565b620000e960201b60201c565b81600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050506200025e565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620001df82620001b2565b9050919050565b620001f181620001d2565b8114620001fd57600080fd5b50565b6000815190506200021181620001e6565b92915050565b60008060408385031215620002315762000230620001ad565b5b6000620002418582860162000200565b9250506020620002548582860162000200565b9150509250929050565b612285806200026e6000396000f3fe6080604052600436106100915760003560e01c80638da5cb5b116100595780638da5cb5b1461016c57806397016f3f146101975780639fba176b146101c2578063f2fde38b146101f2578063ffa2e9531461021b57610091565b8063150b7a0214610096578063176354fd146100d35780631ea89a22146100fc5780631f71cb3114610125578063715018a614610155575b600080fd5b3480156100a257600080fd5b506100bd60048036038101906100b89190611011565b610246565b6040516100ca91906110d4565b60405180910390f35b3480156100df57600080fd5b506100fa60048036038101906100f591906110ef565b6102eb565b005b34801561010857600080fd5b50610123600480360381019061011e91906110ef565b610337565b005b61013f600480360381019061013a91906115dd565b610383565b60405161014c91906117c0565b60405180910390f35b34801561016157600080fd5b5061016a610b59565b005b34801561017857600080fd5b50610181610b6d565b60405161018e91906117ea565b60405180910390f35b3480156101a357600080fd5b506101ac610b96565b6040516101b99190611864565b60405180910390f35b6101dc60048036038101906101d7919061187f565b610bbc565b6040516101e991906117c0565b60405180910390f35b3480156101fe57600080fd5b50610219600480360381019061021491906110ef565b610d11565b005b34801561022757600080fd5b50610230610d94565b60405161023d91906119b2565b60405180910390f35b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146102d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102cf90611a50565b60405180910390fd5b63150b7a0260e01b905095945050505050565b6102f3610dba565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b61033f610dba565b80600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600080600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16635d228b16348f6040518363ffffffff1660e01b81526004016103e291906117c0565b60206040518083038185885af1158015610400573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906104259190611a85565b90508a518c511461046b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161046290611b24565b60405180910390fd5b88518a51146104af576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104a690611bb6565b60405180910390fd5b86518851146104f3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104ea90611c48565b60405180910390fd5b8551885114610537576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161052e90611cda565b60405180910390fd5b845188511461057b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161057290611d6c565b60405180910390fd5b60008c511461066a5760005b8c5181101561066857600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16638a431578838f84815181106105e2576105e1611d8c565b5b60200260200101518f85815181106105fd576105fc611d8c565b5b60200260200101516040518463ffffffff1660e01b815260040161062393929190611ef8565b600060405180830381600087803b15801561063d57600080fd5b505af1158015610651573d6000803e3d6000fd5b50505050808061066090611f6c565b915050610587565b505b60008a51146107595760005b8a5181101561075757600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16631663c121838d84815181106106d1576106d0611d8c565b5b60200260200101518d85815181106106ec576106eb611d8c565b5b60200260200101516040518463ffffffff1660e01b815260040161071293929190611fb4565b600060405180830381600087803b15801561072c57600080fd5b505af1158015610740573d6000803e3d6000fd5b50505050808061074f90611f6c565b915050610676565b505b60008851146108965760005b885181101561089457600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16639dd4349b8360405180606001604052808d86815181106107cb576107ca611d8c565b5b602002602001015181526020018c86815181106107eb576107ea611d8c565b5b602002602001015181526020018b868151811061080b5761080a611d8c565b5b602002602001015181525089858151811061082957610828611d8c565b5b60200260200101516040518463ffffffff1660e01b815260040161084f93929190612093565b600060405180830381600087803b15801561086957600080fd5b505af115801561087d573d6000803e3d6000fd5b50505050808061088c90611f6c565b915050610765565b505b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663bd4986a0836040518263ffffffff1660e01b81526004016108f391906117c0565b602060405180830381865afa158015610910573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061093491906120ed565b90508415610a1757600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16631663c1218383600067ffffffffffffffff8111156109975761099661112d565b5b6040519080825280602002602001820160405280156109c55781602001602082028036833780820191505090505b506040518463ffffffff1660e01b81526004016109e493929190611fb4565b600060405180830381600087803b1580156109fe57600080fd5b505af1158015610a12573d6000803e3d6000fd5b505050505b8315610ab357600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166342842e0e3083856040518463ffffffff1660e01b8152600401610a7c9392919061211a565b600060405180830381600087803b158015610a9657600080fd5b505af1158015610aaa573d6000803e3d6000fd5b50505050610b45565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166342842e0e3033856040518463ffffffff1660e01b8152600401610b129392919061211a565b600060405180830381600087803b158015610b2c57600080fd5b505af1158015610b40573d6000803e3d6000fd5b505050505b81925050509b9a5050505050505050505050565b610b61610dba565b610b6b6000610e38565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000610d0488600067ffffffffffffffff811115610bdd57610bdc61112d565b5b604051908082528060200260200182016040528015610c1057816020015b6060815260200190600190039081610bfb5790505b50600067ffffffffffffffff811115610c2c57610c2b61112d565b5b604051908082528060200260200182016040528015610c5f57816020015b6060815260200190600190039081610c4a5790505b50600067ffffffffffffffff811115610c7b57610c7a61112d565b5b604051908082528060200260200182016040528015610ca95781602001602082028036833780820191505090505b50600067ffffffffffffffff811115610cc557610cc461112d565b5b604051908082528060200260200182016040528015610cf857816020015b6060815260200190600190039081610ce35790505b508c8c8c8c8c8c610383565b9050979650505050505050565b610d19610dba565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610d88576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d7f906121c3565b60405180910390fd5b610d9181610e38565b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610dc2610efc565b73ffffffffffffffffffffffffffffffffffffffff16610de0610b6d565b73ffffffffffffffffffffffffffffffffffffffff1614610e36576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e2d9061222f565b60405180910390fd5b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600033905090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610f4382610f18565b9050919050565b610f5381610f38565b8114610f5e57600080fd5b50565b600081359050610f7081610f4a565b92915050565b6000819050919050565b610f8981610f76565b8114610f9457600080fd5b50565b600081359050610fa681610f80565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f840112610fd157610fd0610fac565b5b8235905067ffffffffffffffff811115610fee57610fed610fb1565b5b60208301915083600182028301111561100a57611009610fb6565b5b9250929050565b60008060008060006080868803121561102d5761102c610f0e565b5b600061103b88828901610f61565b955050602061104c88828901610f61565b945050604061105d88828901610f97565b935050606086013567ffffffffffffffff81111561107e5761107d610f13565b5b61108a88828901610fbb565b92509250509295509295909350565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6110ce81611099565b82525050565b60006020820190506110e960008301846110c5565b92915050565b60006020828403121561110557611104610f0e565b5b600061111384828501610f61565b91505092915050565b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6111658261111c565b810181811067ffffffffffffffff821117156111845761118361112d565b5b80604052505050565b6000611197610f04565b90506111a3828261115c565b919050565b600067ffffffffffffffff8211156111c3576111c261112d565b5b602082029050602081019050919050565b600080fd5b600067ffffffffffffffff8211156111f4576111f361112d565b5b6111fd8261111c565b9050602081019050919050565b82818337600083830152505050565b600061122c611227846111d9565b61118d565b905082815260208101848484011115611248576112476111d4565b5b61125384828561120a565b509392505050565b600082601f8301126112705761126f610fac565b5b8135611280848260208601611219565b91505092915050565b600061129c611297846111a8565b61118d565b905080838252602082019050602084028301858111156112bf576112be610fb6565b5b835b8181101561130657803567ffffffffffffffff8111156112e4576112e3610fac565b5b8086016112f1898261125b565b855260208501945050506020810190506112c1565b5050509392505050565b600082601f83011261132557611324610fac565b5b8135611335848260208601611289565b91505092915050565b600067ffffffffffffffff8211156113595761135861112d565b5b602082029050602081019050919050565b600067ffffffffffffffff8211156113855761138461112d565b5b602082029050602081019050919050565b60006113a96113a48461136a565b61118d565b905080838252602082019050602084028301858111156113cc576113cb610fb6565b5b835b818110156113f557806113e18882610f97565b8452602084019350506020810190506113ce565b5050509392505050565b600082601f83011261141457611413610fac565b5b8135611424848260208601611396565b91505092915050565b600061144061143b8461133e565b61118d565b9050808382526020820190506020840283018581111561146357611462610fb6565b5b835b818110156114aa57803567ffffffffffffffff81111561148857611487610fac565b5b80860161149589826113ff565b85526020850194505050602081019050611465565b5050509392505050565b600082601f8301126114c9576114c8610fac565b5b81356114d984826020860161142d565b91505092915050565b600067ffffffffffffffff8211156114fd576114fc61112d565b5b602082029050602081019050919050565b600061152161151c846114e2565b61118d565b9050808382526020820190506020840283018581111561154457611543610fb6565b5b835b8181101561156d57806115598882610f61565b845260208401935050602081019050611546565b5050509392505050565b600082601f83011261158c5761158b610fac565b5b813561159c84826020860161150e565b91505092915050565b60008115159050919050565b6115ba816115a5565b81146115c557600080fd5b50565b6000813590506115d7816115b1565b92915050565b60008060008060008060008060008060006101608c8e03121561160357611602610f0e565b5b60006116118e828f01610f97565b9b505060208c013567ffffffffffffffff81111561163257611631610f13565b5b61163e8e828f01611310565b9a505060408c013567ffffffffffffffff81111561165f5761165e610f13565b5b61166b8e828f016114b4565b99505060608c013567ffffffffffffffff81111561168c5761168b610f13565b5b6116988e828f01611577565b98505060808c013567ffffffffffffffff8111156116b9576116b8610f13565b5b6116c58e828f016114b4565b97505060a08c013567ffffffffffffffff8111156116e6576116e5610f13565b5b6116f28e828f016113ff565b96505060c08c013567ffffffffffffffff81111561171357611712610f13565b5b61171f8e828f01611310565b95505060e08c013567ffffffffffffffff8111156117405761173f610f13565b5b61174c8e828f01611310565b9450506101008c013567ffffffffffffffff81111561176e5761176d610f13565b5b61177a8e828f016114b4565b93505061012061178c8e828f016115c8565b92505061014061179e8e828f016115c8565b9150509295989b509295989b9093969950565b6117ba81610f76565b82525050565b60006020820190506117d560008301846117b1565b92915050565b6117e481610f38565b82525050565b60006020820190506117ff60008301846117db565b92915050565b6000819050919050565b600061182a61182561182084610f18565b611805565b610f18565b9050919050565b600061183c8261180f565b9050919050565b600061184e82611831565b9050919050565b61185e81611843565b82525050565b60006020820190506118796000830184611855565b92915050565b600080600080600080600060e0888a03121561189e5761189d610f0e565b5b60006118ac8a828b01610f97565b975050602088013567ffffffffffffffff8111156118cd576118cc610f13565b5b6118d98a828b016113ff565b965050604088013567ffffffffffffffff8111156118fa576118f9610f13565b5b6119068a828b01611310565b955050606088013567ffffffffffffffff81111561192757611926610f13565b5b6119338a828b01611310565b945050608088013567ffffffffffffffff81111561195457611953610f13565b5b6119608a828b016114b4565b93505060a06119718a828b016115c8565b92505060c06119828a828b016115c8565b91505092959891949750929550565b600061199c82611831565b9050919050565b6119ac81611991565b82525050565b60006020820190506119c760008301846119a3565b92915050565b600082825260208201905092915050565b7f504b5048656c7065723a206f6e6c792061636365707473207472616e7366657260008201527f732066726f6d2074686520504b504e465420636f6e7472616374000000000000602082015250565b6000611a3a603a836119cd565b9150611a45826119de565b604082019050919050565b60006020820190508181036000830152611a6981611a2d565b9050919050565b600081519050611a7f81610f80565b92915050565b600060208284031215611a9b57611a9a610f0e565b5b6000611aa984828501611a70565b91505092915050565b7f504b5048656c7065723a20697066732063696420616e642073636f706520617260008201527f726179206c656e67746873206d757374206d6174636800000000000000000000602082015250565b6000611b0e6036836119cd565b9150611b1982611ab2565b604082019050919050565b60006020820190508181036000830152611b3d81611b01565b9050919050565b7f504b5048656c7065723a206164647265737320616e642073636f70652061727260008201527f6179206c656e67746873206d757374206d617463680000000000000000000000602082015250565b6000611ba06035836119cd565b9150611bab82611b44565b604082019050919050565b60006020820190508181036000830152611bcf81611b93565b9050919050565b7f504b5048656c7065723a2061757468206d6574686f64207479706520616e642060008201527f6964206172726179206c656e67746873206d757374206d617463680000000000602082015250565b6000611c32603b836119cd565b9150611c3d82611bd6565b604082019050919050565b60006020820190508181036000830152611c6181611c25565b9050919050565b7f504b5048656c7065723a2061757468206d6574686f64207479706520616e642060008201527f7075626b6579206172726179206c656e67746873206d757374206d6174636800602082015250565b6000611cc4603f836119cd565b9150611ccf82611c68565b604082019050919050565b60006020820190508181036000830152611cf381611cb7565b9050919050565b7f504b5048656c7065723a2061757468206d6574686f64207479706520616e642060008201527f73636f706573206172726179206c656e67746873206d757374206d6174636800602082015250565b6000611d56603f836119cd565b9150611d6182611cfa565b604082019050919050565b60006020820190508181036000830152611d8581611d49565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600081519050919050565b600082825260208201905092915050565b60005b83811015611df5578082015181840152602081019050611dda565b60008484015250505050565b6000611e0c82611dbb565b611e168185611dc6565b9350611e26818560208601611dd7565b611e2f8161111c565b840191505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b611e6f81610f76565b82525050565b6000611e818383611e66565b60208301905092915050565b6000602082019050919050565b6000611ea582611e3a565b611eaf8185611e45565b9350611eba83611e56565b8060005b83811015611eeb578151611ed28882611e75565b9750611edd83611e8d565b925050600181019050611ebe565b5085935050505092915050565b6000606082019050611f0d60008301866117b1565b8181036020830152611f1f8185611e01565b90508181036040830152611f338184611e9a565b9050949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000611f7782610f76565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203611fa957611fa8611f3d565b5b600182019050919050565b6000606082019050611fc960008301866117b1565b611fd660208301856117db565b8181036040830152611fe88184611e9a565b9050949350505050565b600082825260208201905092915050565b600061200e82611dbb565b6120188185611ff2565b9350612028818560208601611dd7565b6120318161111c565b840191505092915050565b60006060830160008301516120546000860182611e66565b506020830151848203602086015261206c8282612003565b915050604083015184820360408601526120868282612003565b9150508091505092915050565b60006060820190506120a860008301866117b1565b81810360208301526120ba818561203c565b905081810360408301526120ce8184611e9a565b9050949350505050565b6000815190506120e781610f4a565b92915050565b60006020828403121561210357612102610f0e565b5b6000612111848285016120d8565b91505092915050565b600060608201905061212f60008301866117db565b61213c60208301856117db565b61214960408301846117b1565b949350505050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006121ad6026836119cd565b91506121b882612151565b604082019050919050565b600060208201905081810360008301526121dc816121a0565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006122196020836119cd565b9150612224826121e3565b602082019050919050565b600060208201905081810360008301526122488161220c565b905091905056fea264697066735822122078669f1153d945ad96cf00c16f839b5a72d87e1028e11a4661814e6ebb283f8464736f6c634300081100330000000000000000000000008f75a53f65e31dd0d2e40d0827becaae2299d1110000000000000000000000004aed2f242e806c58758677059340e29e6b5b7619
Deployed ByteCode
0x6080604052600436106100915760003560e01c80638da5cb5b116100595780638da5cb5b1461016c57806397016f3f146101975780639fba176b146101c2578063f2fde38b146101f2578063ffa2e9531461021b57610091565b8063150b7a0214610096578063176354fd146100d35780631ea89a22146100fc5780631f71cb3114610125578063715018a614610155575b600080fd5b3480156100a257600080fd5b506100bd60048036038101906100b89190611011565b610246565b6040516100ca91906110d4565b60405180910390f35b3480156100df57600080fd5b506100fa60048036038101906100f591906110ef565b6102eb565b005b34801561010857600080fd5b50610123600480360381019061011e91906110ef565b610337565b005b61013f600480360381019061013a91906115dd565b610383565b60405161014c91906117c0565b60405180910390f35b34801561016157600080fd5b5061016a610b59565b005b34801561017857600080fd5b50610181610b6d565b60405161018e91906117ea565b60405180910390f35b3480156101a357600080fd5b506101ac610b96565b6040516101b99190611864565b60405180910390f35b6101dc60048036038101906101d7919061187f565b610bbc565b6040516101e991906117c0565b60405180910390f35b3480156101fe57600080fd5b50610219600480360381019061021491906110ef565b610d11565b005b34801561022757600080fd5b50610230610d94565b60405161023d91906119b2565b60405180910390f35b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146102d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102cf90611a50565b60405180910390fd5b63150b7a0260e01b905095945050505050565b6102f3610dba565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b61033f610dba565b80600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600080600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16635d228b16348f6040518363ffffffff1660e01b81526004016103e291906117c0565b60206040518083038185885af1158015610400573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906104259190611a85565b90508a518c511461046b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161046290611b24565b60405180910390fd5b88518a51146104af576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104a690611bb6565b60405180910390fd5b86518851146104f3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104ea90611c48565b60405180910390fd5b8551885114610537576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161052e90611cda565b60405180910390fd5b845188511461057b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161057290611d6c565b60405180910390fd5b60008c511461066a5760005b8c5181101561066857600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16638a431578838f84815181106105e2576105e1611d8c565b5b60200260200101518f85815181106105fd576105fc611d8c565b5b60200260200101516040518463ffffffff1660e01b815260040161062393929190611ef8565b600060405180830381600087803b15801561063d57600080fd5b505af1158015610651573d6000803e3d6000fd5b50505050808061066090611f6c565b915050610587565b505b60008a51146107595760005b8a5181101561075757600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16631663c121838d84815181106106d1576106d0611d8c565b5b60200260200101518d85815181106106ec576106eb611d8c565b5b60200260200101516040518463ffffffff1660e01b815260040161071293929190611fb4565b600060405180830381600087803b15801561072c57600080fd5b505af1158015610740573d6000803e3d6000fd5b50505050808061074f90611f6c565b915050610676565b505b60008851146108965760005b885181101561089457600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16639dd4349b8360405180606001604052808d86815181106107cb576107ca611d8c565b5b602002602001015181526020018c86815181106107eb576107ea611d8c565b5b602002602001015181526020018b868151811061080b5761080a611d8c565b5b602002602001015181525089858151811061082957610828611d8c565b5b60200260200101516040518463ffffffff1660e01b815260040161084f93929190612093565b600060405180830381600087803b15801561086957600080fd5b505af115801561087d573d6000803e3d6000fd5b50505050808061088c90611f6c565b915050610765565b505b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663bd4986a0836040518263ffffffff1660e01b81526004016108f391906117c0565b602060405180830381865afa158015610910573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061093491906120ed565b90508415610a1757600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16631663c1218383600067ffffffffffffffff8111156109975761099661112d565b5b6040519080825280602002602001820160405280156109c55781602001602082028036833780820191505090505b506040518463ffffffff1660e01b81526004016109e493929190611fb4565b600060405180830381600087803b1580156109fe57600080fd5b505af1158015610a12573d6000803e3d6000fd5b505050505b8315610ab357600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166342842e0e3083856040518463ffffffff1660e01b8152600401610a7c9392919061211a565b600060405180830381600087803b158015610a9657600080fd5b505af1158015610aaa573d6000803e3d6000fd5b50505050610b45565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166342842e0e3033856040518463ffffffff1660e01b8152600401610b129392919061211a565b600060405180830381600087803b158015610b2c57600080fd5b505af1158015610b40573d6000803e3d6000fd5b505050505b81925050509b9a5050505050505050505050565b610b61610dba565b610b6b6000610e38565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000610d0488600067ffffffffffffffff811115610bdd57610bdc61112d565b5b604051908082528060200260200182016040528015610c1057816020015b6060815260200190600190039081610bfb5790505b50600067ffffffffffffffff811115610c2c57610c2b61112d565b5b604051908082528060200260200182016040528015610c5f57816020015b6060815260200190600190039081610c4a5790505b50600067ffffffffffffffff811115610c7b57610c7a61112d565b5b604051908082528060200260200182016040528015610ca95781602001602082028036833780820191505090505b50600067ffffffffffffffff811115610cc557610cc461112d565b5b604051908082528060200260200182016040528015610cf857816020015b6060815260200190600190039081610ce35790505b508c8c8c8c8c8c610383565b9050979650505050505050565b610d19610dba565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610d88576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d7f906121c3565b60405180910390fd5b610d9181610e38565b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610dc2610efc565b73ffffffffffffffffffffffffffffffffffffffff16610de0610b6d565b73ffffffffffffffffffffffffffffffffffffffff1614610e36576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e2d9061222f565b60405180910390fd5b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600033905090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610f4382610f18565b9050919050565b610f5381610f38565b8114610f5e57600080fd5b50565b600081359050610f7081610f4a565b92915050565b6000819050919050565b610f8981610f76565b8114610f9457600080fd5b50565b600081359050610fa681610f80565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f840112610fd157610fd0610fac565b5b8235905067ffffffffffffffff811115610fee57610fed610fb1565b5b60208301915083600182028301111561100a57611009610fb6565b5b9250929050565b60008060008060006080868803121561102d5761102c610f0e565b5b600061103b88828901610f61565b955050602061104c88828901610f61565b945050604061105d88828901610f97565b935050606086013567ffffffffffffffff81111561107e5761107d610f13565b5b61108a88828901610fbb565b92509250509295509295909350565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6110ce81611099565b82525050565b60006020820190506110e960008301846110c5565b92915050565b60006020828403121561110557611104610f0e565b5b600061111384828501610f61565b91505092915050565b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6111658261111c565b810181811067ffffffffffffffff821117156111845761118361112d565b5b80604052505050565b6000611197610f04565b90506111a3828261115c565b919050565b600067ffffffffffffffff8211156111c3576111c261112d565b5b602082029050602081019050919050565b600080fd5b600067ffffffffffffffff8211156111f4576111f361112d565b5b6111fd8261111c565b9050602081019050919050565b82818337600083830152505050565b600061122c611227846111d9565b61118d565b905082815260208101848484011115611248576112476111d4565b5b61125384828561120a565b509392505050565b600082601f8301126112705761126f610fac565b5b8135611280848260208601611219565b91505092915050565b600061129c611297846111a8565b61118d565b905080838252602082019050602084028301858111156112bf576112be610fb6565b5b835b8181101561130657803567ffffffffffffffff8111156112e4576112e3610fac565b5b8086016112f1898261125b565b855260208501945050506020810190506112c1565b5050509392505050565b600082601f83011261132557611324610fac565b5b8135611335848260208601611289565b91505092915050565b600067ffffffffffffffff8211156113595761135861112d565b5b602082029050602081019050919050565b600067ffffffffffffffff8211156113855761138461112d565b5b602082029050602081019050919050565b60006113a96113a48461136a565b61118d565b905080838252602082019050602084028301858111156113cc576113cb610fb6565b5b835b818110156113f557806113e18882610f97565b8452602084019350506020810190506113ce565b5050509392505050565b600082601f83011261141457611413610fac565b5b8135611424848260208601611396565b91505092915050565b600061144061143b8461133e565b61118d565b9050808382526020820190506020840283018581111561146357611462610fb6565b5b835b818110156114aa57803567ffffffffffffffff81111561148857611487610fac565b5b80860161149589826113ff565b85526020850194505050602081019050611465565b5050509392505050565b600082601f8301126114c9576114c8610fac565b5b81356114d984826020860161142d565b91505092915050565b600067ffffffffffffffff8211156114fd576114fc61112d565b5b602082029050602081019050919050565b600061152161151c846114e2565b61118d565b9050808382526020820190506020840283018581111561154457611543610fb6565b5b835b8181101561156d57806115598882610f61565b845260208401935050602081019050611546565b5050509392505050565b600082601f83011261158c5761158b610fac565b5b813561159c84826020860161150e565b91505092915050565b60008115159050919050565b6115ba816115a5565b81146115c557600080fd5b50565b6000813590506115d7816115b1565b92915050565b60008060008060008060008060008060006101608c8e03121561160357611602610f0e565b5b60006116118e828f01610f97565b9b505060208c013567ffffffffffffffff81111561163257611631610f13565b5b61163e8e828f01611310565b9a505060408c013567ffffffffffffffff81111561165f5761165e610f13565b5b61166b8e828f016114b4565b99505060608c013567ffffffffffffffff81111561168c5761168b610f13565b5b6116988e828f01611577565b98505060808c013567ffffffffffffffff8111156116b9576116b8610f13565b5b6116c58e828f016114b4565b97505060a08c013567ffffffffffffffff8111156116e6576116e5610f13565b5b6116f28e828f016113ff565b96505060c08c013567ffffffffffffffff81111561171357611712610f13565b5b61171f8e828f01611310565b95505060e08c013567ffffffffffffffff8111156117405761173f610f13565b5b61174c8e828f01611310565b9450506101008c013567ffffffffffffffff81111561176e5761176d610f13565b5b61177a8e828f016114b4565b93505061012061178c8e828f016115c8565b92505061014061179e8e828f016115c8565b9150509295989b509295989b9093969950565b6117ba81610f76565b82525050565b60006020820190506117d560008301846117b1565b92915050565b6117e481610f38565b82525050565b60006020820190506117ff60008301846117db565b92915050565b6000819050919050565b600061182a61182561182084610f18565b611805565b610f18565b9050919050565b600061183c8261180f565b9050919050565b600061184e82611831565b9050919050565b61185e81611843565b82525050565b60006020820190506118796000830184611855565b92915050565b600080600080600080600060e0888a03121561189e5761189d610f0e565b5b60006118ac8a828b01610f97565b975050602088013567ffffffffffffffff8111156118cd576118cc610f13565b5b6118d98a828b016113ff565b965050604088013567ffffffffffffffff8111156118fa576118f9610f13565b5b6119068a828b01611310565b955050606088013567ffffffffffffffff81111561192757611926610f13565b5b6119338a828b01611310565b945050608088013567ffffffffffffffff81111561195457611953610f13565b5b6119608a828b016114b4565b93505060a06119718a828b016115c8565b92505060c06119828a828b016115c8565b91505092959891949750929550565b600061199c82611831565b9050919050565b6119ac81611991565b82525050565b60006020820190506119c760008301846119a3565b92915050565b600082825260208201905092915050565b7f504b5048656c7065723a206f6e6c792061636365707473207472616e7366657260008201527f732066726f6d2074686520504b504e465420636f6e7472616374000000000000602082015250565b6000611a3a603a836119cd565b9150611a45826119de565b604082019050919050565b60006020820190508181036000830152611a6981611a2d565b9050919050565b600081519050611a7f81610f80565b92915050565b600060208284031215611a9b57611a9a610f0e565b5b6000611aa984828501611a70565b91505092915050565b7f504b5048656c7065723a20697066732063696420616e642073636f706520617260008201527f726179206c656e67746873206d757374206d6174636800000000000000000000602082015250565b6000611b0e6036836119cd565b9150611b1982611ab2565b604082019050919050565b60006020820190508181036000830152611b3d81611b01565b9050919050565b7f504b5048656c7065723a206164647265737320616e642073636f70652061727260008201527f6179206c656e67746873206d757374206d617463680000000000000000000000602082015250565b6000611ba06035836119cd565b9150611bab82611b44565b604082019050919050565b60006020820190508181036000830152611bcf81611b93565b9050919050565b7f504b5048656c7065723a2061757468206d6574686f64207479706520616e642060008201527f6964206172726179206c656e67746873206d757374206d617463680000000000602082015250565b6000611c32603b836119cd565b9150611c3d82611bd6565b604082019050919050565b60006020820190508181036000830152611c6181611c25565b9050919050565b7f504b5048656c7065723a2061757468206d6574686f64207479706520616e642060008201527f7075626b6579206172726179206c656e67746873206d757374206d6174636800602082015250565b6000611cc4603f836119cd565b9150611ccf82611c68565b604082019050919050565b60006020820190508181036000830152611cf381611cb7565b9050919050565b7f504b5048656c7065723a2061757468206d6574686f64207479706520616e642060008201527f73636f706573206172726179206c656e67746873206d757374206d6174636800602082015250565b6000611d56603f836119cd565b9150611d6182611cfa565b604082019050919050565b60006020820190508181036000830152611d8581611d49565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600081519050919050565b600082825260208201905092915050565b60005b83811015611df5578082015181840152602081019050611dda565b60008484015250505050565b6000611e0c82611dbb565b611e168185611dc6565b9350611e26818560208601611dd7565b611e2f8161111c565b840191505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b611e6f81610f76565b82525050565b6000611e818383611e66565b60208301905092915050565b6000602082019050919050565b6000611ea582611e3a565b611eaf8185611e45565b9350611eba83611e56565b8060005b83811015611eeb578151611ed28882611e75565b9750611edd83611e8d565b925050600181019050611ebe565b5085935050505092915050565b6000606082019050611f0d60008301866117b1565b8181036020830152611f1f8185611e01565b90508181036040830152611f338184611e9a565b9050949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000611f7782610f76565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203611fa957611fa8611f3d565b5b600182019050919050565b6000606082019050611fc960008301866117b1565b611fd660208301856117db565b8181036040830152611fe88184611e9a565b9050949350505050565b600082825260208201905092915050565b600061200e82611dbb565b6120188185611ff2565b9350612028818560208601611dd7565b6120318161111c565b840191505092915050565b60006060830160008301516120546000860182611e66565b506020830151848203602086015261206c8282612003565b915050604083015184820360408601526120868282612003565b9150508091505092915050565b60006060820190506120a860008301866117b1565b81810360208301526120ba818561203c565b905081810360408301526120ce8184611e9a565b9050949350505050565b6000815190506120e781610f4a565b92915050565b60006020828403121561210357612102610f0e565b5b6000612111848285016120d8565b91505092915050565b600060608201905061212f60008301866117db565b61213c60208301856117db565b61214960408301846117b1565b949350505050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006121ad6026836119cd565b91506121b882612151565b604082019050919050565b600060208201905081810360008301526121dc816121a0565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006122196020836119cd565b9150612224826121e3565b602082019050919050565b600060208201905081810360008301526122488161220c565b905091905056fea264697066735822122078669f1153d945ad96cf00c16f839b5a72d87e1028e11a4661814e6ebb283f8464736f6c63430008110033