From f81274738a1da77ceef4d00ed9f3d29520806419 Mon Sep 17 00:00:00 2001 From: Shyngys Shynbolatov Date: Fri, 23 Jul 2021 16:04:22 +0600 Subject: [PATCH] ecoBurning allowance added. Burning is useful when migrating to the new blockchain or to decrease the supply which sort of can affect the demand (increase it). TransferFrom unlimited allowance exploit fixed --- trc20token.sol | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/trc20token.sol b/trc20token.sol index 1e38026..a62ea11 100644 --- a/trc20token.sol +++ b/trc20token.sol @@ -44,14 +44,16 @@ contract TRC20 { return true; } - // 3rd party can spend someone's fund if that person approved it using approve function + // spend 3rd party's approved token amount function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { - require(_value <= allowance[_from][msg.sender]); + require(allowance[_from][msg.sender] >= _value); + allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); + return true; } - // approve 3rd party to spend your tokens + // approve 3rd party to spend/ecoburn your tokens function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); @@ -69,4 +71,18 @@ contract TRC20 { return true; } + + // eco burn tokens of 3rd party + function ecoburnFrom(address _from, uint256 _value) public returns (bool success) { + require(balanceOf[_from] >= _value); + require(allowance[_from][msg.sender] >= _value); + + balanceOf[_from] -= _value; + allowance[_from][msg.sender] -= _value; + totalSupply -= _value; + + emit EcoBurn(_from, _value); + + return true; + } } \ No newline at end of file