Skip to content

Commit d85fa46

Browse files
committed
backport: SignatureValidatorV2: fix edge case in which signature mode is out of bounds and we just silently fail due to the solidity check
1 parent 3aa40d4 commit d85fa46

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

contracts/libs/SignatureValidatorV2.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ library SignatureValidator {
1414
EIP712,
1515
EthSign,
1616
SmartWallet,
17-
Spoof
17+
Spoof,
18+
// WARNING: must always be last
19+
LastUnused
1820
}
1921

2022
// bytes4(keccak256("isValidSignature(bytes32,bytes)"))
@@ -28,6 +30,8 @@ library SignatureValidator {
2830
require(sig.length >= 1, "SV_SIGLEN");
2931
uint8 modeRaw;
3032
unchecked { modeRaw = uint8(sig[sig.length - 1]); }
33+
// Ensure we're in bounds for mode; Solidity does this as well but it will just silently blow up rather than showing a decent error
34+
require(modeRaw < uint8(SignatureMode.LastUnused), "SV_SIGMODE");
3135
SignatureMode mode = SignatureMode(modeRaw);
3236

3337
// {r}{s}{v}{mode}
@@ -56,10 +60,12 @@ library SignatureValidator {
5660
return address(wallet);
5761
// {address}{mode}; the spoof mode is used when simulating calls
5862
} else if (mode == SignatureMode.Spoof && allowSpoofing) {
63+
// This is safe cause it's specifically intended for spoofing sigs in simulation conditions, where tx.origin can be controlled
64+
// slither-disable-next-line tx-origin
5965
require(tx.origin == address(1), "SV_SPOOF_ORIGIN");
6066
require(sig.length == 33, "SV_SPOOF_LEN");
6167
sig.trimToSize(32);
6268
return abi.decode(sig, (address));
63-
} else revert("SV_SIGMODE");
69+
};
6470
}
6571
}

0 commit comments

Comments
 (0)