test: 🚧 Added fixtures for new test schema
This commit is contained in:
@@ -4,22 +4,27 @@ pragma solidity >=0.8.4;
|
||||
/// @notice Arithmetic library with operations for fixed-point numbers.
|
||||
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol)
|
||||
library FixedPointMathLib {
|
||||
|
||||
/*//////////////////////////////////////////////////////////////
|
||||
SIMPLIFIED FIXED POINT OPERATIONS
|
||||
//////////////////////////////////////////////////////////////*/
|
||||
|
||||
/// @dev The scalar of ETH and most ERC20s.
|
||||
uint256 internal constant WAD = 1e18;
|
||||
uint256 internal constant WAD = 1e18;
|
||||
|
||||
function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
|
||||
function mulWadDown(
|
||||
uint256 x,
|
||||
uint256 y
|
||||
) internal pure returns (uint256) {
|
||||
// Equivalent to (x * y) / WAD rounded down.
|
||||
return mulDivDown(x, y, WAD);
|
||||
return mulDivDown(x, y, WAD);
|
||||
}
|
||||
|
||||
function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
|
||||
function divWadDown(
|
||||
uint256 x,
|
||||
uint256 y
|
||||
) internal pure returns (uint256) {
|
||||
// Equivalent to (x * WAD) / y rounded down.
|
||||
return mulDivDown(x, WAD, y);
|
||||
return mulDivDown(x, WAD, y);
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////
|
||||
@@ -36,7 +41,12 @@ library FixedPointMathLib {
|
||||
z := mul(x, y)
|
||||
|
||||
// Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
|
||||
if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) {
|
||||
if iszero(
|
||||
and(
|
||||
iszero(iszero(denominator)),
|
||||
or(iszero(x), eq(div(z, x), y))
|
||||
)
|
||||
) {
|
||||
revert(0, 0)
|
||||
}
|
||||
|
||||
@@ -49,7 +59,9 @@ library FixedPointMathLib {
|
||||
GENERAL NUMBER UTILITIES
|
||||
//////////////////////////////////////////////////////////////*/
|
||||
|
||||
function sqrt(uint256 x) internal pure returns (uint256 z) {
|
||||
function sqrt(
|
||||
uint256 x
|
||||
) internal pure returns (uint256 z) {
|
||||
assembly {
|
||||
let y := x // We start y at x, which will help us make our initial estimate.
|
||||
|
||||
@@ -60,7 +72,9 @@ library FixedPointMathLib {
|
||||
|
||||
// We check y >= 2^(k + 8) but shift right by k bits
|
||||
// each branch to ensure that if x >= 256, then y >= 256.
|
||||
if iszero(lt(y, 0x10000000000000000000000000000000000)) {
|
||||
if iszero(
|
||||
lt(y, 0x10000000000000000000000000000000000)
|
||||
) {
|
||||
y := shr(128, y)
|
||||
z := shl(64, z)
|
||||
}
|
||||
@@ -112,4 +126,4 @@ library FixedPointMathLib {
|
||||
z := sub(z, lt(div(x, z), z))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,42 +2,57 @@
|
||||
pragma solidity >=0.8.4;
|
||||
|
||||
/// @notice Gas optimized verification of proof of inclusion for a leaf in a Merkle tree.
|
||||
/// @author Solady
|
||||
/// @author Solady
|
||||
/// (https://github.com/vectorized/solady/blob/main/src/utils/MerkleProofLib.sol)
|
||||
/// @author Modified from Solmate
|
||||
/// @author Modified from Solmate
|
||||
/// (https://github.com/transmissions11/solmate/blob/main/src/utils/MerkleProofLib.sol)
|
||||
/// @author Modified from OpenZeppelin
|
||||
/// @author Modified from OpenZeppelin
|
||||
/// (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/MerkleProof.sol)
|
||||
library MerkleProofLib {
|
||||
/// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
|
||||
function verify(bytes32[] calldata proof, bytes32 root, bytes32 leaf)
|
||||
internal
|
||||
pure
|
||||
returns (bool isValid)
|
||||
{
|
||||
function verify(
|
||||
bytes32[] calldata proof,
|
||||
bytes32 root,
|
||||
bytes32 leaf
|
||||
) internal pure returns (bool isValid) {
|
||||
/// @solidity memory-safe-assembly
|
||||
assembly {
|
||||
if proof.length {
|
||||
// Left shift by 5 is equivalent to multiplying by 0x20.
|
||||
let end := add(proof.offset, shl(5, proof.length))
|
||||
let end := add(
|
||||
proof.offset,
|
||||
shl(5, proof.length)
|
||||
)
|
||||
// Initialize `offset` to the offset of `proof` in the calldata.
|
||||
let offset := proof.offset
|
||||
// Iterate over proof elements to compute root hash.
|
||||
for {} 1 {} {
|
||||
for {
|
||||
|
||||
} 1 {
|
||||
|
||||
} {
|
||||
// Slot of `leaf` in scratch space.
|
||||
// If the condition is true: 0x20, otherwise: 0x00.
|
||||
let scratch := shl(5, gt(leaf, calldataload(offset)))
|
||||
let scratch := shl(
|
||||
5,
|
||||
gt(leaf, calldataload(offset))
|
||||
)
|
||||
// Store elements to hash contiguously in scratch space.
|
||||
// Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
|
||||
mstore(scratch, leaf)
|
||||
mstore(xor(scratch, 0x20), calldataload(offset))
|
||||
mstore(
|
||||
xor(scratch, 0x20),
|
||||
calldataload(offset)
|
||||
)
|
||||
// Reuse `leaf` to store the hash to reduce stack operations.
|
||||
leaf := keccak256(0x00, 0x40)
|
||||
offset := add(offset, 0x20)
|
||||
if iszero(lt(offset, end)) { break }
|
||||
if iszero(lt(offset, end)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
isValid := eq(leaf, root)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity >=0.8.4;
|
||||
pragma solidity >=0.8.4;
|
||||
|
||||
/// @notice Reentrancy protection for smart contracts.
|
||||
/// @author z0r0z.eth
|
||||
@@ -31,4 +31,4 @@ abstract contract ReentrancyGuard {
|
||||
function clearReentrancyGuard() internal virtual {
|
||||
guard = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user