Skip to content

Locked ETH in contract rule #25

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions solidity/locked-eth-in-contract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
pragma solidity 0.8.13;

// ruleid: locked-eth-in-contract
contract Test1 {
receive() external payable {}
}

// ruleid: locked-eth-in-contract
contract Test2 {
bool flag;
function get(bool payed) external payable {
if (msg.value > 0){
flag = true;
}
}
}

// ok: locked-eth-in-contract
contract Test3 {
receive() external payable {}

function skim(address payable to) external{
to.send(this(address).balance);
}
}

// ok: locked-eth-in-contract
contract Test4 {
receive() external payable {}

function skim(address payable to) external{
to.transfer(this(address).balance);
}
}

// ok: locked-eth-in-contract
contract Test5 {
receive() external payable {}

function destruct(address payable to) external{
selfdestruct(to);
}
}

// ruleid: locked-eth-in-contract
contract Test6 {
receive() external payable {}

function skim(address payable to) external{
to.call(...);
}
}

// ok: locked-eth-in-contract
contract Test7 {
receive() external payable {}

function skim(address payable to) external{
(bool sent, bytes memory data) = to.call{value: msg.value}("");
}
}
71 changes: 71 additions & 0 deletions solidity/locked-eth-in-contract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
rules:
- id: locked-eth-in-contract
message: Contract supports depositing ETH, but have no direct way to withdraw any ETH balance present in the contract.
languages:
- solidity
severity: WARNING
metadata:
references:
- https://blog.openzeppelin.com/compound-iii-audit/
- https://github.com/compound-finance/comet/commit/36816138e15477d0ac487b9d97affc0d296ccc49
category: security
tags:
- compound
patterns:
- pattern: |
contract $CONTRACT {
...
function $RECEIVE(...) payable {
...
}
...
}
- pattern-not: |
contract $CONTRACT {
...
function $FUNC(...) {
...
$ADDR.call{value: $AMOUNT, gas: $GAS}(...);
}
...
}
- pattern-not: |
contract $CONTRACT {
...
function $FUNC(...) {
...
$ADDR.call{value: $AMOUNT}(...);
}
...
}
- pattern-not: |
contract $CONTRACT {
...
function $FUNC(...) {
...
$ADDR.send(...);
}
...
}
- pattern-not: |
contract $CONTRACT {
...
function $FUNC(...) {
...
$ADDR.transfer($AMOUNT);
}
...
}
- pattern-not: |
contract $CONTRACT {
...
function $FUNC(...) {
...
selfdestruct(...);
}
...
}
- pattern-not-inside: |
abstract contract $CONTRACT {
...
}