Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audit(16): Round decays in favor of swapper #305

Merged
merged 11 commits into from
Oct 18, 2024
Merged

audit(16): Round decays in favor of swapper #305

merged 11 commits into from
Oct 18, 2024

Conversation

alanhwu
Copy link
Collaborator

@alanhwu alanhwu commented Oct 2, 2024

To favor the swapper, decay outputs should be rounded up and decay inputs should be rounded down.

@alanhwu alanhwu linked an issue Oct 2, 2024 that may be closed by this pull request
src/lib/DutchDecayLib.sol Outdated Show resolved Hide resolved
@@ -702,6 +703,54 @@ contract V3DutchOrderTest is PermitSignature, DeployPermit2, BaseReactorTest {
assertEq(resolvedOrder.input.amount, 0);
}

// 1000 - (100 * (1659087340-1659029740) / (65535)) = 912.1
// This is the input, which should round down to favor the swapper: 912
function testV3ResolveInputEndBlockAfterNow() public {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: no test for output positive / negative slope?

Copy link
Collaborator

@codyborn codyborn left a comment

Choose a reason for hiding this comment

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

I left this comment in the audit. LMK what you think.

Good to flag this. I think the difference this will make in practice will be quite small and wouldn't justify the additional complexity. The decay's will likely be < 50 bps across ~32 blocks. This means we'd be at most .99% off due to rounding (.495 bps).

It's also not clear that being too high or too low on the curve is actually beneficial for the user since we don't know what the real price is (and it's changing in real time). Imagine the actual price is 3. In one world we round up to 3 and get executed in block N. In another world we round down to 2 and hit it at block N+1 (at 4 instead).

* Pass in decay function for input/output

* forge fmt

* Remove MockNonlinearDutchDecayLibContract
@codyborn codyborn merged commit 9a35aad into main Oct 18, 2024
3 checks passed
@codyborn codyborn deleted the audit-v3-16 branch October 18, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

audit: 16
3 participants