-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
491 additions
and
107 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.27; | ||
|
||
library EfficiencyLib { | ||
// NOTE: this function is only safe if the supplied booleans are known to not | ||
// have any dirty bits set (i.e. they are either 0 or 1). It is meant to get | ||
// around the fact that solidity only evaluates both expressions in an && if | ||
// the first expression evaluates to true, which requires a conditional jump. | ||
function and(bool a, bool b) internal pure returns (bool c) { | ||
assembly { | ||
c := and(a, b) | ||
} | ||
} | ||
|
||
// NOTE: this function is only safe if the supplied booleans are known to not | ||
// have any dirty bits set (i.e. they are either 0 or 1). It is meant to get | ||
// around the fact that solidity only evaluates both expressions in an || if | ||
// the first expression evaluates to false, which requires a conditional jump. | ||
function or(bool a, bool b) internal pure returns (bool c) { | ||
assembly { | ||
c := or(a, b) | ||
} | ||
} | ||
|
||
// NOTE: this function is only safe if the supplied uint256 is known to not | ||
// have any dirty bits set (i.e. it is either 0 or 1). | ||
function asBool(uint256 a) internal pure returns (bool b) { | ||
assembly { | ||
b := a | ||
} | ||
} | ||
|
||
function asUint256(bool a) internal pure returns (uint256 b) { | ||
assembly { | ||
b := a | ||
} | ||
} | ||
} |
Oops, something went wrong.