Skip to content

Commit

Permalink
feat: custom errors
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Maldonado <[email protected]>
  • Loading branch information
md0x committed Nov 7, 2024
1 parent 46f98d3 commit d973250
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion contracts/libraries/AddressConverters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
pragma solidity ^0.8.0;

library Bytes32ToAddress {
/**************************************
* ERRORS *
**************************************/
error InvalidBytes32();

function toAddress(bytes32 _bytes32) internal pure returns (address) {
require(uint256(_bytes32) >> 192 == 0, "Invalid bytes32: highest 12 bytes must be 0");
if (uint256(_bytes32) >> 192 != 0) {
revert InvalidBytes32();
}
return address(uint160(uint256(_bytes32)));
}
}
Expand Down

0 comments on commit d973250

Please sign in to comment.