When user tries to deposit transaction will be reverted, if he hadn't approve token to PrincipalToken proxy address earlier. This is incorrect logic, ERC20 unlike ERC721 can be approved in the same transaction with transfer. As default best practice is to use approve in the same function, so some users' will lose funds on gas in first reverted transaction.
Proof of Concept
add this snippet to test/PrincipalToken/PrincipalToken.t.sol
function testDepositWithoutApprove() public {
uint256 amountToDeposit = 1e18;
// transfer must be reverted. deposit function missing approve() of erc20
vm.expectRevert();
principalToken.deposit(amountToDeposit, address(this));
}
Tools Used
Manual review, foundry
Recommended Mitigation Steps
add to deposit:
IERC20(_asset).approve(address(this), assets);
Lines of code
https://github.com/code-423n4/2024-02-spectra/blob/main/src/tokens/PrincipalToken.sol#L176-L185
Vulnerability details
Impact
When user tries to deposit transaction will be reverted, if he hadn't
approve
token toPrincipalToken
proxy address earlier. This is incorrect logic, ERC20 unlike ERC721 can be approved in the same transaction withtransfer
. As default best practice is to use approve in the same function, so some users' will lose funds on gas in first reverted transaction.Proof of Concept
add this snippet to test/PrincipalToken/PrincipalToken.t.sol
Tools Used
Manual review, foundry
Recommended Mitigation Steps
add to
deposit
:IERC20(_asset).approve(address(this), assets);
Assessed type
Token-Transfer