Skip to content

Conversation

@alistair-singh
Copy link
Contributor

Resolves: SNO-1650

@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.99%. Comparing base (7c5d297) to head (e465753).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1636      +/-   ##
==========================================
+ Coverage   85.94%   85.99%   +0.04%     
==========================================
  Files          21       21              
  Lines         925      928       +3     
  Branches      162      163       +1     
==========================================
+ Hits          795      798       +3     
  Misses        104      104              
  Partials       26       26              
Flag Coverage Δ
solidity 85.99% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alistair-singh
Copy link
Contributor Author

I noticed the event:

    event AgentFundsWithdrawn(bytes32 indexed agentID, address indexed recipient, uint256 amount);

Is unused through out our code. I am wondering if we should not emit it in the Handler.sol for v1 and v2. We follow this for other events.

Comment on lines 73 to 82
if (balanceAfter < balanceBefore) {
revert InvalidAmount();
}

uint256 delta = balanceAfter - balanceBefore;
if (delta == 0 || delta > type(uint128).max) {
revert InvalidAmount();
}

transferredAmount = uint128(delta);
Copy link
Contributor

@yrong yrong Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option would be to simply revert if the delta does not match the expected amount. Notably, DeFi protocols like Uniswap do not support these edge cases either. https://docs.uniswap.org/concepts/protocol/integration-issues

Copy link
Contributor Author

@alistair-singh alistair-singh Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, just revert and not support these kinds of tokens at all. @vgeddes ?

The only bad thing with this route, since we have already accepted PAXG, is that if they enabled fees on transfer and it reverted if we detected that. Then all PAXG would essentially never be allowed to be unlocked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I have analyzed a large portion of bridged transfers from mainet(10k, ~80%), and we have not run this case. So I think it would be safe to what you suggest and revert @yrong.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, just revert if delta != amount

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 49bdba9

@yrong
Copy link
Contributor

yrong commented Nov 28, 2025

I noticed the event:

    event AgentFundsWithdrawn(bytes32 indexed agentID, address indexed recipient, uint256 amount);

Is unused through out our code. I am wondering if we should not emit it in the Handler.sol for v1 and v2. We follow this for other events.

That is redundant with the standard ERC-20 Transfer event.

Copy link
Contributor

@claravanstaden claravanstaden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 🪙

revert InvalidAmount();
}

transferredAmount = uint128(delta);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like this return value is ever used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I used to used to emit an event on a previous revision d0c2d5c.

That used the return value to emit an event. But then removed it because:
#1636 (comment)

But it still seems useful to have it as a return value of a function.

Copy link
Contributor

@yrong yrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Comment on lines 97 to 104
uint256 balanceBefore = IERC20(token).balanceOf(recipient);
bytes memory call = abi.encodeCall(AgentExecutor.transferToken, (token, recipient, amount));
invokeOnAgent(agent, executor, call);

uint256 balanceAfter = IERC20(token).balanceOf(recipient);
if (balanceAfter != balanceBefore + amount) {
revert TransferAmountMismatch();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't make sense to revert when unlocking user funds, since the main reason for this PR is to prevent a mismatch between locked funds on the source, and minted funds on the destination.

We don't care about the opposite direction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in f3b4caa

Comment on lines 72 to 74
uint256 balanceAfter = IERC20(token).balanceOf(agent);
if (balanceAfter != balanceBefore + amount) {
revert TransferAmountMismatch();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplification:

Suggested change
uint256 balanceAfter = IERC20(token).balanceOf(agent);
if (balanceAfter != balanceBefore + amount) {
revert TransferAmountMismatch();
if (IERC20(token).balanceOf(agent) != balanceBefore + amount) {
// Tokens with Fee-On-Transfer behaviour are not supported
revert InvalidToken();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in f3b4caa

@alistair-singh alistair-singh force-pushed the alistair/fix-fee-tokens branch from 49bdba9 to f3b4caa Compare December 10, 2025 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants