Skip to content

Commit 5c8c6c0

Browse files
authored
[Certora Audit] G07. Use a mask instead of shifting left and right (safe-global#894)
This pull request includes changes to the `contracts/handler/extensible` directory, specifically in the `MarshalLib.sol` and `SignatureVerifierMuxer.sol` files. The changes focus on improving the handling of data and selectors within assembly code blocks to decrease gas usage. Improvements to data handling and selector extraction: * [`contracts/handler/extensible/MarshalLib.sol`](diffhunk://#diff-7122c44132b6fc89cd7c9f3c48519c88aaf7308705a1170d307d72465eb9e1c9L41-R41): Modified the way the `handler` is extracted from `data` by using a bitwise AND operation to ensure proper extraction of the handler address. [[1]](diffhunk://#diff-7122c44132b6fc89cd7c9f3c48519c88aaf7308705a1170d307d72465eb9e1c9L41-R41) [[2]](diffhunk://#diff-7122c44132b6fc89cd7c9f3c48519c88aaf7308705a1170d307d72465eb9e1c9L59-R59) * [`contracts/handler/extensible/SignatureVerifierMuxer.sol`](diffhunk://#diff-62f21ce8850527f34ef2acdacd96d4a2a1150e3e2a7e16457e82236bbd4259d2L113-R113): Changed the extraction of `sigSelector` from `calldataload` to use a bitwise AND operation for more accurate and secure selector extraction.
1 parent 8137b68 commit 5c8c6c0

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

contracts/handler/extensible/MarshalLib.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ library MarshalLib {
3838
assembly {
3939
// set isStatic to true if the left-most byte of the data is 0x00
4040
isStatic := iszero(shr(248, data))
41-
handler := shr(96, shl(96, data))
41+
handler := and(data, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
4242
}
4343
/* solhint-enable no-inline-assembly */
4444
}
@@ -56,7 +56,7 @@ library MarshalLib {
5656
assembly {
5757
// set isStatic to true if the left-most byte of the data is 0x00
5858
isStatic := iszero(shr(248, data))
59-
handler := shr(96, shl(96, data))
59+
handler := and(data, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
6060
selector := shl(168, shr(160, data))
6161
}
6262
/* solhint-enable no-inline-assembly */

contracts/handler/extensible/SignatureVerifierMuxer.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ abstract contract SignatureVerifierMuxer is ExtensibleBase, ERC1271, ISignatureV
110110
/* solhint-disable no-inline-assembly */
111111
/// @solidity memory-safe-assembly
112112
assembly {
113-
sigSelector := shl(224, shr(224, calldataload(signature.offset)))
113+
sigSelector := calldataload(signature.offset)
114114
}
115115
/* solhint-enable no-inline-assembly */
116116

0 commit comments

Comments
 (0)