-
Notifications
You must be signed in to change notification settings - Fork 588
Checkout #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Checkout #570
Changes from 1 commit
b3cb8a8
0efc4ef
ab7f9ff
24ea7e0
5cc0d30
e5d2b7b
30a9590
6d73171
901536d
567f884
6da7d87
3d01b81
7fae585
30a12a0
c0eb3f2
0e623b1
7bb039b
c41601a
5af284d
3c37ec4
9d3b113
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| pragma solidity ^0.8.11; | ||
|
|
||
| import "@openzeppelin/contracts/proxy/Clones.sol"; | ||
|
|
||
| import "./ICheckout.sol"; | ||
| import "./Vault.sol"; | ||
| import "./Executor.sol"; | ||
|
|
||
| import "../../../external-deps/openzeppelin/utils/Create2.sol"; | ||
|
|
||
| import "../../../extension/PermissionsEnumerable.sol"; | ||
|
|
||
| // $$\ $$\ $$\ $$\ $$\ | ||
| // $$ | $$ | \__| $$ | $$ | | ||
| // $$$$$$\ $$$$$$$\ $$\ $$$$$$\ $$$$$$$ |$$\ $$\ $$\ $$$$$$\ $$$$$$$\ | ||
| // \_$$ _| $$ __$$\ $$ |$$ __$$\ $$ __$$ |$$ | $$ | $$ |$$ __$$\ $$ __$$\ | ||
| // $$ | $$ | $$ |$$ |$$ | \__|$$ / $$ |$$ | $$ | $$ |$$$$$$$$ |$$ | $$ | | ||
| // $$ |$$\ $$ | $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ | | ||
| // \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ | | ||
| // \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/ | ||
|
|
||
| contract Checkout is PermissionsEnumerable, ICheckout { | ||
| /// @dev Registry of vaults created through this Checkout | ||
| mapping(address => bool) isVaultRegistered; | ||
|
|
||
| /// @dev Registry of executors created through this Checkout | ||
| mapping(address => bool) isExecutorRegistered; | ||
|
|
||
| address public immutable vaultImplementation; | ||
| address public immutable executorImplementation; | ||
|
|
||
| constructor( | ||
| address _defaultAdmin, | ||
| address _vaultImplementation, | ||
| address _executorImplementation | ||
| ) { | ||
| vaultImplementation = _vaultImplementation; | ||
| executorImplementation = _executorImplementation; | ||
|
|
||
| _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); | ||
| } | ||
|
|
||
| function createVault(address _vaultAdmin, bytes32 _salt) external payable returns (address) { | ||
| bytes32 salthash = keccak256(abi.encodePacked(msg.sender, _salt)); | ||
| address vault = Clones.cloneDeterministic(vaultImplementation, salthash); | ||
|
|
||
| (bool success, ) = vault.call(abi.encodeWithSelector(Vault.initialize.selector, _vaultAdmin)); | ||
|
|
||
| require(success, "Deployment failed"); | ||
|
|
||
| isVaultRegistered[vault] = true; | ||
|
|
||
| return vault; | ||
| } | ||
|
Comment on lines
+40
to
+53
Check warningCode scanning / Slither Low-level calls
Low level call in Checkout.createVault(address,bytes32) (contracts/prebuilts/unaudited/checkout/Checkout.sol#44-57):
- (success) = vault.call(abi.encodeWithSelector(Vault.initialize.selector,_vaultAdmin)) (contracts/prebuilts/unaudited/checkout/Checkout.sol#48)
Comment on lines
+40
to
+53
Check noticeCode scanning / Slither Reentrancy vulnerabilities
Reentrancy in Checkout.createVault(address,bytes32) (contracts/prebuilts/unaudited/checkout/Checkout.sol#44-57):
External calls:
- (success) = vault.call(abi.encodeWithSelector(Vault.initialize.selector,_vaultAdmin)) (contracts/prebuilts/unaudited/checkout/Checkout.sol#48)
Event emitted after the call(s):
- VaultCreated(vault,_vaultAdmin) (contracts/prebuilts/unaudited/checkout/Checkout.sol#54)
|
||
|
|
||
| function createExecutor(address _executorAdmin, bytes32 _salt) external payable returns (address) { | ||
| bytes32 salthash = keccak256(abi.encodePacked(msg.sender, _salt)); | ||
| address executor = Clones.cloneDeterministic(executorImplementation, salthash); | ||
|
|
||
| (bool success, ) = executor.call(abi.encodeWithSelector(Executor.initialize.selector, _executorAdmin)); | ||
|
|
||
| require(success, "Deployment failed"); | ||
|
|
||
| isExecutorRegistered[executor] = true; | ||
|
|
||
| return executor; | ||
| } | ||
|
Comment on lines
+55
to
+68
Check noticeCode scanning / Slither Reentrancy vulnerabilities
Reentrancy in Checkout.createExecutor(address,bytes32) (contracts/prebuilts/unaudited/checkout/Checkout.sol#59-72):
External calls:
- (success) = executor.call(abi.encodeWithSelector(Executor.initialize.selector,_executorAdmin)) (contracts/prebuilts/unaudited/checkout/Checkout.sol#63)
State variables written after the call(s):
- isExecutorRegistered[executor] = true (contracts/prebuilts/unaudited/checkout/Checkout.sol#67)
Comment on lines
+55
to
+68
Check warningCode scanning / Slither Low-level calls
Low level call in Checkout.createExecutor(address,bytes32) (contracts/prebuilts/unaudited/checkout/Checkout.sol#59-72):
- (success) = executor.call(abi.encodeWithSelector(Executor.initialize.selector,_executorAdmin)) (contracts/prebuilts/unaudited/checkout/Checkout.sol#63)
Comment on lines
+55
to
+68
Check noticeCode scanning / Slither Reentrancy vulnerabilities
Reentrancy in Checkout.createExecutor(address,bytes32) (contracts/prebuilts/unaudited/checkout/Checkout.sol#59-72):
External calls:
- (success) = executor.call(abi.encodeWithSelector(Executor.initialize.selector,_executorAdmin)) (contracts/prebuilts/unaudited/checkout/Checkout.sol#63)
Event emitted after the call(s):
- ExecutorCreated(executor,_executorAdmin) (contracts/prebuilts/unaudited/checkout/Checkout.sol#69)
|
||
|
|
||
| function authorizeVaultToExecutor(address _vault, address _executor) external { | ||
| require(IVault(_vault).canAuthorizeVaultToExecutor(msg.sender), "Not authorized"); | ||
| require(isExecutorRegistered[_executor], "Executor not found"); | ||
|
|
||
| IVault(_vault).setExecutor(_executor); | ||
| } | ||
|
Comment on lines
+70
to
+77
Check noticeCode scanning / Slither Reentrancy vulnerabilities
Reentrancy in Checkout.authorizeVaultToExecutor(address,address) (contracts/prebuilts/unaudited/checkout/Checkout.sol#74-81):
External calls:
- IVault(_vault).setExecutor(_executor) (contracts/prebuilts/unaudited/checkout/Checkout.sol#78)
Event emitted after the call(s):
- VaultAuthorizedToExecutor(_vault,_executor) (contracts/prebuilts/unaudited/checkout/Checkout.sol#80)
|
||
| } | ||
|
Comment on lines
+23
to
+78
Check warningCode scanning / Slither Contracts that lock Ether
Contract locking ether found:
Contract Checkout (contracts/prebuilts/unaudited/checkout/Checkout.sol#23-82) has payable functions:
- ICheckout.createVault(address,bytes32) (contracts/prebuilts/unaudited/checkout/interface/ICheckout.sol#14)
- ICheckout.createExecutor(address,bytes32) (contracts/prebuilts/unaudited/checkout/interface/ICheckout.sol#16)
- Checkout.createVault(address,bytes32) (contracts/prebuilts/unaudited/checkout/Checkout.sol#44-57)
- Checkout.createExecutor(address,bytes32) (contracts/prebuilts/unaudited/checkout/Checkout.sol#59-72)
But does not have a function to withdraw the ether
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| pragma solidity ^0.8.11; | ||
|
|
||
| import "./IExecutor.sol"; | ||
| import "./IVault.sol"; | ||
|
|
||
| import "../../../lib/CurrencyTransferLib.sol"; | ||
| import "../../../eip/interface/IERC20.sol"; | ||
|
|
||
| import "../../../extension/PermissionsEnumerable.sol"; | ||
| import "../../../extension/Initializable.sol"; | ||
|
|
||
| // $$\ $$\ $$\ $$\ $$\ | ||
| // $$ | $$ | \__| $$ | $$ | | ||
| // $$$$$$\ $$$$$$$\ $$\ $$$$$$\ $$$$$$$ |$$\ $$\ $$\ $$$$$$\ $$$$$$$\ | ||
| // \_$$ _| $$ __$$\ $$ |$$ __$$\ $$ __$$ |$$ | $$ | $$ |$$ __$$\ $$ __$$\ | ||
| // $$ | $$ | $$ |$$ |$$ | \__|$$ / $$ |$$ | $$ | $$ |$$$$$$$$ |$$ | $$ | | ||
| // $$ |$$\ $$ | $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ | | ||
| // \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ | | ||
| // \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/ | ||
|
|
||
| contract Executor is Initializable, PermissionsEnumerable, IExecutor { | ||
| constructor() { | ||
| _disableInitializers(); | ||
| } | ||
|
|
||
| function initialize(address _defaultAdmin) external initializer { | ||
| _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); | ||
| } | ||
|
|
||
| receive() external payable {} | ||
|
|
||
| function execute(UserOp calldata op) external { | ||
| require(_canExecute(), "Not authorized"); | ||
|
|
||
| if (op.valueToSend != 0) { | ||
| IVault(op.vault).transferTokensToExecutor(op.currency, op.valueToSend); | ||
| } | ||
|
|
||
| bool success; | ||
| if (op.currency == CurrencyTransferLib.NATIVE_TOKEN) { | ||
| (success, ) = op.target.call{ value: op.valueToSend }(op.data); | ||
| } else { | ||
| if (op.approvalRequired) { | ||
| IERC20(op.currency).approve(op.target, op.valueToSend); | ||
| } | ||
|
|
||
| (success, ) = op.target.call(op.data); | ||
| } | ||
|
|
||
| require(success, "Execution failed"); | ||
| } | ||
|
Comment on lines
+37
to
+56
Check warningCode scanning / Slither Unused return
Executor.execute(IExecutor.UserOp) (contracts/prebuilts/unaudited/checkout/Executor.sol#37-56) ignores return value by IERC20(op.currency).approve(op.target,op.valueToSend) (contracts/prebuilts/unaudited/checkout/Executor.sol#49)
Comment on lines
+37
to
+56
Check warningCode scanning / Slither Low-level calls
Low level call in Executor.execute(IExecutor.UserOp) (contracts/prebuilts/unaudited/checkout/Executor.sol#37-56):
- (success,None) = op.target.call{value: op.valueToSend}(op.data) (contracts/prebuilts/unaudited/checkout/Executor.sol#46)
- (success,None) = op.target.call(op.data) (contracts/prebuilts/unaudited/checkout/Executor.sol#52)
|
||
|
|
||
| function _canExecute() internal view returns (bool) { | ||
| return hasRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| pragma solidity ^0.8.11; | ||
|
|
||
| interface ICheckout { | ||
| function createVault(address _vaultAdmin, bytes32 _salt) external payable returns (address); | ||
|
|
||
| function createExecutor(address _executorAdmin, bytes32 _salt) external payable returns (address); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| pragma solidity ^0.8.11; | ||
|
|
||
| interface IExecutor { | ||
| /** | ||
| * @notice Details of the transaction to execute on target contract. | ||
| * | ||
| * @param target Address to send the transaction to | ||
| * | ||
| * @param currency Represents both native token and erc20 token | ||
| * | ||
| * @param vault Vault providing liquidity for this transaction | ||
| * | ||
| * @param approvalRequired If need to approve erc20 to the target contract | ||
| * | ||
| * @param valueToSend Transaction value to send - both native and erc20 | ||
| * | ||
| * @param data Transaction calldata | ||
| */ | ||
| struct UserOp { | ||
| address target; | ||
| address currency; | ||
| address vault; | ||
| bool approvalRequired; | ||
| uint256 valueToSend; | ||
| bytes data; | ||
| } | ||
|
|
||
| function execute(UserOp calldata op) external; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| pragma solidity ^0.8.11; | ||
|
|
||
| interface IVault { | ||
| /// @dev Emitted when contract admin withdraws tokens. | ||
| event TokensWithdrawn(address _token, uint256 _amount); | ||
|
|
||
| /// @dev Emitted when contract admin deposits tokens. | ||
| event TokensDeposited(address _token, uint256 _amount); | ||
|
|
||
| /// @dev Emitted when executor contract withdraws tokens. | ||
| event TokensTransferredToExecutor(address indexed _executor, address _token, uint256 _amount); | ||
|
|
||
| function transferTokensToExecutor(address _token, uint256 _amount) external; | ||
|
|
||
| function setExecutor(address _executor) external; | ||
|
|
||
| function canAuthorizeVaultToExecutor(address _expectedAdmin) external view returns (bool); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| pragma solidity ^0.8.11; | ||
|
|
||
| import "./IVault.sol"; | ||
|
|
||
| import "../../../lib/CurrencyTransferLib.sol"; | ||
| import "../../../eip/interface/IERC20.sol"; | ||
|
|
||
| import "../../../extension/PermissionsEnumerable.sol"; | ||
| import "../../../extension/Initializable.sol"; | ||
|
|
||
| // $$\ $$\ $$\ $$\ $$\ | ||
| // $$ | $$ | \__| $$ | $$ | | ||
| // $$$$$$\ $$$$$$$\ $$\ $$$$$$\ $$$$$$$ |$$\ $$\ $$\ $$$$$$\ $$$$$$$\ | ||
| // \_$$ _| $$ __$$\ $$ |$$ __$$\ $$ __$$ |$$ | $$ | $$ |$$ __$$\ $$ __$$\ | ||
| // $$ | $$ | $$ |$$ |$$ | \__|$$ / $$ |$$ | $$ | $$ |$$$$$$$$ |$$ | $$ | | ||
| // $$ |$$\ $$ | $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ | | ||
| // \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ | | ||
| // \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/ | ||
|
|
||
| contract Vault is Initializable, PermissionsEnumerable, IVault { | ||
| /// @dev Mapping from token address to total balance in the vault. | ||
| mapping(address => uint256) public tokenBalance; | ||
|
|
||
| /// @dev Address of the executor for this vault. | ||
| address public executor; | ||
|
|
||
| /// @dev Address of the Checkout entrypoint. | ||
| address public checkout; | ||
|
|
||
| constructor() { | ||
| _disableInitializers(); | ||
| } | ||
|
|
||
| function initialize(address _defaultAdmin) external initializer { | ||
| checkout = msg.sender; | ||
| _setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin); | ||
| } | ||
|
|
||
| function deposit(address _token, uint256 _amount) external payable { | ||
| require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "Not authorized"); | ||
|
|
||
| uint256 _actualAmount; | ||
|
|
||
| if (_token == CurrencyTransferLib.NATIVE_TOKEN) { | ||
| require(msg.value == _amount, "!Amount"); | ||
| _actualAmount = _amount; | ||
|
|
||
| tokenBalance[_token] += _actualAmount; | ||
| } else { | ||
| uint256 balanceBefore = IERC20(_token).balanceOf(address(this)); | ||
| CurrencyTransferLib.safeTransferERC20(_token, msg.sender, address(this), _amount); | ||
| _actualAmount = IERC20(_token).balanceOf(address(this)) - balanceBefore; | ||
|
|
||
| tokenBalance[_token] += _actualAmount; | ||
| } | ||
|
|
||
| emit TokensDeposited(_token, _actualAmount); | ||
| } | ||
|
|
||
| function withdraw(address _token, uint256 _amount) external { | ||
| require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "Not authorized"); | ||
|
|
||
| uint256 balance = tokenBalance[_token]; | ||
| // to prevent locking of direct-transferred tokens | ||
| tokenBalance[_token] = _amount > balance ? 0 : balance - _amount; | ||
|
|
||
| CurrencyTransferLib.transferCurrency(_token, address(this), msg.sender, _amount); | ||
|
|
||
| emit TokensWithdrawn(_token, _amount); | ||
| } | ||
|
Comment on lines
+55
to
+67
Check noticeCode scanning / Slither Reentrancy vulnerabilities
Reentrancy in Vault.transferTokensToExecutor(address,uint256) (contracts/prebuilts/unaudited/checkout/Vault.sol#55-67):
External calls:
- CurrencyTransferLib.transferCurrency(_token,address(this),msg.sender,_amount) (contracts/prebuilts/unaudited/checkout/Vault.sol#64)
Event emitted after the call(s):
- TokensTransferredToExecutor(msg.sender,_token,_amount) (contracts/prebuilts/unaudited/checkout/Vault.sol#66)
|
||
|
|
||
| function transferTokensToExecutor(address _token, uint256 _amount) external { | ||
| require(_canTransferTokens(), "Not authorized"); | ||
|
|
||
| uint256 balance = tokenBalance[_token]; | ||
| require(balance >= _amount, "Not enough balance"); | ||
|
|
||
| tokenBalance[_token] -= _amount; | ||
|
|
||
| CurrencyTransferLib.transferCurrency(_token, address(this), msg.sender, _amount); | ||
|
|
||
| emit TokensTransferredToExecutor(msg.sender, _token, _amount); | ||
| } | ||
|
Comment on lines
+69
to
+84
Check noticeCode scanning / Slither Reentrancy vulnerabilities
Reentrancy in Vault.swapAndTransferTokensToExecutor(address,uint256,ISwap.SwapOp) (contracts/prebuilts/unaudited/checkout/Vault.sol#69-84):
External calls:
- _swap(_swapOp) (contracts/prebuilts/unaudited/checkout/Vault.sol#73)
- (success,None) = _router.call{value: amountIn}(_swapOp.swapCalldata) (contracts/prebuilts/unaudited/checkout/Vault.sol#112)
- IERC20(_tokenIn).approve(_swapOp.router,amountIn) (contracts/prebuilts/unaudited/checkout/Vault.sol#114)
- (success,None) = _router.call(_swapOp.swapCalldata) (contracts/prebuilts/unaudited/checkout/Vault.sol#115)
- CurrencyTransferLib.transferCurrency(_token,address(this),msg.sender,_amount) (contracts/prebuilts/unaudited/checkout/Vault.sol#81)
External calls sending eth:
- _swap(_swapOp) (contracts/prebuilts/unaudited/checkout/Vault.sol#73)
- (success,None) = _router.call{value: amountIn}(_swapOp.swapCalldata) (contracts/prebuilts/unaudited/checkout/Vault.sol#112)
Event emitted after the call(s):
- TokensTransferredToExecutor(msg.sender,_token,_amount) (contracts/prebuilts/unaudited/checkout/Vault.sol#83)
|
||
|
|
||
| function setExecutor(address _executor) external { | ||
| require(_canSetExecutor(), "Not authorized"); | ||
|
|
||
| executor = _executor; | ||
| } | ||
|
|
||
| function canAuthorizeVaultToExecutor(address _expectedAdmin) external view returns (bool) { | ||
| return hasRole(DEFAULT_ADMIN_ROLE, _expectedAdmin); | ||
| } | ||
|
|
||
| function _canSetExecutor() internal view returns (bool) { | ||
| return msg.sender == checkout; | ||
| } | ||
|
|
||
| function _canTransferTokens() internal view returns (bool) { | ||
| return msg.sender == executor; | ||
| } | ||
| } | ||
Check notice
Code scanning / Slither
Reentrancy vulnerabilities