From eece619d1695c321453d1212bb340a5b7ecdd9fb Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 5 Dec 2024 00:32:47 -0800 Subject: [PATCH] fix: gas estimation during session validation Couldn't find a better way to do this and I don't know how this wasn't a problem before? --- src/validators/SessionKeyValidator.sol | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/validators/SessionKeyValidator.sol b/src/validators/SessionKeyValidator.sol index 0aec04af..bd202995 100644 --- a/src/validators/SessionKeyValidator.sol +++ b/src/validators/SessionKeyValidator.sol @@ -144,8 +144,14 @@ contract SessionKeyValidator is IModuleValidator { (SessionLib.SessionSpec, uint64[]) ); require(spec.signer != address(0), "Invalid signer (empty)"); - (address recoveredAddress, ) = ECDSA.tryRecover(signedHash, transactionSignature); - require(recoveredAddress != address(0), "Invalid signature (empty)"); + (address recoveredAddress, ECDSA.RecoverError recoverError) = ECDSA.tryRecover(signedHash, transactionSignature); + + // gas estimation provides invalid custom signatures + if (recoveredAddress == address(0) && recoverError == ECDSA.RecoverError.InvalidSignature) { + // this should increase the gas estimation and shouldn't otherwise be possible + return keccak256(_signature) != keccak256(transactionSignature); + } + require(recoveredAddress == spec.signer, "Invalid signer (mismatch)"); bytes32 sessionHash = keccak256(abi.encode(spec)); sessions[sessionHash].validate(transaction, spec, periodIds);