Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit b8b5d47

Browse files
agryaznovdvc94ch
andauthored
port timechain#1544 to here (#45)
Co-authored-by: David Craven <[email protected]>
1 parent 62ce628 commit b8b5d47

18 files changed

+125
-63
lines changed

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ solc = '0.8.28'
2121
# - https://ethereumclassic.org/knowledge/history
2222
evm_version = 'shanghai'
2323
optimizer = true
24-
optimizer_runs = 200000
24+
optimizer_runs = 500000
2525

2626
###############
2727
# EVM options #

remappings.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/GatewayProxy.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pragma solidity >=0.8.0;
55

66
import {ERC1967} from "./utils/ERC1967.sol";
7-
import {Context, CreateKind, IUniversalFactory} from "@universal-factory/IUniversalFactory.sol";
7+
import {Context, CreateKind, IUniversalFactory} from "../lib/universal-factory/src/IUniversalFactory.sol";
88

99
contract GatewayProxy {
1010
/**

src/Primitives.sol

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ library PrimitiveUtils {
281281
bytes memory onGmpReceived = callback.callback;
282282
bytes32 dataHash;
283283
assembly ("memory-safe") {
284-
let offset := add(onGmpReceived, 0xa4)
284+
let offset := add(onGmpReceived, 0xc4)
285285
dataHash := keccak256(add(offset, 0x20), mload(offset))
286286
}
287287
callback.eip712hash = bytes32(GMP_VERSION);
@@ -332,9 +332,10 @@ library PrimitiveUtils {
332332
// | 0x0124..0x0144 <- onGmpReceived.id
333333
// | 0x0144..0x0164 <- onGmpReceived.network
334334
// | 0x0164..0x0184 <- onGmpReceived.source
335-
// | 0x0184..0x01a4 <- onGmpReceived.data.offset
336-
// | 0x01a4..0x01c4 <- onGmpReceived.data.length
337-
// | 0x01c4........ <- onGmpReceived.data
335+
// | 0x0184..0x01a4 <- onGmpReceived.nonce
336+
// | 0x01a4..0x01c4 <- onGmpReceived.data.offset
337+
// | 0x01c4..0x01e4 <- onGmpReceived.data.length
338+
// | 0x01e4........ <- onGmpReceived.data
338339
if (isCalldata) {
339340
GmpMessage calldata m = _intoCalldataPointer(message);
340341
callback.source = m.source;
@@ -345,10 +346,11 @@ library PrimitiveUtils {
345346
callback.nonce = m.nonce;
346347
bytes calldata data = m.data;
347348
callback.callback = abi.encodeWithSignature(
348-
"onGmpReceived(bytes32,uint128,bytes32,bytes)",
349+
"onGmpReceived(bytes32,uint128,bytes32,uint64,bytes)",
349350
callback.eip712hash,
350351
callback.srcNetwork,
351352
callback.source,
353+
callback.nonce,
352354
data
353355
);
354356
} else {
@@ -360,10 +362,11 @@ library PrimitiveUtils {
360362
callback.gasLimit = m.gasLimit;
361363
callback.nonce = m.nonce;
362364
callback.callback = abi.encodeWithSignature(
363-
"onGmpReceived(bytes32,uint128,bytes32,bytes)",
365+
"onGmpReceived(bytes32,uint128,bytes32,uint64,bytes)",
364366
callback.eip712hash,
365367
callback.srcNetwork,
366368
callback.source,
369+
callback.nonce,
367370
m.data
368371
);
369372
}

src/interfaces/IGmpReceiver.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface IGmpReceiver {
1717
* @param payload The message payload with no specified format
1818
* @return 32 byte result which will be stored together with GMP message
1919
*/
20-
function onGmpReceived(bytes32 id, uint128 network, bytes32 source, bytes calldata payload)
20+
function onGmpReceived(bytes32 id, uint128 network, bytes32 source, uint64 nonce, bytes calldata payload)
2121
external
2222
payable
2323
returns (bytes32);

src/utils/GasUtils.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ library GasUtils {
4343
/**
4444
* @dev Base cost of the `IExecutor.execute` method.
4545
*/
46-
uint256 internal constant EXECUTION_BASE_COST = EXECUTION_SELECTOR_OVERHEAD + 46960;
46+
uint256 internal constant EXECUTION_BASE_COST = EXECUTION_SELECTOR_OVERHEAD + 46960 + 38;
4747

4848
/**
4949
* @dev Base cost of the `IGateway.submitMessage` method.
@@ -347,7 +347,7 @@ library GasUtils {
347347
uint256 gas = _toWord(messageSize) * 3;
348348
gas = gas.saturatingAdd(_toWord(messageSize) * 6);
349349
gas = gas.saturatingAdd(gasUsed);
350-
uint256 memoryExpansion = messageSize.align32() + 0x80 + 0x0120 + 164 + 0x40;
350+
uint256 memoryExpansion = messageSize.align32() + 0x80 + 0x0120 + 164 + 0x40 + 32;
351351
{
352352
// Selector + Signature + GmpMessage
353353
uint256 words = messageSize.align32().saturatingAdd(388 + 31) >> 5;

test/Batching.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ pragma solidity >=0.8.0;
55

66
import {Test, console, Vm} from "forge-std/Test.sol";
77
import {VmSafe} from "forge-std/Vm.sol";
8-
import {FactoryUtils} from "@universal-factory/FactoryUtils.sol";
9-
import {IUniversalFactory} from "@universal-factory/IUniversalFactory.sol";
8+
import {FactoryUtils} from "../lib/universal-factory/src/FactoryUtils.sol";
9+
import {IUniversalFactory} from "../lib/universal-factory/src/IUniversalFactory.sol";
1010
import {TestUtils, SigningKey, SigningUtils} from "./TestUtils.sol";
1111
import {GasSpender} from "./utils/GasSpender.sol";
1212
import {BaseTest} from "./utils/BaseTest.sol";
@@ -161,6 +161,7 @@ contract Batching is BaseTest {
161161
0x0000000000000000000000000000000000000000000000000000000000000000,
162162
1,
163163
0x0000000000000000000000000000000000000000000000000000000000000000,
164+
0,
164165
abi.encode(gasToWaste)
165166
)
166167
);

test/GasUtils.t.sol

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ contract GasUtilsTest is BaseTest {
120120
dest: gmpReceiver,
121121
destNetwork: DEST_NETWORK_ID,
122122
gasLimit: gasLimit,
123-
nonce: 0,
123+
nonce: 1,
124124
data: data
125125
});
126126

@@ -221,21 +221,21 @@ contract GasUtilsTest is BaseTest {
221221

222222
function test_gasUtils() external pure {
223223
uint256 baseCost = GasUtils.EXECUTION_BASE_COST;
224-
assertEq(GasUtils.estimateGas(0, 0, 0), 31528 + baseCost);
225-
assertEq(GasUtils.estimateGas(0, 33, 0), 31901 + baseCost);
226-
assertEq(GasUtils.estimateGas(33, 0, 0), 32561 + baseCost);
227-
assertEq(GasUtils.estimateGas(20, 13, 0), 32301 + baseCost);
224+
assertEq(GasUtils.estimateGas(0, 0, 0), 31531 + baseCost);
225+
assertEq(GasUtils.estimateGas(0, 33, 0), 31904 + baseCost);
226+
assertEq(GasUtils.estimateGas(33, 0, 0), 32564 + baseCost);
227+
assertEq(GasUtils.estimateGas(20, 13, 0), 32304 + baseCost);
228228

229229
UFloat9x56 one = UFloatMath.ONE;
230-
assertEq(GasUtils.estimateWeiCost(one, 0, 0, 0, 0), 31528 + baseCost);
231-
assertEq(GasUtils.estimateWeiCost(one, 0, 0, 33, 0), 31901 + baseCost);
232-
assertEq(GasUtils.estimateWeiCost(one, 0, 33, 0, 0), 32561 + baseCost);
233-
assertEq(GasUtils.estimateWeiCost(one, 0, 20, 13, 0), 32301 + baseCost);
230+
assertEq(GasUtils.estimateWeiCost(one, 0, 0, 0, 0), 31531 + baseCost);
231+
assertEq(GasUtils.estimateWeiCost(one, 0, 0, 33, 0), 31904 + baseCost);
232+
assertEq(GasUtils.estimateWeiCost(one, 0, 33, 0, 0), 32564 + baseCost);
233+
assertEq(GasUtils.estimateWeiCost(one, 0, 20, 13, 0), 32304 + baseCost);
234234

235235
UFloat9x56 two = UFloat9x56.wrap(0x8080000000000000);
236-
assertEq(GasUtils.estimateWeiCost(two, 0, 0, 0, 0), (31528 + baseCost) * 2);
237-
assertEq(GasUtils.estimateWeiCost(two, 0, 0, 33, 0), (31901 + baseCost) * 2);
238-
assertEq(GasUtils.estimateWeiCost(two, 0, 33, 0, 0), (32561 + baseCost) * 2);
239-
assertEq(GasUtils.estimateWeiCost(two, 0, 20, 13, 0), (32301 + baseCost) * 2);
236+
assertEq(GasUtils.estimateWeiCost(two, 0, 0, 0, 0), (31531 + baseCost) * 2);
237+
assertEq(GasUtils.estimateWeiCost(two, 0, 0, 33, 0), (31904 + baseCost) * 2);
238+
assertEq(GasUtils.estimateWeiCost(two, 0, 33, 0, 0), (32564 + baseCost) * 2);
239+
assertEq(GasUtils.estimateWeiCost(two, 0, 20, 13, 0), (32304 + baseCost) * 2);
240240
}
241241
}

test/Gateway.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,22 @@ contract GatewayTest is BaseTest {
328328
0x0000000000000000000000000000000000000000000000000000000000000000,
329329
1,
330330
0x0000000000000000000000000000000000000000000000000000000000000000,
331+
0,
331332
abi.encode(uint256(1234))
332333
)
333334
);
334335
// Calling the receiver contract directly to make the address warm
335336
address sender = TestUtils.createTestAccount(10 ether);
336337
(uint256 gasUsed,, bytes memory output) =
337-
TestUtils.executeCall(sender, address(receiver), 23_318, 0, testEncodedCall);
338+
TestUtils.executeCall(sender, address(receiver), 23_318 + 128, 0, testEncodedCall);
338339
assertEq(gasUsed, 1234);
339340
assertEq(output.length, 32);
340341
}
341342

342343
function test_estimateMessageCost() external {
343344
vm.txGasPrice(1);
344345
uint256 cost = gateway.estimateMessageCost(DEST_NETWORK_ID, 96, 100000);
345-
assertEq(cost, GasUtils.EXECUTION_BASE_COST + 133821);
346+
assertEq(cost, GasUtils.EXECUTION_BASE_COST + 133824);
346347
}
347348

348349
function test_checkPayloadSize() external {

test/GatewayProxy.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
pragma solidity >=0.8.0;
55

6-
import {IUniversalFactory} from "@universal-factory/IUniversalFactory.sol";
7-
import {FactoryUtils} from "@universal-factory/FactoryUtils.sol";
6+
import {IUniversalFactory} from "../lib/universal-factory/src/IUniversalFactory.sol";
7+
import {FactoryUtils} from "../lib/universal-factory/src/FactoryUtils.sol";
88
import {Test, console} from "forge-std/Test.sol";
99
import {VmSafe} from "forge-std/Vm.sol";
1010
import {TestUtils, SigningKey, SigningUtils} from "./TestUtils.sol";

0 commit comments

Comments
 (0)