Japy69 - Unsafe use of tx.origin in the mint function will leading to unauthorized LP token minting #1
Labels
Duplicate
A valid issue that is a duplicate of an issue with `Has Duplicates` label
Medium
A Medium severity issue.
Reward
A payout will be made for this issue
Sponsor Disputed
The sponsor disputed this issue's validity
Japy69
Medium
Unsafe use of tx.origin in the mint function will leading to unauthorized LP token minting
Summary
The use of
tx.origin
in themint
function of the Velar protocol allows for a phishing attack. If a user grants unlimited allowance to the contract forbase_token
andquote_token
, a malicious contract can execute themint
function on their behalf, resulting in unauthorized minting of LP tokens. The root cause is the use oftx.origin
to determine the user, which is unsafe as it can be manipulated by intermediate contracts.Root Cause
In
core.vy:166
there is an unsafe use oftx.origin
as it can cause unauthorized minting.The choice to use tx.origin may be because of
api.vy
contract between user andcore.vy
contract. There is a good explaination of why it is unsafe in the Solidity documentation: https://docs.soliditylang.org/en/latest/security-considerations.html#tx-origin.The
mint
function inAPI.vy
allows users to mint LP tokens by depositingbase_token
andquote_token
into the contract. The function usestx.origin
to identify the user initiating the transaction:This design is problematic because
tx.origin
represents the original sender of the transaction, not necessarily the direct caller. In scenarios where a user interacts with another contract that in turn calls themint
function,tx.origin
will still point to the original user.Internal pre-conditions
The victim must have granted an allowance to the core contract address for both
base_token
andquote_token
, enabling the contract to transfer tokens on the victim's behalf.The victim must initiate a transaction with a smart contract that allows the attacker to indirectly call the
mint
function at any point during the transaction. This can be easily achieved, for example, if the victim interacts with an automated router like Uniswap's that swaps tokens based on optimal trade routes. The attacker could create a malicious token involved in the trade, and within thetransfer
function of this malicious token, the attacker can execute a call to the Velor protocol'smint
function. Becausetx.origin
will still refer to the victim, the Velor protocol will perceive the transaction as initiated by the victim.External pre-conditions
No response
Attack Path
If a user has set an unlimited allowance for
base_token
andquote_token
to this contract, a malicious contract can execute a phishing attack by:mint
function onAPI.vy
.tx.origin
to transfer tokens from the user’s address to the contract, minting new LP tokens without the user's explicit consent.Impact
PoC
No response
Mitigation
To mitigate this vulnerability, replace
tx.origin
with auser
parameter passed to themint
function. This parameter should be set by themsg.sender
when theAPI.vy
contract calls the function. The updated function signature should look like this:Additionally, the contract call on
api.vy:101
should be updated to:By passing
msg.sender
as theuser
, the function ensures that only the immediate caller is authorized to initiate the minting process, thus preventing phishing attacks.Duplicate of #82
The text was updated successfully, but these errors were encountered: