Skip to content

Commit

Permalink
ERC20BaseModule improvement + doc
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Jul 31, 2023
1 parent 85151a0 commit a004795
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions contracts/modules/wrapper/mandatory/ERC20BaseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ abstract contract ERC20BaseModule is ERC20Upgradeable {
uint256 value,
uint256 currentAllowance
) public virtual returns (bool) {
address owner = _msgSender();
require(
allowance(_msgSender(), spender) == currentAllowance,
allowance(owner, spender) == currentAllowance,
"CMTAT: current allowance is not right"
);
ERC20Upgradeable.approve(spender, value);
// We call directly the internal function _approve
// The reason is that the public function adds only the owner address recovery
ERC20Upgradeable._approve(owner, spender, value);
return true;
}

Expand Down
10 changes: 10 additions & 0 deletions doc/modules/presentation/mandatory/erc20base.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ returns (bool)
Transfer the given `amount` of tokens from the caller to the given `destination` address.
The function returns `true` on success and reverts on error.

###### Requirements

* `to` cannot be the zero address.
* the caller must have a balance of at least `value`.

##### `approve(address,uint256)`

Origin: OpenZeppelin (ERC20Upgradeable)
Expand Down Expand Up @@ -181,6 +186,11 @@ So, Bob got 210 tokens in total, while Alice never means to allow him to transfe

In order to mitigate this kind of attack, Alice at step 3 calls `approve (bob, 110, 100)`. Such call could only succeed if the allowance is still 100, i.e. Bob's attempt to front run the transaction will make Alice's transaction to fail.

###### Requirement

- The given `currentAllowance` value has to be equal to the amount of token the spender is currently allowed to transfer from the caller.
- `spender`and the sender cannot be the zero address (check made by `OpenZeppelin-_approve`).

##### `transferFrom(address,address,uint256)`

This function overrides the function `transferFrom`from OpenZeppelin
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/presentation/mandatory/mint.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ event Mint(address indexed account, uint256 value)

##### Description

Emitted when the specified `value` amount of new tokens were created and
Emitted when the specified `value` amount of new tokens are created and
allocated to the specified `account`.

0 comments on commit a004795

Please sign in to comment.