Skip to content

Commit

Permalink
Move functions to the correct section Gateway.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohann committed Jan 2, 2025
1 parent 5fc0c36 commit aa97bcb
Showing 1 changed file with 44 additions and 45 deletions.
89 changes: 44 additions & 45 deletions src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,50 +147,6 @@ contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712 {
);
}

/**
* @dev Execute a single GMP message.
* IMPORTANT: This method doesn't check if the `params` are a valid `GmpMessage`, this must be done by the caller.
*/
function _gmpCommand(bytes calldata params) private returns (bytes32 operationHash) {
require(params.length >= 256, "invalid GmpMessage");
GmpMessage calldata gmp;
assembly {
gmp := add(params.offset, 0x20)
}
_checkGmpMessage(gmp);
// Convert the `GmpMessage` into `GmpCallback`, which is a more efficient representation.
// see `src/Primitives.sol` for more details.
GmpCallback memory callback = gmp.intoCallback();
operationHash = callback.eip712hash;
_execute(callback);
}

/**
* @dev Register a single shard, and returns the operation hash.
*/
function _registerShardCommand(bytes calldata params) private returns (bytes32 operationHash) {
require(params.length == 64, "invalid TssKey");
TssKey calldata newShard;
assembly {
newShard := params.offset
}
operationHash = Hashing.hash(newShard.yParity, newShard.xCoord);
_setShard(newShard);
}

/**
* @dev Removes a single shard from the set.
*/
function _unregisterShardCommand(bytes calldata params) private returns (bytes32 operationHash) {
require(params.length == 64, "invalid TssKey");
TssKey calldata shard;
assembly {
shard := params.offset
}
operationHash = Hashing.hash(shard.yParity, shard.xCoord);
_revokeShard(shard);
}

// Register/Revoke TSS keys using shard TSS signature
function updateKeys(Signature calldata signature, UpdateKeysMessage calldata message) external {
// Check if the message was already executed to prevent replay attacks
Expand Down Expand Up @@ -233,6 +189,49 @@ contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712 {
*/
type CommandsLookUpTable is uint256;

/**
* @dev Dispatch a single GMP message.
*/
function _gmpCommand(bytes calldata params) private returns (bytes32 operationHash) {
require(params.length >= 256, "invalid GmpMessage");
GmpMessage calldata gmp;
assembly {
gmp := add(params.offset, 0x20)
}
_checkGmpMessage(gmp);
// Convert the `GmpMessage` into `GmpCallback`, which is a more efficient representation.
// see `src/Primitives.sol` for more details.
GmpCallback memory callback = gmp.intoCallback();
operationHash = callback.eip712hash;
_execute(callback);
}

/**
* @dev Register a single shard and returns the GatewayOp hash.
*/
function _registerShardCommand(bytes calldata params) private returns (bytes32 operationHash) {
require(params.length == 64, "invalid TssKey");
TssKey calldata newShard;
assembly {
newShard := params.offset
}
operationHash = Hashing.hash(newShard.yParity, newShard.xCoord);
_setShard(newShard);
}

/**
* @dev Removes a single shard from the set.
*/
function _unregisterShardCommand(bytes calldata params) private returns (bytes32 operationHash) {
require(params.length == 64, "invalid TssKey");
TssKey calldata shard;
assembly {
shard := params.offset
}
operationHash = Hashing.hash(shard.yParity, shard.xCoord);
_revokeShard(shard);
}

/**
* Cast the command function into a uint256.
*/
Expand Down Expand Up @@ -330,7 +329,7 @@ contract Gateway is IGateway, IExecutor, IUpgradable, GatewayEIP712 {
}

/**
* @dev Verify and dispatch messages from the Timechain in batch.
* @dev Verify and dispatch messages from the Timechain.
*/
function batchExecute(Signature calldata signature, InboundMessage calldata message) external {
uint256 initialGas = gasleft();
Expand Down

0 comments on commit aa97bcb

Please sign in to comment.