You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🧐 Motivation
The ERC20Permit contract is great in that it provide a building block which is both ERC20 & ERC712 compliant. It also include some features, like nonce management, which are not by default in ERC712 but are required to do proper signature checking in the permit function.
However, when wanting to expand the ERC712 compliant features beyound the simple permit function, it is not possible to increment the counter (private slot). This means that if I wanted to add a transferFromBySig or any other feature using ERC712, I would have to use an independent nonce. This is really not great.
📝 Details
A simple, yet effective, solution is to add an internal function that lets you "consumed" a nonce:
function _useNonce(address owner) internal virtual returns (uint256 current) {
Counters.Counter storage nonce = _nonces[owner];
current = nonce.current();
nonce.increment();
}
Since this function only increment, it doesn't create any security issue that would allow signed messages to be replayed.
The text was updated successfully, but these errors were encountered:
Amxx
changed the title
add an internal _incrementNonces(address) function in ERC20Permit
Add an internal _incrementNonces(address) function in ERC20Permit
Mar 5, 2021
frangio
changed the title
Add an internal _incrementNonces(address) function in ERC20Permit
Add an internal _useNonce(address) function in ERC20Permit
Mar 5, 2021
🧐 Motivation
The ERC20Permit contract is great in that it provide a building block which is both ERC20 & ERC712 compliant. It also include some features, like nonce management, which are not by default in ERC712 but are required to do proper signature checking in the permit function.
However, when wanting to expand the ERC712 compliant features beyound the simple
permit
function, it is not possible to increment the counter (private slot). This means that if I wanted to add atransferFromBySig
or any other feature using ERC712, I would have to use an independent nonce. This is really not great.📝 Details
A simple, yet effective, solution is to add an internal function that lets you "consumed" a nonce:
Since this function only increment, it doesn't create any security issue that would allow signed messages to be replayed.
The text was updated successfully, but these errors were encountered: