Skip to content

Commit 93d35e2

Browse files
committed
remove _getRelayedCallSender helper
1 parent caf52fc commit 93d35e2

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

contracts/utils/_MetaTransactionContext.sol

+20-29
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,29 @@ abstract contract _MetaTransactionContext is _Context {
2121
returns (address msgSender)
2222
{
2323
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.
2929

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.
4332

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;
4736

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;
5547
}
56-
return result;
5748
}
5849
}

0 commit comments

Comments
 (0)