-
Notifications
You must be signed in to change notification settings - Fork 108
PerpV2LeverageModule ABDK audit fixes #190
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
Conversation
a99a543 to
2d82cf9
Compare
6c8d9c3 to
4ca9d2b
Compare
cgewecke
left a comment
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.
Questions about skipped items from the ABDK audit:
Item 18, L757
In two places we're using .mul(-1) to flip the sign. ABDK says it's more optimal to use a safe negation function.
pendingFundingPayments: perpExchange.getAllPendingFundingPayment(address(_setToken)).mul(-1), _isIssue ? baseTradeNotionalQuantity : baseTradeNotionalQuantity.mul(-1),
At Perp, negation is handled using a set of methods that look like this:
function neg256(int256 a) internal pure returns (int256) {
require(a > -2**255, "PerpMath: inversion overflow");
return -a;
}
function neg256(uint256 a) internal pure returns (int256) {
return -PerpSafeCast.toInt256(a);
}
function neg128(int128 a) internal pure returns (int128) {
require(a > -2**127, "PerpMath: inversion overflow");
return -a;
}
function neg128(uint128 a) internal pure returns (int128) {
return -PerpSafeCast.toInt128(a);
}Question: We are using SafeMath for mul so there shouldn't be any overflow issues but what would the efficiency gain proposed in this recommendation look like in our case and what is our reason for skipping? (Fine w/ skipping fwiw - this flip is simple).
Item 11: try/catch blocks
ABDK says:
Consider ignoring only a certain class of errors or implementing some way to detect which modules do implement the “IDebtIssuanceModule” interface.
Their suggestion might not be viable but could we add a clearer comment about what's happening here, e.g why it's wrapped like this, etc?
set-protocol-v2/contracts/protocol/modules/PerpV2LeverageModule.sol
Lines 249 to 254 in 4892ef8
| // Try if register exists on any of the modules including the debt issuance module | |
| address[] memory modules = _setToken.getModules(); | |
| for(uint256 i = 0; i < modules.length; i++) { | |
| try IDebtIssuanceModule(modules[i]).registerToIssuanceModule(_setToken) {} catch {} | |
| } | |
| } |
@cgewecke And added comments for the try-catch block in 0e704f03 |
https://docs.google.com/spreadsheets/d/1-S4Gkn5UD5MsZcODgCHCOBY9UX8bETPEk7jzzvwxsYY/edit#gid=0