Skip to content

Commit

Permalink
tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
TilakMaddy committed Aug 2, 2024
1 parent 8a3d4b4 commit 5dc6ff5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/contract-playground/src/MsgValueInLoop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,34 @@
pragma solidity ^0.8.0;

// COPIED from Slither Wiki

// BAD
contract MsgValueInLoop1 {
mapping(address => uint256) balances;

function bad(address[] memory receivers) public payable {
// BAD for loop
// BAD for loop (uses msg.value inside loop)
for (uint256 i = 0; i < receivers.length; i++) {
balances[receivers[i]] += msg.value;
}
}
}

// GOOD
contract MsgValueOutsideLoop {
mapping(address => uint256) balances;

function good(address[] memory receivers) public payable {
// GOOD for loop (does not use msg.value inside loop)
uint256 total = msg.value;
for (uint256 i = 0; i < receivers.length; i++) {
balances[receivers[i]] += total / receivers.length;
}
}
}

///// MORE BAD EXAMPLES //////

contract MsgValueInLoop2 {
mapping(address => uint256) balances;

Expand Down

0 comments on commit 5dc6ff5

Please sign in to comment.