Skip to content

Solidity API

ERC20ExtendedInternal

_Implements safety improvements for the ERC20 allowance mechanism to prevent transaction-ordering vulnerabilities. These vulnerabilities could occur when a token holder submits two different approve transactions in succession, where the second transaction might be mined before the first one.

This contract provides internal functions for increasing and decreasing allowances incrementally, rather than setting them directly, which is safer than the standard approve mechanism._

_increaseAllowance

solidity
function _increaseAllowance(address spender, uint256 amount) internal virtual returns (bool)

Increases the allowance granted to a spender

_This is a safer alternative to standard approve. It lets users increment allowances rather than setting them directly, preventing potential double-spend scenarios.

Security considerations:

  • Checks for overflow in unchecked block to save gas while maintaining safety
  • Reverts if the addition would overflow
  • Uses msg.sender as the token owner to prevent unauthorized allowance modifications_

Parameters

NameTypeDescription
spenderaddressThe address which will be allowed to spend the tokens
amountuint256The amount of tokens to increase the allowance by

Return Values

NameTypeDescription
[0]boolsuccess True if the operation succeeded, reverts otherwise

_decreaseAllowance

solidity
function _decreaseAllowance(address spender, uint256 amount) internal virtual returns (bool)

Decreases the allowance granted to a spender

_Provides a safe way to reduce the amount of tokens that a spender is allowed to withdraw

Security considerations:

  • Cannot decrease allowance below zero (handled by the internal _decreaseAllowance function)
  • Uses msg.sender as the token owner to prevent unauthorized allowance modifications_

Parameters

NameTypeDescription
spenderaddressThe address which will have its allowance decreased
amountuint256The amount of tokens to decrease the allowance by

Return Values

NameTypeDescription
[0]boolsuccess True if the operation succeeded, reverts otherwise