Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/sig/SignatureLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can still use require and just pass the custom error as the 2nd arg

bytes memory authData = new bytes(37);
bytes memory clientDataJSON = new bytes(webauthnData.length - 37);
for (uint256 i = 0; i < 37; i++) {
Expand Down
5 changes: 4 additions & 1 deletion src/tx/Eip1559TransactionLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/tx/Eip7702TransactionLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/tx/TempoTransactionLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down