Logic Error due to different representation of Native ETH (0x0 & 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
The vault's initialisation logic incorrectly assumes that native ETH is represented by the alternative ETH address, but the constructor already converts it to the zero address. As a result, the code attempts to approve the zero address as an ERC20 token, which could cause unexpected behaviour during vault initialisation.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-notional-judging/issues/15
Found by
xiaoming90
Summary
Unexpected results might occur during vault initialization if either of the pool's tokens is a Native ETH due to the confusion between Deployments.ETH_ADDRESS (address(0)) and Deployments.ALT_ETH_ADDRESS (0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE).
Vulnerability Detail
The PRIMARY_TOKEN or SECONDARY_TOKEN is explicitly converted to Deployments.ETH_ADDRESS (address(0) during deployment.
File: Curve2TokenPoolMixin.sol
abstract contract Curve2TokenPoolMixin is CurvePoolMixin {
..SNIP..
24: constructor(
25: NotionalProxy notional_,
26: ConvexVaultDeploymentParams memory params
27: ) CurvePoolMixin(notional_, params) {
28: address primaryToken = _getNotionalUnderlyingToken(params.baseParams.primaryBorrowCurrencyId);
29:
30: PRIMARY_TOKEN = primaryToken;
31:
32: // Curve uses ALT_ETH_ADDRESS
33: if (primaryToken == Deployments.ETH_ADDRESS) {
34: primaryToken = Deployments.ALT_ETH_ADDRESS;
35: }
36:
37: address token0 = CURVE_POOL.coins(0);
38: address token1 = CURVE_POOL.coins(1);
39:
40: uint8 primaryIndex;
41: address secondaryToken;
42: if (token0 == primaryToken) {
43: primaryIndex = 0;
44: secondaryToken = token1;
45: } else {
46: primaryIndex = 1;
47: secondaryToken = token0;
48: }
49:
50: if (secondaryToken == Deployments.ALT_ETH_ADDRESS) {
51: secondaryToken = Deployments.ETH_ADDRESS;
52: }
53:
54: PRIMARY_INDEX = primaryIndex;
55: SECONDARY_TOKEN = secondaryToken;
It was observed that there is a logic error within the Curve2TokenConvexVault.initialize function. Based on Lines 56 and 59 within the Curve2TokenConvexVault.initialize function, it assumes that if either the primary or secondary token is ETH, then the PRIMARY_TOKEN or SECONDARY_TOKEN will be set to Deployments.ALT_ETH_ADDRESS, which point to 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE.
However, this is incorrect as the PRIMARY_TOKEN or SECONDARY_TOKEN has already been converted to Deployments.ETH_ADDRESS (address(0)) during deployment. Refer to the constructor of Curve2TokenPoolMixin.
Thus, the PRIMARY_TOKEN or SECONDARY_TOKEN will never be equal to Deployments.ALT_ETH_ADDRESS, and the condition at Lines 56 and 59 will always evaluate to True.
File: Curve2TokenConvexVault.sol
contract Curve2TokenConvexVault is Curve2TokenVaultMixin {
..SNIP..
48: function initialize(InitParams calldata params)
49: external
50: initializer
51: onlyNotionalOwner
52: {
53: __INIT_VAULT(params.name, params.borrowCurrencyId);
54: CurveVaultStorage.setStrategyVaultSettings(params.settings);
55:
56: if (PRIMARY_TOKEN != Deployments.ALT_ETH_ADDRESS) {
57: IERC20(PRIMARY_TOKEN).checkApprove(address(CURVE_POOL), type(uint256).max);
58: }
59: if (SECONDARY_TOKEN != Deployments.ALT_ETH_ADDRESS) {
60: IERC20(SECONDARY_TOKEN).checkApprove(address(CURVE_POOL), type(uint256).max);
61: }
62:
63: CURVE_POOL_TOKEN.checkApprove(address(CONVEX_BOOSTER), type(uint256).max);
64: }
As a result, if the PRIMARY_TOKEN or SECONDARY_TOKEN is Deployments.ETH_ADDRESS (address(0)), the code will go ahead to call the checkApprove function, which might cause unexpected results during vault initialization.
Impact
Unexpected results during vault initialization if either of the pool's tokens is a Native ETH.
Code Snippet
Tool used
Manual Review
Recommendation
If the PRIMARY_TOKEN or SECONDARY_TOKEN is equal to Deployments.ALT_ETH_ADDRESS or Deployments.ETH_ADDRESS, this means that it points to native ETH and the checkApprove can be safely skipped.
function initialize(InitParams calldata params)
external
initializer
onlyNotionalOwner
{
__INIT_VAULT(params.name, params.borrowCurrencyId);
CurveVaultStorage.setStrategyVaultSettings(params.settings);
- if (PRIMARY_TOKEN != Deployments.ALT_ETH_ADDRESS) {
+ if (PRIMARY_TOKEN != Deployments.ALT_ETH_ADDRESS || PRIMARY_TOKEN != Deployments.ETH_ADDRESS) {
IERC20(PRIMARY_TOKEN).checkApprove(address(CURVE_POOL), type(uint256).max);
}
- if (SECONDARY_TOKEN != Deployments.ALT_ETH_ADDRESS) {
+ if (SECONDARY_TOKEN != Deployments.ALT_ETH_ADDRESS || SECONDARY_TOKEN != Deployments.ETH_ADDRESS) {
IERC20(SECONDARY_TOKEN).checkApprove(address(CURVE_POOL), type(uint256).max);
}
CURVE_POOL_TOKEN.checkApprove(address(CONVEX_BOOSTER), type(uint256).max);
}
Discussion
jeffywu
This issue appears valid, however, it's curious that this was not caught in unit tests since we tested against the wstETH/ETH pool which should have tripped this issue.
We can mark it as valid, @weitianjie2000 will investigate more on why the unit tests worked.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The initialisation function checks for the alternative ETH address, but the constructor has already converted native ETH to the zero address, so the condition is always true and the code attempts to approve the zero address.
Impact
Unexpected results during vault initialization if either of the pool's tokens is a Native ETH.
What the attacker needed
Vault initialisation with native ETH pool
The fix
The condition should also check for the zero address (or use a logical AND instead of OR) so that approval is skipped when the token is native ETH.
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.
In Ethereum, native ETH is sometimes represented by a special placeholder address. This project uses two different placeholders: one is the zero address and the other is a specific address starting with 0xEeee. The code checks for the wrong placeholder, so it tries to treat native ETH as a regular token and calls an approval function on it, which can fail or behave unexpectedly.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.