ERC2771Context gas improvements (#5590)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -55,8 +55,10 @@ abstract contract ERC2771Context is Context {
|
|||||||
function _msgSender() internal view virtual override returns (address) {
|
function _msgSender() internal view virtual override returns (address) {
|
||||||
uint256 calldataLength = msg.data.length;
|
uint256 calldataLength = msg.data.length;
|
||||||
uint256 contextSuffixLength = _contextSuffixLength();
|
uint256 contextSuffixLength = _contextSuffixLength();
|
||||||
if (isTrustedForwarder(msg.sender) && calldataLength >= contextSuffixLength) {
|
if (calldataLength >= contextSuffixLength && isTrustedForwarder(msg.sender)) {
|
||||||
return address(bytes20(msg.data[calldataLength - contextSuffixLength:]));
|
unchecked {
|
||||||
|
return address(bytes20(msg.data[calldataLength - contextSuffixLength:]));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return super._msgSender();
|
return super._msgSender();
|
||||||
}
|
}
|
||||||
@ -70,8 +72,10 @@ abstract contract ERC2771Context is Context {
|
|||||||
function _msgData() internal view virtual override returns (bytes calldata) {
|
function _msgData() internal view virtual override returns (bytes calldata) {
|
||||||
uint256 calldataLength = msg.data.length;
|
uint256 calldataLength = msg.data.length;
|
||||||
uint256 contextSuffixLength = _contextSuffixLength();
|
uint256 contextSuffixLength = _contextSuffixLength();
|
||||||
if (isTrustedForwarder(msg.sender) && calldataLength >= contextSuffixLength) {
|
if (calldataLength >= contextSuffixLength && isTrustedForwarder(msg.sender)) {
|
||||||
return msg.data[:calldataLength - contextSuffixLength];
|
unchecked {
|
||||||
|
return msg.data[:calldataLength - contextSuffixLength];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return super._msgData();
|
return super._msgData();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user