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

Commit bec014e

Browse files
authored
Remove more stuff. (#53)
1 parent e33df7f commit bec014e

File tree

13 files changed

+99
-489
lines changed

13 files changed

+99
-489
lines changed

src/Gateway.sol

Lines changed: 42 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,26 @@ import {UFloat9x56, UFloatMath} from "./utils/Float9x56.sol";
1111
import {RouteStore} from "./storage/Routes.sol";
1212
import {ShardStore} from "./storage/Shards.sol";
1313
import {IGateway} from "./interfaces/IGateway.sol";
14-
import {IUpgradable} from "./interfaces/IUpgradable.sol";
1514
import {IGmpReceiver} from "./interfaces/IGmpReceiver.sol";
16-
import {IExecutor} from "./interfaces/IExecutor.sol";
1715
import {
1816
Command,
1917
InboundMessage,
2018
GatewayOp,
2119
GmpCallback,
2220
GmpMessage,
2321
GmpStatus,
24-
GmpSender,
25-
Network,
2622
Route,
2723
PrimitiveUtils,
28-
UpdateKeysMessage,
2924
Signature,
3025
TssKey,
3126
MAX_PAYLOAD_SIZE
3227
} from "./Primitives.sol";
33-
import {NetworkID, NetworkIDHelpers} from "./NetworkID.sol";
3428
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
3529
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
3630
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
3731
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
3832

3933
abstract contract GatewayEIP712 is Initializable {
40-
using NetworkIDHelpers for NetworkID;
41-
4234
bytes32 private constant GATEWAY_STORAGE_SLOT = keccak256("analog.gateway.storage");
4335

4436
struct GatewayEIP712Storage {
@@ -68,8 +60,7 @@ abstract contract GatewayEIP712 is Initializable {
6860
}
6961
}
7062

71-
contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712, UUPSUpgradeable, OwnableUpgradeable {
72-
using PrimitiveUtils for UpdateKeysMessage;
63+
contract Gateway is IGateway, GatewayEIP712, UUPSUpgradeable, OwnableUpgradeable {
7364
using PrimitiveUtils for GmpMessage;
7465
using PrimitiveUtils for GmpCallback;
7566
using PrimitiveUtils for address;
@@ -78,7 +69,36 @@ contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712, UUPSUpgrade
7869
using ShardStore for ShardStore.MainStorage;
7970
using RouteStore for RouteStore.MainStorage;
8071
using RouteStore for RouteStore.NetworkInfo;
81-
using NetworkIDHelpers for NetworkID;
72+
73+
/**
74+
* @dev Emitted when `GmpMessage` is executed.
75+
* @param id EIP-712 hash of the `GmpPayload`, which is it's unique identifier
76+
* @param source sender pubkey/address (the format depends on src chain)
77+
* @param dest recipient address
78+
* @param status GMP message execution status
79+
* @param result GMP result
80+
*/
81+
event GmpExecuted(
82+
bytes32 indexed id, bytes32 indexed source, address indexed dest, GmpStatus status, bytes32 result
83+
);
84+
85+
/**
86+
* @dev Emitted when a Batch is executed.
87+
* @param batch batch_id which is executed
88+
*/
89+
event BatchExecuted(uint64 batch);
90+
91+
/**
92+
* @dev Emitted when shards are registered.
93+
* @param keys registered shard's keys
94+
*/
95+
event ShardsRegistered(TssKey[] keys);
96+
97+
/**
98+
* @dev Emitted when shards are unregistered.
99+
* @param keys unregistered shard's keys
100+
*/
101+
event ShardsUnregistered(TssKey[] keys);
82102

83103
/**
84104
* @dev Selector of `GmpCreated` event.
@@ -87,11 +107,6 @@ contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712, UUPSUpgrade
87107
bytes32 private constant GMP_CREATED_EVENT_SELECTOR =
88108
0x081a0b65828c1720ce022ffb992d4a5ec86e2abc4c383acd4029ba8486e41b4f;
89109

90-
/**
91-
* @dev The address of the `UniversalFactory` contract, must be the same on all networks.
92-
*/
93-
address internal constant FACTORY = 0x0000000000001C4Bf962dF86e38F0c10c7972C6E;
94-
95110
// GMP message status
96111
mapping(bytes32 => GmpInfo) private _messages;
97112

@@ -143,7 +158,7 @@ contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712, UUPSUpgrade
143158
}
144159

145160
function networkInfo(uint16 id) external view returns (RouteStore.NetworkInfo memory) {
146-
return RouteStore.getMainStorage().get(NetworkID.wrap(id));
161+
return RouteStore.getMainStorage().get(id);
147162
}
148163

149164
/**
@@ -160,35 +175,6 @@ contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712, UUPSUpgrade
160175
);
161176
}
162177

163-
// Register/Revoke TSS keys using shard TSS signature
164-
function updateKeys(Signature calldata signature, UpdateKeysMessage calldata message) external {
165-
// Check if the message was already executed to prevent replay attacks
166-
bytes32 messageHash = message.eip712hash();
167-
require(_executedMessages[messageHash] == bytes32(0), "message already executed");
168-
169-
// Verify the signature and store the message hash
170-
_verifySignature(signature, messageHash);
171-
_executedMessages[messageHash] = bytes32(signature.xCoord);
172-
173-
// Register/Revoke shards pubkeys
174-
ShardStore.MainStorage storage store = ShardStore.getMainStorage();
175-
176-
// Revoke tss keys (revoked keys can be registred again keeping the previous nonce)
177-
store.revokeKeys(message.revoke);
178-
179-
// Register or activate revoked keys
180-
store.registerTssKeys(message.register);
181-
182-
// Emit event
183-
if (message.revoke.length > 0) {
184-
emit ShardsUnregistered(message.revoke);
185-
}
186-
187-
if (message.register.length > 0) {
188-
emit ShardsRegistered(message.register);
189-
}
190-
}
191-
192178
/*//////////////////////////////////////////////////////////////
193179
GATEWAY OPERATIONS AND COMMANDS
194180
//////////////////////////////////////////////////////////////*/
@@ -505,11 +491,11 @@ contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712, UUPSUpgrade
505491
/**
506492
* @dev Send message from this chain to another chain.
507493
* @param destinationAddress the target address on the destination chain
508-
* @param routeId the target chain where the contract call will be made
494+
* @param network the target chain where the contract call will be made
509495
* @param executionGasLimit the gas limit available for the contract call
510496
* @param data message data with no specified format
511497
*/
512-
function submitMessage(address destinationAddress, uint16 routeId, uint256 executionGasLimit, bytes calldata data)
498+
function submitMessage(address destinationAddress, uint16 network, uint256 executionGasLimit, bytes calldata data)
513499
external
514500
payable
515501
returns (bytes32)
@@ -519,28 +505,28 @@ contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712, UUPSUpgrade
519505

520506
// Check if the provided parameters are valid
521507
// See `RouteStorage.estimateWeiCost` at `storage/Routes.sol` for more details.
522-
RouteStore.NetworkInfo memory route = RouteStore.getMainStorage().get(NetworkID.wrap(routeId));
508+
RouteStore.NetworkInfo memory route = RouteStore.getMainStorage().get(network);
523509
(uint256 gasCost, uint256 fee) = route.estimateCost(data, executionGasLimit);
524510
require(msg.value >= fee, "insufficient tx value");
525511

526512
// We use 20 bytes for represent the address and 1 bit for the contract flag
527-
GmpSender source = msg.sender.toSender(false);
513+
bytes32 source = msg.sender.toSender();
528514

529515
unchecked {
530516
// Nonce is per sender, it's incremented for every message sent.
531517
uint64 nextNonce = uint64(_nonces[msg.sender]++);
532518

533519
// Create GMP message and update nonce
534520
GmpMessage memory message = GmpMessage(
535-
source, NETWORK_ID(), destinationAddress, routeId, uint64(executionGasLimit), nextNonce, data
521+
source, NETWORK_ID(), destinationAddress, network, uint64(executionGasLimit), nextNonce, data
536522
);
537523

538524
// Emit `GmpCreated` event without copy the data, to simplify the gas estimation.
539525
_emitGmpCreated(
540526
message.messageId(),
541527
source,
542528
destinationAddress,
543-
routeId,
529+
network,
544530
executionGasLimit,
545531
gasCost,
546532
nextNonce,
@@ -554,7 +540,7 @@ contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712, UUPSUpgrade
554540
*/
555541
function _emitGmpCreated(
556542
bytes32 messageID,
557-
GmpSender source,
543+
bytes32 source,
558544
address destinationAddress,
559545
uint16 destinationNetwork,
560546
uint256 executionGasLimit,
@@ -590,16 +576,16 @@ contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712, UUPSUpgrade
590576
/**
591577
* @notice Estimate the gas cost of execute a GMP message.
592578
* @dev This function is called on the destination chain before calling the gateway to execute a source contract.
593-
* @param networkid The target chain where the contract call will be made
579+
* @param network The target chain where the contract call will be made
594580
* @param messageSize Message size
595581
* @param messageSize Message gas limit
596582
*/
597-
function estimateMessageCost(uint16 networkid, uint256 messageSize, uint256 gasLimit)
583+
function estimateMessageCost(uint16 network, uint256 messageSize, uint256 gasLimit)
598584
external
599585
view
600586
returns (uint256)
601587
{
602-
RouteStore.NetworkInfo memory route = RouteStore.getMainStorage().get(NetworkID.wrap(networkid));
588+
RouteStore.NetworkInfo memory route = RouteStore.getMainStorage().get(network);
603589

604590
// Estimate the cost
605591
return route.estimateWeiCost(uint16(messageSize), gasLimit);

src/NetworkID.sol

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

0 commit comments

Comments
 (0)