Skip to content

Commit 438a180

Browse files
committed
note approval to zero reverts
1 parent da1d127 commit 438a180

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

readme.md

+9
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ in the wild problems caused by this issue.
155155

156156
*example*: [Approval.sol](./src/Approval.sol)
157157

158+
## Revert on Approval To Zero Address
159+
160+
Some tokens (e.g. OpenZeppelin) will revert if trying to approve the zero address to spend tokens
161+
(i.e. a call to `approve(address(0), amt)`).
162+
163+
Integrators may need to add special cases to handle this logic if working with such a token.
164+
165+
*example*: [ApprovalToZero.sol](./src/ApprovalToZero.sol)
166+
158167
## Revert on Zero Value Transfers
159168

160169
Some tokens (e.g. `LEND`) revert when transfering a zero value amount.

src/ApprovalToZero.sol

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (C) 2020 d-xo
2+
// SPDX-License-Identifier: AGPL-3.0-only
3+
4+
pragma solidity >=0.6.12;
5+
6+
import {ERC20} from "./ERC20.sol";
7+
8+
contract ApprovalToZeroToken is ERC20 {
9+
// --- Init ---
10+
constructor(uint _totalSupply) ERC20(_totalSupply) public {}
11+
12+
// --- Token ---
13+
function approve(address usr, uint wad) override public returns (bool) {
14+
require(usr != address(0), "no approval for the zero address");
15+
return super.approve(usr, wad);
16+
}
17+
}

0 commit comments

Comments
 (0)