User might execute PositionToken of token set by previous token owner
The AutoRange contract stores a per-token position configuration that is not cleared when the token is transferred to a new owner. A new owner could therefore have their position executed using a configuration set by the previous owner, potentially affecting the swap and the protocol's incentive.
Submitted by cryptphi
The AutoRange.configToken() function updates the state variable positionConfigs for a tokenId and callable by the owner of the tokenId. However, in the call to AutoRange.execute(), the state variable positionConfigs for the tokenId is used in setting the local variable PositionConfig memory config without any further check to ensure the config has been set by the current owner of the tokenId.
This in some way could affect the swapcall on the token position such that the protocol does not receive any incentive.
Proof of Concept
- Alice is an operator and owns token 1 and sets the
configToken()to configure token to be used before callingexecuteWithVault().
https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/transformers/AutoRange.sol#L276-L297
positionConfigs state variable for tokenId is set in configToken() by token owner:
function configToken(uint256 tokenId, address vault, PositionConfig calldata config) external {
_validateOwner(tokenId, vault);
// lower tick must be always below or equal to upper tick - if they are equal - range adjustment is deactivated
if (config.lowerTickDelta > config.upperTickDelta) {
revert InvalidConfig();
}
positionConfigs[tokenId] = config;
- After a while and eventually Alice no longer has any position on token and transfers the token to Bob.
- Bob is another operator and calls
executeWithVault(); the calls happen using the old token config set by Alice.
https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/transformers/AutoRange.sol#L111-L116
positionConfigs[tokenId] set by a previous tokenId owner being used:
function execute(ExecuteParams calldata params) external {
if (!operators[msg.sender] && !vaults[msg.sender]) {
revert Unauthorized();
}
ExecuteState memory state;
PositionConfig memory config = positionConfigs[params.tokenId];
Recommended Mitigation Steps
Using an enumerable set or additional mapping parameter to set the current owner in the positionConfigs state variable and an additional check in execute() to ensure the config was set by token owner.
kalinbas (Revert) acknowledged and commented:
Position config is not reset when transferring a position to someone else, but the operator
approval/approvalforallis reset. So the position can’t be automated anymore, and if it is given approval, the revert UI will also let the user set the new config. So this is valid but not a problem.
Makes sense. I also believe that frontend security checks are unreliable, so I’m still maintaining it as an Medium.
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 per-token configuration mapping is not reset or re-validated against the current owner when the token is transferred.
Impact
The new owner's position could be executed with the previous owner's configuration, which may affect the swap and mean the protocol does not receive its incentive; the maintainer notes that operator approvals are reset on transfer, so the position cannot be automated until approval is given again.
What the attacker needed
A token position is transferred to a new owner; the new owner grants operator approval; the new owner calls execute
The fix
The configuration should record the owner who set it, and execute() should check that this matches the current token owner, or the configuration should be cleared on transfer.
How it was found
- Alice, an operator, owns token 1 and calls configToken() to set its position configuration.
- Alice later transfers the token to Bob.
- Bob calls executeWithVault(), and the call uses the old configuration set by Alice.
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 smart contract keeps a saved setting for each token position, like a note saying how it should be managed. When the position is sold or transferred, that note stays behind, so the new owner's position may be handled using the old owner's instructions. This can change how the position is traded and may cost the protocol a fee it expected.
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.