approve() call with incorrect function signature will make any SoftVault deployed with USDT as the underlying token unusable
The EnsureApprove contract calls USDT's approve function through a standard IERC20 interface that expects a boolean return value, but USDT's approve returns nothing, causing the call to revert. This makes any SoftVault deployed with USDT as the underlying token unusable, wasting deployment costs.
approve() call with incorrect function signature will make any SoftVault deployed with USDT as the underlying token unusable
Summary
Open Zeppelin's safeTransfer() is used throughout the blueberry contracts, this ensures that calls to contracts without return values don't fail, however, the EnsureApprove contract uses a normal IERC20 interface and a normal approve() function call. Since USDT doesn't return a boolean as expected by the interface, this would leave the contract unusable.
Vulnerability Detail
If a SoftVault is deployed using USDT as the uToken, the contract's main functions won't work as intended since the ensureApprove function call will fail.
USDT approve signature: function approve(address spender, uint value) public;
This will cause loss of funds because the cost to deploy the contract will essentially have been wasted. The developers explicitly stated that they intend to use USDT as an underlying token in the SoftVault's NatSpec:
Actually i do not understand why the issue was closed in the last contest with the comment:
USDT only can call approve function when the allowance is zero or to set the allowance to zero first.
This is not related to the stated issue, that the approval will revert because the generic IERC20 interface is used, which is expecting a bool return data.
nevillehuang
Escalate:
Referring to @Gornutz comment, this was marked as No-Fix and Non-Reward in previous contest, and should be invalid according to sherlock's rules here:
In an update contest, issues from the previous contest with wont fix labels are not considered valid.
In addition, EnsureApprove.sol uses _ensureApprove() directly to approve tokens (for e.g. USDT) for contracts inheriting it, so the issue above of needing an interface is not a problem.
sherlock-admin2
Escalate:
Referring to @Gornutz comment, this was marked as No-Fix and Non-Reward in previous contest, and should be invalid according to sherlock's rules here:
In an update contest, issues from the previous contest with wont fix labels are not considered valid.
In addition, EnsureApprove.sol uses _ensureApprove() directly to approve tokens (for e.g. USDT) for contracts inheriting it, so the issue above of needing an interface is not a problem.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Shogoki
Escalate:
Referring to @Gornutz comment, this was marked as No-Fix and Non-Reward in previous contest, and should be invalid according to sherlock's rules here:
In an update contest, issues from the previous contest with wont fix labels are not considered valid.
Hmm, yep that is kind of an interesting case. I agree, that it is probably fair in terms of rewards to consider this invalid.
However as stated in my comment above, i do not understand the reasoning for closing this in the initial contest.
securitygrid
The function signature only needs the function name and parameters, and does not need a return value.
Shogoki
The function signature only needs the function name and parameters, and does not need a return value.
While this is true for the call, it is still a problem as the transaction will revert because Solidity checks for the expected return size and compares it to the actual returned data size.
nevillehuang
The function signature only needs the function name and parameters, and does not need a return value.
While this is true for the call, it is still a problem as the transaction will revert because Solidity checks for the expected return size and compares it to the actual returned data size.
As @securitygrid said, there will be no reverts, given allowance is approved to zero first. The interface only requires the function selector to match and call the function in the USDT contract check this link here
When a contract is called, the EVM (Ethereum Virtual Machine) reads the first four bytes of the provided data to determine the function selector. The EVM uses this selector to match it with the correct function within the contract. If a match is found, the function is executed. If no match is found, the function call fails.
For example, function signature of approve() here would be bytes4(keccak256("approve(address,uint)"));
Unless there are two approve functions with different number of arguments, this submission seems like only a valid QA/low finding since there is only 1 approve function exposed in USDT contract
securitygrid
@nevillehuang
This problem should be considered from the compiled code:
The compiled code of IERC20(token).approve(spender, 0) is similar to the following:
Solidity
(bool ret, bytes data) = token.call(abi.encodeWithSignature("approve(address,uint256)", spender, 0);
if (ret) {
if (data.length != 1) // since usdt.approve has no return value, so data.length = 0
{
revert;
}
return abi.decode(data, (bool));
} else {
revert;
}
Shogoki
@nevillehuang This problem should be considered from the compiled code: The compiled code of IERC20(token).approve(spender, 0) is similar to the following:
Solidity
(bool ret, bytes data) = token.call(abi.encodeWithSignature("approve(address,uint256)", spender, 0);
if (ret) {
if (data.length != 1) // since usdt.approve has no return vault, so data.length = 0
{
revert;
}
return abi.decode(data, (bool));
} else {
revert;
}
That is correct.
To demonstrate the issue we can use the following litle PoC.
Creating a Contract EnsureApproveTest.sol
Solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
import {EnsureApprove} from "./utils/EnsureApprove.sol" ;
contract EnsureApproveTest is EnsureApprove {
function approveMe(address token, uint256 amount) external {
_ensureApprove(token, msg.sender, amount);
}
}
Running this will result in the 2nd test to fail, because of the mismatching return data length
1 failing
1) Ensure Approve
IERC20 Interface
TEST USDT APPROVAL:
Error: Transaction reverted: function returned an unexpected amount of data
hrishibhat
Result:
Medium
Has duplicates
Considering this a value medium issue based on the discussions above, this was a valid issue that was not acknowledged in the previous contests, but now with additional information is considered a valid medium.
I agree the Wont fix rule might need to be more clear of the conditions to which they are applied
The original report as published on Sherlock, by n1punp. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The contract uses a standard IERC20 interface for approve, which expects a boolean return value, but USDT's approve returns no data, causing a revert due to return data length mismatch.
Impact
The vault becomes unusable, causing loss of funds because the deployment cost is wasted.
What the attacker needed
SoftVault deployed with USDT as underlying token
The fix
Add support for USDT by using an interface with ERC20 functions that do not return values.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
Some tokens like USDT have an approve function that does not return a value, while the standard interface expects a true/false answer. When the contract calls approve through that standard interface, the mismatch makes the transaction fail. As a result, the vault cannot work with USDT.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.