Correctly encode approval interactions for USDT-like tokens#4354
Merged
MartinquaXD merged 5 commits intomainfrom Apr 21, 2026
Merged
Correctly encode approval interactions for USDT-like tokens#4354MartinquaXD merged 5 commits intomainfrom
MartinquaXD merged 5 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the approvals logic to support tokens like USDT, which require resetting allowances to zero before they can be increased. It also updates the end-to-end tests to use USDT to validate this new behavior. Feedback was provided regarding the approvals implementation, specifically pointing out that the use of a HashMap for aggregation is redundant and introduces non-determinism. Furthermore, the logic should be corrected to avoid emitting an unnecessary approval interaction when the current on-chain allowance is already sufficient.
jmg-duarte
reviewed
Apr 21, 2026
jmg-duarte
approved these changes
Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Alternative to #4340
USDT is a bit special because it is one of very few tokens where the
approve()function requires you to set the allowance back to 0 before you can alter it again to avoid a vulnerability (see here).Changes
This PR adjusts the driver's approval encoding logic such that it checks whether the regular
approve()call would revert. In case that happens it encodes anapprove(0)andapprove(desired_value)to be compatible with this security measure / quirk.That way we support all those tokens on all chains without needing any extra configuration parameters or hardcoded values. The downside is 1 extra RPC call every time we have to increase an approval which is extremely rare so it's fine.
How to test
Converted an existing
USDC -> USDTorder fork test to be aUSDT -> USDCtest. This test fails without the PR's change.