@@ -21,38 +21,29 @@ abstract contract _MetaTransactionContext is _Context {
21
21
returns (address msgSender )
22
22
{
23
23
if (msg .sender == address (this )) {
24
- msgSender = _getRelayedCallSender ();
25
- } else {
26
- msgSender = msg . sender ;
27
- }
28
- }
24
+ // We need to read 20 bytes (an address) located at array index msg.data.length - 20. In memory, the array
25
+ // is prefixed with a 32-byte length value, so we first add 32 to get the memory read index. However, doing
26
+ // so would leave the address in the upper 20 bytes of the 32-byte word, which is inconvenient and would
27
+ // require bit shifting. We therefore subtract 12 from the read index so the address lands on the lower 20
28
+ // bytes. This can always be done due to the 32-byte prefix.
29
29
30
- function _getRelayedCallSender ()
31
- private
32
- pure
33
- returns (address payable result )
34
- {
35
- // We need to read 20 bytes (an address) located at array index msg.data.length - 20. In memory, the array
36
- // is prefixed with a 32-byte length value, so we first add 32 to get the memory read index. However, doing
37
- // so would leave the address in the upper 20 bytes of the 32-byte word, which is inconvenient and would
38
- // require bit shifting. We therefore subtract 12 from the read index so the address lands on the lower 20
39
- // bytes. This can always be done due to the 32-byte prefix.
40
-
41
- // The final memory read index is msg.data.length - 20 + 32 - 12 = msg.data.length. Using inline assembly is the
42
- // easiest/most-efficient way to perform this operation.
30
+ // The final memory read index is msg.data.length - 20 + 32 - 12 = msg.data.length. Using inline assembly is the
31
+ // easiest/most-efficient way to perform this operation.
43
32
44
- // These fields are not accessible from assembly
45
- bytes memory array = msg .data ;
46
- uint256 index = msg .data .length ;
33
+ // These fields are not accessible from assembly
34
+ bytes memory array = msg .data ;
35
+ uint256 index = msg .data .length ;
47
36
48
- // solhint-disable-next-line no-inline-assembly
49
- assembly {
50
- // Load the 32 bytes word from memory with the address on the lower 20 bytes, and mask those.
51
- result := and (
52
- mload (add (array, index)),
53
- 0xffffffffffffffffffffffffffffffffffffffff
54
- )
37
+ // solhint-disable-next-line no-inline-assembly
38
+ assembly {
39
+ // Load the 32 bytes word from memory with the address on the lower 20 bytes, and mask those.
40
+ msgSender := and (
41
+ mload (add (array, index)),
42
+ 0xffffffffffffffffffffffffffffffffffffffff
43
+ )
44
+ }
45
+ } else {
46
+ msgSender = msg .sender ;
55
47
}
56
- return result;
57
48
}
58
49
}
0 commit comments