DoS for the user's calling stake and stakeReleasableTokensFrom function
The CollateralVault contract allows anyone to call modifyCollateralizableTokenAllowanceWithSignature directly, so an attacker can front-run a user's stake transaction and consume the user's signature, causing the user's transaction to revert with an invalid signature error. This griefing attack repeatedly blocks the user's stake and stakeReleasableTokensFrom calls.
- Disclosed after under an hour
#36552 [SC-Medium] DoS for the user's calling `stake` and `stakeReleasableTokensFrom` function
Submitted on Nov 5th 2024 at 20:34:01 UTC by @savi0ur for Audit Comp | Anvil
- Report ID: #36552
- Report Type: Smart Contract
- Report severity: Medium
- Target: https://etherscan.io/address/0xd042C267758eDDf34B481E1F539d637e41db3e5a
- Impacts:
- Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)
Description
Bug Description
In the `TimeBasedCollateralPool` contract, user can call `stake` and `stakeReleasableTokensFrom` function to stake their tokens. However, both of this functions uses signed signature to modify collateralizable token allowance using `modifyCollateralizableTokenAllowanceWithSignature` function, as shown below.
```solidity function stake( IERC20 _token, uint256 _amount, bytes calldata _collateralizableApprovalSignature ) external withEligibleAccountTokensReleased(msg.sender, address(_token)) returns (uint256) { if (_collateralizableApprovalSignature.length > 0) { collateral.modifyCollateralizableTokenAllowanceWithSignature( msg.sender, address(this), address(_token), Pricing.safeCastToInt256(_amount), _collateralizableApprovalSignature ); // <==== }
return _stake(_token, _amount);
} ```
```solidity function stakeReleasableTokensFrom( ITimeBasedCollateralPool _pool, IERC20 _token, uint256 _amount, bytes calldata _collateralizableApprovalSignature ) external withEligibleAccountTokensReleased(msg.sender, address(_token)) returns (uint256) { if (address(_pool) != address(this)) { IERC20[] memory tokens = new IERC20; tokens[0] = _token; _pool.releaseEligibleTokens(msg.sender, tokens); } if (_collateralizableApprovalSignature.length > 0) { collateral.modifyCollateralizableTokenAllowanceWithSignature( msg.sender, address(this), address(_token), Pricing.safeCastToInt256(_amount), _collateralizableApprovalSignature ); // <==== }
return _stake(_token, _amount);
} ```
Whenever users call this functions, attacker can frontrun their transaction and uses their signed signature to directly call `modifyCollateralizableTokenAllowanceWithSignature` function on `CollateralVault` contract using all the other details from user's tx. Thus user's tx will get reverted due to Invalid Signature error.
As we can see below, `modifyCollateralizableTokenAllowanceWithSignature` function is directly callable with all the details from victim's tx.
```solidity function modifyCollateralizableTokenAllowanceWithSignature( address _accountAddress, address _collateralizableContractAddress, address _tokenAddress, int256 _allowanceAdjustment, bytes calldata _signature ) external { if (_allowanceAdjustment > 0 && !collateralizableContracts[_collateralizableContractAddress]) revert ContractNotApprovedByProtocol(_collateralizableContractAddress);
_modifyCollateralizableTokenAllowanceWithSignature(
_accountAddress,
_collateralizableContractAddress,
_tokenAddress,
_allowanceAdjustment,
_signature
);
}
function _modifyCollateralizableTokenAllowanceWithSignature( address _accountAddress, address _collateralizableContractAddress, address _tokenAddress, int256 _allowanceAdjustment, bytes calldata _signature ) private { { bytes32 hash = _hashTypedDataV4( keccak256( abi.encode( COLLATERALIZABLE_TOKEN_ALLOWANCE_ADJUSTMENT_TYPEHASH, _collateralizableContractAddress, _tokenAddress, _allowanceAdjustment, _useNonce(_accountAddress, COLLATERALIZABLE_TOKEN_ALLOWANCE_ADJUSTMENT_TYPEHASH) ) ) ); if (!SignatureChecker.isValidSignatureNow(_accountAddress, hash, _signature)) { revert InvalidSignature(_accountAddress); // <=== } ```
Attack Scenario
- Alice sign the tx off-chain and submit it to perform `stake`
- While the Alice tx is in mempool, Bob `(Attacker)` can see it, frontrun it, and execute `modifyCollateralizableTokenAllowanceWithSignature` directly on the collateral vault contract with all the necessary details and signature of Alice.
- Alice's tx now executes after Bob's tx and it will get reverted as the signature is already used.
Impact
Attacker can make user's `stake` and `stakeReleasableTokensFrom` tx to always failed.
I'm marking this issue as Medium according to Immunefi's vulnerability classification system : Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol).
> Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol): Griefing is when the attacker calls certain functions of the smart contract that would put it in a suboptimal state, thus blocking normal function execution for any user. This would cause the user to lose money for sending the transaction, but when the smart contract is back to normal, the user would be able to call the function once again to complete it. In this instance, the attacker damaged the user by requiring them to send another transaction. The attacker does not profit, but they do damage the users or the protocol.
Recommendation
Make sure the caller (`msg.sender`) for `modifyCollateralizableTokenAllowanceWithSignature` function in `CollateralVault` contract is approved collateralizable contracts in `collateralizableContracts` mapping as shown below.
```diff function modifyCollateralizableTokenAllowanceWithSignature( address _accountAddress, address _collateralizableContractAddress, address _tokenAddress, int256 _allowanceAdjustment, bytes calldata _signature ) external {
-
if (!collateralizableContracts[msg.sender]) revert Unauthorized(msg.sender); if (_allowanceAdjustment > 0 && !collateralizableContracts[_collateralizableContractAddress]) revert ContractNotApprovedByProtocol(_collateralizableContractAddress);
_modifyCollateralizableTokenAllowanceWithSignature( _accountAddress, _collateralizableContractAddress, _tokenAddress, _allowanceAdjustment, _signature ); } ```
References
- CollateralVault: https://etherscan.io/address/0x5d2725fdE4d7Aa3388DA4519ac0449Cc031d675f?utm\\_source=immunefi
- TimeBasedCollateralPool: https://etherscan.io/address/0xd042C267758eDDf34B481E1F539d637e41db3e5a?utm\\_source=immunefi
Proof of Concept
Proof Of Concept
PoC Secret Gist: https://gist.github.com/pratraut/1a66b395e862383be9945713b89ff035
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
Likely the modifyCollateralizableTokenAllowanceWithSignature function lacks a check that msg.sender is an approved collateralizable contract, allowing anyone to consume signatures.
Impact
An attacker can cause a user's stake and stakeReleasableTokensFrom transactions to always fail, forcing the user to resubmit and pay gas again.
What the attacker needed
Attacker can see pending transactions; victim submits a stake transaction with a signature
The fix
The modifyCollateralizableTokenAllowanceWithSignature function should check that msg.sender is an approved collateralizable contract.
How it was found
- Alice signs a transaction off-chain and submits a stake call.
- Bob sees Alice's transaction in the mempool.
- Bob front-runs by calling modifyCollateralizableTokenAllowanceWithSignature directly on the CollateralVault with Alice's signature and details.
- Alice's transaction executes after Bob's and reverts because the signature is already used.
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.
When you stake tokens, you sign a message off-chain that proves you approved the action. The contract that checks this signature can be called by anyone, not just the staking contract. An attacker can copy your signed message and submit it first, so when your own transaction arrives the signature is already used and your transaction fails.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.