From bb73c44ee740f7ec9460ffedee79998d1eb57c1f Mon Sep 17 00:00:00 2001 From: BotchM Date: Mon, 20 Jun 2022 13:14:26 +0300 Subject: [PATCH] gas optimizations on terabethia contract --- core/eth/contracts/Terabethia.sol | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/core/eth/contracts/Terabethia.sol b/core/eth/contracts/Terabethia.sol index 7680c8a1..aaba2924 100644 --- a/core/eth/contracts/Terabethia.sol +++ b/core/eth/contracts/Terabethia.sol @@ -67,27 +67,26 @@ contract Terabethia is Initializable, ITerabethiaCore { external returns (bytes32) { - simpleStorage().nonce += 1; + unchecked { + simpleStorage().nonce += 1; + } + + uint256 nonce = simpleStorage().nonce; bytes32 msgHash = keccak256( abi.encodePacked( uint256(uint160(msg.sender)), to_address, - simpleStorage().nonce, + nonce, payload.length, payload ) ); - simpleStorage().messages[msgHash] += 1; + simpleStorage().messages[msgHash] = 1; // we only emit event, so we can auto-trigger message consumption on the IC - emit LogMessageToL2( - msg.sender, - to_address, - simpleStorage().nonce, - payload - ); + emit LogMessageToL2(msg.sender, to_address, nonce, payload); return msgHash; }