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(9): Round gas adjustments in favor of swapper #302

Merged
merged 5 commits into from
Oct 16, 2024
Merged

Conversation

alanhwu
Copy link
Collaborator

@alanhwu alanhwu commented Oct 1, 2024

Round gas adjustments in favor of swappers based on input/output and gas price increasing/decreasing

@alanhwu alanhwu linked an issue Oct 1, 2024 that may be closed by this pull request
@@ -112,15 +112,19 @@ contract V3DutchOrderReactor is BaseReactor {
// positive means an increase in gas
int256 gasDeltaGwei = block.basefee.sub(order.startingBaseFee);

// Gas increase should increase input
int256 inputDelta = int256(order.baseInput.adjustmentPerGweiBaseFee) * gasDeltaGwei / 1 gwei;
// Gas increase should increase input (round up when positive, down when negative)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: add comment here about how less input = favoring swapper

Comment on lines 1448 to 1449
assertEq(resolvedOrder.input.amount, 100 ether - 0.08 gwei, "Input should handle small negative gas changes");
assertEq(resolvedOrder.outputs[0].amount, 100 ether + 0.08 gwei, "Output should handle small negative gas changes");
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a test that specifically tests the rounding down / up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

accidentally tested using gwei instead of wei. fixed

zhongeric
zhongeric previously approved these changes Oct 4, 2024
codyborn
codyborn previously approved these changes Oct 8, 2024
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.

Looks good. I'm surprised that this lowered the gas costs!

@alanhwu alanhwu dismissed stale reviews from codyborn and zhongeric via f174dd5 October 16, 2024 15:58
@alanhwu alanhwu merged commit d7cea37 into main Oct 16, 2024
3 checks passed
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: 9
3 participants