35.SWC-135_checkExecution
2023-07-13 15:58:04 # 09.SWC

SWC-135_useless statement

link

1
2
3
4
5
6
7
8
9
10
11
12
13
14
pragma solidity ^0.5.0;

contract DepositBox {
mapping(address => uint) balance;

// Accept deposit
function deposit(uint amount) public payable {
require(msg.value == amount, 'incorrect amount');
// Should update user balance
// balance[msg.sender] == amount;
// fixed
balance[msg.sender] = amount;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
pragma solidity ^0.5.0;

contract Wallet {
mapping(address => uint) balance;

// Deposit funds in contract
function deposit(uint amount) public payable {
require(msg.value == amount, 'msg.value must be equal to amount');
balance[msg.sender] = amount;
}

// Withdraw funds from contract
function withdraw(uint amount) public {
require(amount <= balance[msg.sender], 'amount must be less than balance');

uint previousBalance = balance[msg.sender];
balance[msg.sender] = previousBalance - amount;

// Attempt to send amount from the contract to msg.sender
// msg.sender.call.value(amount);
// fixed:
(bool success, ) = msg.sender.call.value(amount)("");
require(success, 'transfer failed');
// issues#7096,#2707
}
}

We should prevent useless code in contract and ensure the code will produce the intended effects.

Prev
2023-07-13 15:58:04 # 09.SWC
Next