@@ -56,18 +56,6 @@ contract Gateway is IGateway, UUPSUpgradeable, OwnableUpgradeable {
5656 bytes32 indexed id , bytes32 indexed source , address indexed dest , GmpStatus status , bytes32 result
5757 );
5858
59- /**
60- * @dev Emitted when shards are registered.
61- * @param keys registered shard's keys
62- */
63- event ShardsRegistered (TssKey[] keys );
64-
65- /**
66- * @dev Emitted when shards are unregistered.
67- * @param keys unregistered shard's keys
68- */
69- event ShardsUnregistered (TssKey[] keys );
70-
7159 // number of signing sessions per batch
7260 mapping (uint64 => uint16 ) internal _signingSessions;
7361
@@ -112,6 +100,8 @@ contract Gateway is IGateway, UUPSUpgradeable, OwnableUpgradeable {
112100 transferOwnership (newAdmin);
113101 }
114102
103+ function _include_gmp_message (GmpMessage memory ) external {}
104+
115105 /**
116106 * Withdraw funds from the gateway contract
117107 * @param amount The amount to withdraw
@@ -142,36 +132,34 @@ contract Gateway is IGateway, UUPSUpgradeable, OwnableUpgradeable {
142132 * @dev List all shards.
143133 */
144134 function shards () external view returns (TssKey[] memory ) {
145- return ShardStore.getMainStorage ().listShards ();
135+ return ShardStore.getMainStorage ().list ();
146136 }
147137
148138 /**
149139 * @dev Register Shards in batch.
150140 */
151- function setShards (TssKey[] calldata publicKeys ) external onlyOwner {
152- (TssKey[] memory created , TssKey[] memory revoked ) = ShardStore.getMainStorage ().replaceTssKeys (publicKeys);
153-
154- if (created.length > 0 ) {
155- emit ShardsRegistered (created);
141+ function setShards (TssKey[] calldata register , TssKey[] calldata revoke ) external onlyOwner {
142+ ShardStore.MainStorage storage store = ShardStore.getMainStorage ();
143+ for (uint256 i = 0 ; i < register.length ; i++ ) {
144+ store.register (register[i]);
156145 }
157-
158- if (revoked.length > 0 ) {
159- emit ShardsUnregistered (revoked);
146+ for (uint256 i = 0 ; i < revoke.length ; i++ ) {
147+ store.revoke (revoke[i]);
160148 }
161149 }
162150
163151 /**
164152 * @dev List all routes.
165153 */
166154 function routes () external view returns (Route[] memory ) {
167- return RouteStore.getMainStorage ().listRoutes ();
155+ return RouteStore.getMainStorage ().list ();
168156 }
169157
170158 /**
171159 * @dev Create or update a single route
172160 */
173161 function setRoute (Route calldata info ) external onlyOwner {
174- RouteStore.getMainStorage ().createOrUpdateRoute (info);
162+ RouteStore.getMainStorage ().insert (info);
175163 }
176164
177165 // IGateway implementation
@@ -344,12 +332,7 @@ contract Gateway is IGateway, UUPSUpgradeable, OwnableUpgradeable {
344332 return operationHash;
345333 }
346334
347- bool isSuccess = ShardStore.getMainStorage ().register (publicKey);
348- if (isSuccess) {
349- TssKey[] memory keys = new TssKey [](1 );
350- keys[0 ] = publicKey;
351- emit ShardsRegistered (keys);
352- }
335+ ShardStore.getMainStorage ().register (publicKey);
353336 }
354337
355338 /**
@@ -367,12 +350,7 @@ contract Gateway is IGateway, UUPSUpgradeable, OwnableUpgradeable {
367350 return operationHash;
368351 }
369352
370- bool isSuccess = ShardStore.getMainStorage ().revoke (publicKey);
371- if (isSuccess) {
372- TssKey[] memory keys = new TssKey [](1 );
373- keys[0 ] = publicKey;
374- emit ShardsUnregistered (keys);
375- }
353+ ShardStore.getMainStorage ().revoke (publicKey);
376354 }
377355
378356 /**
@@ -478,10 +456,14 @@ contract Gateway is IGateway, UUPSUpgradeable, OwnableUpgradeable {
478456 function execute (Signature calldata signature , Batch calldata batch ) external {
479457 uint256 initialGas = gasleft ();
480458
459+ // Load shard from storage
460+ ShardStore.ShardInfo storage signer = ShardStore.getMainStorage ().get (signature.xCoord);
461+
481462 uint16 numSigningSessions = _signingSessions[batch.batchId];
482463 bool dry;
483464 if (numSigningSessions == 0 ) {
484- numSigningSessions = batch.numSigningSessions;
465+ numSigningSessions = signer.numSessions;
466+ emit BatchExecuted (batch.batchId);
485467 } else if (numSigningSessions == 1 ) {
486468 revert ("batch already executed " );
487469 } else if (numSigningSessions > 1 ) {
@@ -492,17 +474,13 @@ contract Gateway is IGateway, UUPSUpgradeable, OwnableUpgradeable {
492474
493475 // Execute the commands and compute the operations root hash
494476 (, bytes32 rootHash ) = _executeCommands (batch.ops, dry);
495- emit BatchExecuted (batch.batchId);
496477
497478 // Compute the Batch signing hash
498- rootHash = PrimitiveUtils.hash (batch.version, batch.batchId, batch.numSigningSessions, uint256 (rootHash));
479+ rootHash = PrimitiveUtils.hash (batch.version, batch.batchId, uint256 (rootHash));
499480 bytes32 signingHash = keccak256 (
500481 abi.encodePacked ("Analog GMP v2 " , networkId (), bytes32 (uint256 (uint160 (address (this )))), rootHash)
501482 );
502483
503- // Load shard from storage
504- ShardStore.ShardInfo storage signer = ShardStore.getMainStorage ().get (signature);
505-
506484 // Verify Signature
507485 require (
508486 Schnorr.verify (signer.yParity, signature.xCoord, uint256 (signingHash), signature.e, signature.s),
@@ -512,7 +490,7 @@ contract Gateway is IGateway, UUPSUpgradeable, OwnableUpgradeable {
512490 // Refund the chronicle gas
513491 unchecked {
514492 // Extra gas overhead used to execute the refund logic + selector overhead
515- uint256 gasUsed = 2890 ;
493+ uint256 gasUsed = 2968 ;
516494
517495 // Compute the gas used + base cost + proxy overhead
518496 gasUsed += GasUtils.txBaseGas ();
0 commit comments