You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA Medium severity issue.RewardA payout will be made for this issue
The use of tx.origin may cause a trader to lose funds
Summary
Traders interact with the protocol through calls to the api.vy contract. Every interaction is then forwarded to the core.vy contract which is responsible for identifying the trader's address, pulling tokens from the address and performing the desired operation.
Vulnerability Detail
The issue comes from the fact that the core.vy contract identifies the trader using tx.origin. This can lead to unexpected and undesirable behaviors especially when using Smart Contract Wallets (Gnosis Safe ; Abstract Accounts ; ...)
a trader owns a Smart Contract Wallet, with 3 other traders, that holds 4,000 USDT
the trader also holds 5,000 USDT
the trader tries to use the protocol and approve() the core.vy contract to pull type(uint256).max amount of USDT
the trader opens a position with 100 USDT
now the traders that own the smart wallet are confident and want to commit 3,000 USDT from their smart wallet
they all sign the required set of transactions to open() a position in Velar (e.g. USDT.approve())
the initial trader triggers the set of transactions with the intention to open a position for the smart wallet
Velar identifies the trader with tx.origin and performs the open() for the trader's address, not the smart wallet
The initial trader commited 3,000 USDT from his own tokens in Velar
He is now subjected to price fluctuation of the market and has an additional position opened, which he did not intend to.
Impact
This design can potentially cause a loss of funds for the protocol users, performing internal operations with the address that initiated the transaction rather than a potential third party contract.
Tool used
Manual Review
Recommendation
In api.vy retrieve msg.sender and forward this address as a new parameter in all core.vy functions.
For example :
api.vy
@external
def open(
base_token : address,
quote_token : address,
long : bool,
collateral0 : uint256,
leverage : uint256, # @audit does setting it to 0 break something? A : can't set it to 0
desired : uint256,
slippage : uint256,
payload : Bytes[224]
) -> PositionState:
ctx: Ctx = self.CONTEXT(base_token, quote_token, desired, slippage, payload)
- return self.CORE.open(1, base_token, quote_token, long, collateral0, leverage, ctx)+ return self.CORE.open(1, base_token, quote_token, long, collateral0, leverage, msg.sender, ctx)
core.vy
@external
def open(
id : uint256,
base_token : address,
quote_token : address,
long : bool,
collateral0 : uint256,
leverage : uint256,
+ user : address,
ctx : Ctx) -> PositionState:
self._INTERNAL()
- user : address = tx.origin
sherlock-admin3
changed the title
Bent Teal Wolf - The use of tx.origin may cause a trader to lose funds
Greed - The use of tx.origin may cause a trader to lose funds
Sep 11, 2024
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA Medium severity issue.RewardA payout will be made for this issue
Greed
Medium
The use of
tx.origin
may cause a trader to lose fundsSummary
Traders interact with the protocol through calls to the
api.vy
contract. Every interaction is then forwarded to thecore.vy
contract which is responsible for identifying the trader's address, pulling tokens from the address and performing the desired operation.Vulnerability Detail
The issue comes from the fact that the
core.vy
contract identifies the trader usingtx.origin
. This can lead to unexpected and undesirable behaviors especially when usingSmart Contract Wallets
(Gnosis Safe
;Abstract Accounts
; ...)https://github.com/sherlock-audit/2024-08-velar-artha/blob/main/gl-sherlock/contracts/core.vy#L241
Let the following scenario :
Smart Contract Wallet
, with 3 other traders, that holds 4,000 USDTapprove()
thecore.vy
contract to pulltype(uint256).max
amount ofUSDT
open()
a position in Velar (e.g.USDT.approve()
)tx.origin
and performs theopen()
for the trader's address, not the smart walletThe initial trader commited 3,000 USDT from his own tokens in Velar
He is now subjected to price fluctuation of the market and has an additional position opened, which he did not intend to.
Impact
This design can potentially cause a loss of funds for the protocol users, performing internal operations with the address that initiated the transaction rather than a potential third party contract.
Tool used
Manual Review
Recommendation
In
api.vy
retrievemsg.sender
and forward this address as a new parameter in allcore.vy
functions.For example :
api.vy
core.vy
Duplicate of #82
The text was updated successfully, but these errors were encountered: