File tree Expand file tree Collapse file tree 5 files changed +46
-3
lines changed
Expand file tree Collapse file tree 5 files changed +46
-3
lines changed Original file line number Diff line number Diff line change 7878 forge test --fuzz-runs 5000
7979 )
8080
81- tests-nightly :
81+ tests-ithaca :
8282 name : Forge Ithaca Testing
8383 runs-on : ubuntu-latest
8484 strategy :
8989 - name : Install Foundry Nightly
9090 uses : foundry-rs/foundry-toolchain@v1
9191 with :
92- version : nightly
92+ version : stable
9393 - name : Install Dependencies
9494 run : forge install
9595 - name : Run Tests with ${{ matrix.profile }}
Original file line number Diff line number Diff line change @@ -455,4 +455,20 @@ Returns bytes in calldata. Performs bounds checks.
455455function emptyCalldata() internal pure returns (bytes calldata result)
456456```
457457
458- Returns empty calldata bytes. For silencing the compiler.
458+ Returns empty calldata bytes. For silencing the compiler.
459+
460+ ### msbToAddress(bytes32)
461+
462+ ``` solidity
463+ function msbToAddress(bytes32 x) internal pure returns (address)
464+ ```
465+
466+ Returns the most significant 20 bytes as an address.
467+
468+ ### lsbToAddress(bytes32)
469+
470+ ``` solidity
471+ function lsbToAddress(bytes32 x) internal pure returns (address)
472+ ```
473+
474+ Returns the least significant 20 bytes as an address.
Original file line number Diff line number Diff line change @@ -849,4 +849,14 @@ library LibBytes {
849849 result.length := 0
850850 }
851851 }
852+
853+ /// @dev Returns the most significant 20 bytes as an address.
854+ function msbToAddress (bytes32 x ) internal pure returns (address ) {
855+ return address (bytes20 (x));
856+ }
857+
858+ /// @dev Returns the least significant 20 bytes as an address.
859+ function lsbToAddress (bytes32 x ) internal pure returns (address ) {
860+ return address (uint160 (uint256 (x)));
861+ }
852862}
Original file line number Diff line number Diff line change @@ -853,4 +853,14 @@ library LibBytes {
853853 result.length := 0
854854 }
855855 }
856+
857+ /// @dev Returns the most significant 20 bytes as an address.
858+ function msbToAddress (bytes32 x ) internal pure returns (address ) {
859+ return address (bytes20 (x));
860+ }
861+
862+ /// @dev Returns the least significant 20 bytes as an address.
863+ function lsbToAddress (bytes32 x ) internal pure returns (address ) {
864+ return address (uint160 (uint256 (x)));
865+ }
856866}
Original file line number Diff line number Diff line change @@ -366,4 +366,11 @@ contract LibBytesTest is SoladyTest {
366366 return type (uint256 ).max;
367367 }
368368 }
369+
370+ function testBytes32ToAddress (bytes32 x ) public {
371+ uint256 msb = uint256 (x) >> 96 ;
372+ uint256 lsb = (uint256 (x) << 96 ) >> 96 ;
373+ assertEq (uint160 (LibBytes.msbToAddress (x)), msb);
374+ assertEq (uint160 (LibBytes.lsbToAddress (x)), lsb);
375+ }
369376}
You can’t perform that action at this time.
0 commit comments