-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat: fix settleAndRefund
vulnerability
#4
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
92310 | ||
92245 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
67502 | ||
67437 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
151057 | ||
150992 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
68681 | ||
68616 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
53973 | ||
53952 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
968068 | ||
968047 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
121582 | ||
121561 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
337258 | ||
337237 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
56319 | ||
56298 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
93083 | ||
93040 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
95068 | ||
95025 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
74512 | ||
74469 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
318966 | ||
318945 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
41941 | ||
41876 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
19558 | ||
19493 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
37410 | ||
37345 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
22764 | ||
22699 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
348473 | ||
348452 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
61021 | ||
61000 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
241433 | ||
241390 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
84159 | ||
84138 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
53488 | ||
53445 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
43387 | ||
43322 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
56488 | ||
56445 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
104597 | ||
104543 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
25044312 | ||
25044269 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
36401 | ||
36336 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
103140 | ||
103041 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
42051 | ||
41986 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
36404 | ||
36339 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
19513 | ||
19448 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
27680 | ||
27615 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
21962 | ||
21897 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
7075 | ||
7049 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
122540 | ||
122519 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
158832 | ||
158811 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
47017 | ||
46974 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
47016 | ||
46973 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
11692 | ||
11627 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
72621 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
34111 |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,26 +126,26 @@ contract Vault is IVault, VaultToken, Ownable { | |
SettlementGuard.accountDelta(msg.sender, currency, -(paid.toInt128())); | ||
} | ||
|
||
function settleAndRefund(Currency currency, address to) | ||
function settleAndMintRefund(Currency currency, address to) | ||
external | ||
payable | ||
override | ||
isLocked | ||
returns (uint256 paid, uint256 refund) | ||
{ | ||
paid = currency.balanceOfSelf() - reservesOfVault[currency]; | ||
int256 currentDelta = SettlementGuard.getCurrencyDelta(msg.sender, currency); | ||
uint256 reservesBefore = reservesOfVault[currency]; | ||
reservesOfVault[currency] = currency.balanceOfSelf(); | ||
paid = reservesOfVault[currency] - reservesBefore; | ||
|
||
int256 currentDelta = SettlementGuard.getCurrencyDelta(msg.sender, currency); | ||
if (currentDelta >= 0 && paid > currentDelta.toUint256()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can cache currentDelta after casting to uint256 so you don't have to keep casting it again, wasting gas.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also just to confirm, refund is only done, and paid is only adjusted if currentDelta is positive or zero, never if currentDelta is negative? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yep. do you think theres a scenario where negative balanceDelta (vault owes caller token) might need to handled? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, that's why I'm asking. |
||
// msg.sender owes vault but paid more than than whats owed | ||
refund = paid - currentDelta.toUint256(); | ||
paid = currentDelta.toUint256(); | ||
} | ||
|
||
reservesOfVault[currency] += paid; | ||
SettlementGuard.accountDelta(msg.sender, currency, -(paid.toInt128())); | ||
|
||
if (refund > 0) currency.transfer(to, refund); | ||
if (refund > 0) _mint(to, currency, refund); | ||
} | ||
|
||
/// @inheritdoc IVault | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this part, the function would revert if reservesBefore is larger than the current reserve, since it would mean that the locker did not transfer anything to increase the current balance right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the locker didn't transfer anything, this function shouldn't revert. The behavior should be the same as
settle()
.Can think of 1 scenario for revert:
1/ might be for rebasing token, where a negative rebase was done which cause the current balance in vault to be lesser than reserveBefore
cc @chefburger or @ChefSnoopy if can add on to more scenarios where revert might happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cant come with other cases either, but i think it's fine to just let it revert if reservesBefore is greater than current.