diff --git a/src/sig/SignatureLib.sol b/src/sig/SignatureLib.sol index b1a63a3..448950f 100644 --- a/src/sig/SignatureLib.sol +++ b/src/sig/SignatureLib.sol @@ -45,6 +45,13 @@ library SignatureLib { uint8 internal constant WEBAUTHN_FLAG_UP = 0x01; // user present uint8 internal constant WEBAUTHN_FLAG_UV = 0x04; // user verified + /*////////////////////////////////////////////////////////////// + ERRORS + //////////////////////////////////////////////////////////////*/ + + /// @notice Thrown when `webauthnData` is shorter than the 37-byte authenticatorData prefix. + error WebAuthnDataTooShort(); + /*////////////////////////////////////////////////////////////// LOW-S NORMALIZATION //////////////////////////////////////////////////////////////*/ @@ -150,7 +157,7 @@ library SignatureLib { /// @dev `sha256(authenticatorData || sha256(clientDataJSON))`. function webAuthnMessageHash(bytes memory webauthnData) internal pure returns (bytes32) { // First 37 bytes are authenticatorData (no extensions, since the precompile rejects ED). - require(webauthnData.length >= 37, "SignatureLib: webauthnData too short"); + if (webauthnData.length < 37) revert WebAuthnDataTooShort(); bytes memory authData = new bytes(37); bytes memory clientDataJSON = new bytes(webauthnData.length - 37); for (uint256 i = 0; i < 37; i++) { diff --git a/src/tx/Eip1559TransactionLib.sol b/src/tx/Eip1559TransactionLib.sol index 87b643e..eacb0b5 100644 --- a/src/tx/Eip1559TransactionLib.sol +++ b/src/tx/Eip1559TransactionLib.sol @@ -25,9 +25,12 @@ library Eip1559TransactionLib { /// @notice EIP-1559 transaction type prefix. uint8 internal constant TX_TYPE = 0x02; + /// @notice Thrown when `block.chainid` does not fit in a `uint64`. + error ChainIdExceedsUint64(); + /// @notice Creates a new EIP-1559 transaction with default values. function create() internal view returns (Eip1559Transaction memory tx_) { - require(block.chainid <= type(uint64).max, "chain ID exceeds uint64"); + if (block.chainid > type(uint64).max) revert ChainIdExceedsUint64(); // Safe after the explicit range check above. // forge-lint: disable-next-line(unsafe-typecast) tx_.chainId = uint64(block.chainid); diff --git a/src/tx/Eip7702TransactionLib.sol b/src/tx/Eip7702TransactionLib.sol index f0d3dd0..5620054 100644 --- a/src/tx/Eip7702TransactionLib.sol +++ b/src/tx/Eip7702TransactionLib.sol @@ -39,9 +39,12 @@ library Eip7702TransactionLib { /// @notice EIP-7702 authorization magic for signing. uint8 internal constant AUTH_MAGIC = 0x05; + /// @notice Thrown when `block.chainid` does not fit in a `uint64`. + error ChainIdExceedsUint64(); + /// @notice Creates a new EIP-7702 transaction with default values. function create() internal view returns (Eip7702Transaction memory tx_) { - require(block.chainid <= type(uint64).max, "chain ID exceeds uint64"); + if (block.chainid > type(uint64).max) revert ChainIdExceedsUint64(); // Safe after the explicit range check above. // forge-lint: disable-next-line(unsafe-typecast) tx_.chainId = uint64(block.chainid); diff --git a/src/tx/TempoTransactionLib.sol b/src/tx/TempoTransactionLib.sol index 0287257..fcfbd91 100644 --- a/src/tx/TempoTransactionLib.sol +++ b/src/tx/TempoTransactionLib.sol @@ -52,6 +52,9 @@ library TempoTransactionLib { /// @notice Tempo transaction type prefix. uint8 internal constant TX_TYPE = 0x76; + /// @notice Thrown when a fee payer signature is not exactly 65 bytes. + error InvalidFeePayerSignatureLength(); + /// @notice Creates a new Tempo transaction with default values. function create() internal pure returns (TempoTransaction memory tx_) { tx_.gasLimit = 21000; @@ -431,7 +434,7 @@ library TempoTransactionLib { /// @notice Encodes fee payer signature as RLP list [v, r, s] function _encodeFeePayerSignature(bytes memory sig) private pure returns (bytes memory) { - require(sig.length == 65, "Invalid fee payer signature length"); + if (sig.length != 65) revert InvalidFeePayerSignatureLength(); // Parse signature: first 32 bytes = r, next 32 = s, last byte = v bytes32 r = bytes32(0);