-
Notifications
You must be signed in to change notification settings - Fork 14
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
Fix gas meter and setNetwork #18
Merged
+522
−335
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
708d5cf
Make submitMessage gas cost predictable
Lohann 9f70338
Improve docs
Lohann 6f34e67
Fix gas meter
Lohann 6d682c9
Fix unit tests
Lohann 81c6b3c
Remove commented code
Lohann 4c054db
Remove debug from test_baseExecutionCost
Lohann fc6df94
Fix typo
Lohann fe60dcc
Make GasUtils.proxyOverheadGasCost safe
Lohann 4618c7f
Update submitMessage constant
Lohann 1f160f3
Remove unused methods
Lohann e50d798
Fix setNetworkInfo method
Lohann d5fdc8a
Fix ternary
Lohann f0fb54c
Remove duplicated storage access
Lohann 1144441
Add memory-safe-assembly tag to countNonZeros method
Lohann 8aaa40b
Fix bytes32 method overloading
Lohann 1a28daf
Explicitly make deprecated method private
Lohann b1e8439
Add a method for query the network info
Lohann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,20 +11,20 @@ library BranchlessMath { | |
* @dev Returns the smallest of two numbers. | ||
*/ | ||
function min(uint256 x, uint256 y) internal pure returns (uint256) { | ||
return select(x < y, x, y); | ||
return ternary(x < y, x, y); | ||
} | ||
|
||
/** | ||
* @dev Returns the largest of two numbers. | ||
*/ | ||
function max(uint256 x, uint256 y) internal pure returns (uint256) { | ||
return select(x > y, x, y); | ||
return ternary(x > y, x, y); | ||
} | ||
|
||
/** | ||
* @dev If `condition` is true returns `a`, otherwise returns `b`. | ||
*/ | ||
function select(bool condition, uint256 a, uint256 b) internal pure returns (uint256) { | ||
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) { | ||
unchecked { | ||
// branchless select, works because: | ||
// b ^ (a ^ b) == a | ||
|
@@ -40,13 +40,67 @@ library BranchlessMath { | |
|
||
/** | ||
* @dev If `condition` is true returns `a`, otherwise returns `b`. | ||
* see `BranchlessMath.ternary` | ||
*/ | ||
function select(bool condition, address a, address b) internal pure returns (address) { | ||
return address(uint160(select(condition, uint256(uint160(a)), uint256(uint160(b))))); | ||
function ternary(bool condition, address a, address b) internal pure returns (address r) { | ||
assembly { | ||
r := xor(b, mul(xor(a, b), condition)) | ||
} | ||
} | ||
|
||
/** | ||
* @dev If `condition` is true returns `a`, otherwise returns `b`. | ||
* see `BranchlessMath.ternary` | ||
*/ | ||
function ternary(bool condition, bytes32 a, bytes32 b) internal pure returns (bytes32 r) { | ||
assembly { | ||
r := xor(b, mul(xor(a, b), condition)) | ||
} | ||
} | ||
|
||
/** | ||
* @dev If `condition` is true returns `a`, otherwise returns `b`. | ||
* see `BranchlessMath.ternary` | ||
*/ | ||
function ternaryU128(bool condition, uint128 a, uint128 b) internal pure returns (uint128 r) { | ||
assembly { | ||
r := xor(b, mul(xor(a, b), condition)) | ||
} | ||
} | ||
Comment on lines
+65
to
+69
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. Yeah.. even so solidity supports method overloading, it doesn't work with types of the same family, only between different types like |
||
|
||
/** | ||
* @dev If `condition` is true returns `a`, otherwise returns `b`. | ||
* see `BranchlessMath.ternary` | ||
*/ | ||
function ternaryU64(bool condition, uint64 a, uint64 b) internal pure returns (uint64 r) { | ||
assembly { | ||
r := xor(b, mul(xor(a, b), condition)) | ||
} | ||
} | ||
|
||
/** | ||
* @dev If `condition` is true returns `a`, otherwise returns `b`. | ||
* see `BranchlessMath.ternary` | ||
*/ | ||
function ternaryU32(bool condition, uint32 a, uint32 b) internal pure returns (uint32 r) { | ||
assembly { | ||
r := xor(b, mul(xor(a, b), condition)) | ||
} | ||
} | ||
|
||
/** | ||
* @dev If `condition` is true returns `a`, otherwise returns `b`. | ||
* see `BranchlessMath.ternary` | ||
*/ | ||
function ternaryU8(bool condition, uint8 a, uint8 b) internal pure returns (uint8 r) { | ||
assembly { | ||
r := xor(b, mul(xor(a, b), condition)) | ||
} | ||
} | ||
|
||
/** | ||
* @dev If `condition` is true return `value`, otherwise return zero. | ||
* see `BranchlessMath.ternary` | ||
*/ | ||
function selectIf(bool condition, uint256 value) internal pure returns (uint256) { | ||
unchecked { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Upgrade was failling because I had to add it back.