# SafeERC20: Does safeIncreaseAllowance have same security issue as approve?

**URL:** <https://forum.openzeppelin.com/t/safeerc20-does-safeincreaseallowance-have-same-security-issue-as-approve/7744>\
**Category:** Security\
**Created:** [May 3, 2021, 2:37pm UTC](https://forum.openzeppelin.com/t/safeerc20-does-safeincreaseallowance-have-same-security-issue-as-approve/7744 "2021-05-03T14:37:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![suranap](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/suranap/32/5481_2.png) [@suranap](https://forum.openzeppelin.com/u/suranap)\
**Post date:** [May 3, 2021, 2:37pm UTC](https://forum.openzeppelin.com/t/safeerc20-does-safeincreaseallowance-have-same-security-issue-as-approve/7744/1 "2021-05-03T14:37:57Z")

</div>

My contract wants to increase a user’s allowance by +5. I simply call `safeIncreaseAllowance(user, 5)` as recommended by the SafeERC20 contract.

An auditor suggested the following:  
`safeIncreaseAllowance(user, 0); safeIncreaseAllowance(user, 5);` This does not make sense to me, as the first call does nothing. I think he’s copying the pattern for `approve`.

**Question** : Is my call above safe with respect to the known vulnerability to `approve`?

Discussion:

I read about the [vulnerability in `approve`](https://blockchain-projects.readthedocs.io/multiple_withdrawal.html). It looks to me like most people are still doing this wrong. AFAIK, the “vulnerability” is only when you send 2 separate approve transactions and the attacker front runs the calls to grab more tokens than intended.

For example, [yearn’s contracts](https://github.com/yearn/yearn-protocol/blob/a22eb5b88cec7698b75d9ea0db02f19b5e6e009b/contracts/strategies/StrategyDAI3pool.sol#L89) do the following:

```
IERC20(want).safeApprove(ypool, 0);
IERC20(want).safeApprove(ypool, _want);

```

How is this safer? The pair of calls is equivalent to calling `approve(ypool, _want)`. But the pair of calls is used to undermine the safety checks in `safeApprove`.

---

<div class="post-metadata">

**Author:** ![Amxx](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/amxx/32/668_2.png) [@Amxx](https://forum.openzeppelin.com/u/Amxx)\
**Post date:** [May 3, 2021, 8:27pm UTC](https://forum.openzeppelin.com/t/safeerc20-does-safeincreaseallowance-have-same-security-issue-as-approve/7744/2 "2021-05-03T20:27:53Z")

</div>

> [@suranap](#):
>
> AFAIK, the “vulnerability” is only when you send 2 separate approve transactions and the attacker front runs the calls to grab more tokens than intended.

Exactly!  
Setting approve twice is not necessary if you know for sure they will be part of the same tx. This is why you don't need to set approval to 0 before doing an "increaseAllowance".

---

<div class="post-metadata">

**Author:** ![suranap](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/suranap/32/5481_2.png) [@suranap](https://forum.openzeppelin.com/u/suranap)\
**Post date:** [May 10, 2021, 2:52pm UTC](https://forum.openzeppelin.com/t/safeerc20-does-safeincreaseallowance-have-same-security-issue-as-approve/7744/3 "2021-05-10T14:52:40Z")

</div>

Thanks. The auditor explained why, and now it makes sense. Some ERC20 contracts (e.g. Tether) changed the behavior of `approve` to look like `safeApprove`. That means you must call `approve(me, 0)` and `approve(me, value)`. If you call `safeIncreaseAllowance` it will fail because approves directly to a new value without going to 0 first.

In fact, this means you can’t use SafeERC20 in a general way because some tokens are broken. We have to modify SafeERC20 to call `approve` twice. That’s too bad.
