fix overflow checks

This commit is contained in:
Ricardo Guilherme Schmidt
2023-09-25 18:33:23 -03:00
parent 3f95a3bcf9
commit c64845eddc
3 changed files with 17 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
| contracts/MiniMeToken.sol:MiniMeToken contract | | | | | |
|------------------------------------------------|-----------------|---------|---------|---------|---------|
| Deployment Cost | Deployment Size | | | | |
| 1793495 | 9955 | | | | |
| 1804309 | 10009 | | | | |
| Function Name | min | avg | median | max | # calls |
| allowance | 808 | 808 | 808 | 808 | 3 |
| approve | 30781 | 31244 | 31244 | 31708 | 2 |
@@ -9,26 +9,26 @@
| balanceOfAt | 1142 | 2585 | 2363 | 3603 | 26 |
| changeController | 758 | 1318 | 758 | 3558 | 5 |
| controller | 2447 | 2447 | 2447 | 2447 | 6 |
| createCloneToken | 1838245 | 1838245 | 1838245 | 1838245 | 2 |
| createCloneToken | 1849066 | 1849066 | 1849066 | 1849066 | 2 |
| decimals | 294 | 294 | 294 | 294 | 6 |
| destroyTokens | 9001 | 9001 | 9001 | 9001 | 1 |
| generateTokens | 2541 | 82077 | 94498 | 95796 | 11 |
| generateTokens | 2541 | 82088 | 94510 | 95808 | 11 |
| name | 3253 | 3253 | 3253 | 3253 | 6 |
| parentSnapShotBlock | 284 | 284 | 284 | 284 | 7 |
| parentToken | 305 | 305 | 305 | 305 | 7 |
| symbol | 3274 | 3274 | 3274 | 3274 | 6 |
| totalSupply | 1911 | 2917 | 1911 | 4930 | 6 |
| totalSupplyAt | 1995 | 3028 | 3003 | 4603 | 7 |
| transfer | 75187 | 75187 | 75187 | 75187 | 1 |
| transferFrom | 3495 | 48093 | 66590 | 74194 | 3 |
| transfer | 75193 | 75193 | 75193 | 75193 | 1 |
| transferFrom | 3495 | 48097 | 66596 | 74200 | 3 |
| contracts/MiniMeTokenFactory.sol:MiniMeTokenFactory contract | | | | | |
|--------------------------------------------------------------|-----------------|---------|---------|---------|---------|
| Deployment Cost | Deployment Size | | | | |
| 2118450 | 10613 | | | | |
| 2129265 | 10667 | | | | |
| Function Name | min | avg | median | max | # calls |
| createCloneToken | 1830667 | 1830667 | 1830667 | 1830667 | 2 |
| createCloneToken | 1841488 | 1841488 | 1841488 | 1841488 | 2 |

View File

@@ -1,14 +1,14 @@
AllowanceTest:testAllowance() (gas: 244285)
AllowanceTest:testAllowance() (gas: 244303)
AllowanceTest:testDeployment() (gas: 45814)
CreateCloneTokenTest:testCreateCloneToken() (gas: 2171532)
CreateCloneTokenTest:testCreateCloneToken() (gas: 2182389)
CreateCloneTokenTest:testDeployment() (gas: 45769)
CreateCloneTokenTest:testGenerateTokens() (gas: 2050854)
CreateCloneTokenTest:testGenerateTokens() (gas: 2061699)
DestroyTokensTest:testDeployment() (gas: 45598)
DestroyTokensTest:testDestroyTokens() (gas: 124930)
DestroyTokensTest:testDestroyTokens() (gas: 124942)
GenerateTokensTest:testDeployment() (gas: 45553)
GenerateTokensTest:testGenerateTokens() (gas: 114609)
GenerateTokensTest:testGenerateTokens() (gas: 114621)
GenerateTokensTest:test_RevertWhen_SenderIsNotController() (gas: 14930)
MiniMeTokenTest:testDeployment() (gas: 45598)
ReentrancyTest:testAttack() (gas: 229376)
ReentrancyTest:testAttack() (gas: 229394)
TransferTest:testDeployment() (gas: 45814)
TransferTest:testTransfer() (gas: 201263)
TransferTest:testTransfer() (gas: 201281)

View File

@@ -173,7 +173,7 @@ abstract contract MiniMeBase is Controlled, IERC20 {
// Then update the balance array with the new value for the address
// receiving the tokens
uint256 previousBalanceTo = balanceOfAt(_to, block.number);
if (previousBalanceTo + _amount < previousBalanceTo) revert Overflow(); // Check for overflow
if (uint128(previousBalanceTo + _amount) < previousBalanceTo) revert Overflow(); // Check for overflow
updateValueAtNow(balances[_to], previousBalanceTo + _amount);
// Alerts the token controller of the transfer
@@ -310,9 +310,9 @@ abstract contract MiniMeBase is Controlled, IERC20 {
/// @return True if the tokens are generated correctly
function mint(address _owner, uint256 _amount) internal returns (bool) {
uint256 curTotalSupply = totalSupply();
if (curTotalSupply + _amount < curTotalSupply) revert Overflow(); // Check for overflow
if (uint128(curTotalSupply + _amount) < curTotalSupply) revert Overflow(); // Check for overflow
uint256 previousBalanceTo = balanceOf(_owner);
if (previousBalanceTo + _amount < previousBalanceTo) revert Overflow(); // Check for overflow
if (uint128(previousBalanceTo + _amount) < previousBalanceTo) revert Overflow(); // Check for overflow
updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount);
updateValueAtNow(balances[_owner], previousBalanceTo + _amount);
emit Transfer(address(0), _owner, _amount);