Skip to content

Commit

Permalink
chore: add payload_hash to gateway module
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Sep 2, 2023
1 parent e1371f4 commit d1a84de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Todo: remove this file once we have a proper gateway module
module axelar::gateway {
use sui::event::emit;
use sui::hash::keccak256;

struct ContractCall has copy, drop {
source: vector<u8>,
destination_chain: vector<u8>,
destination_address: vector<u8>,
payload: vector<u8>,
payload_hash: vector<u8>,
}

public fun call_contract(destination_chain: vector<u8>, destination_address: vector<u8>, payload: vector<u8>) {
Expand All @@ -15,6 +17,7 @@ module axelar::gateway {
destination_chain,
destination_address,
payload,
payload_hash: keccak256(&payload)
});
}
}
21 changes: 15 additions & 6 deletions packages/axelar-local-dev-sui/src/SuiRelayer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ethers } from 'ethers';
import { arrayify, defaultAbiCoder } from 'ethers/lib/utils';
import { arrayify, defaultAbiCoder, hexlify, keccak256 } from 'ethers/lib/utils';
import {
logger,
getSignedExecuteInput,
Expand All @@ -16,6 +15,8 @@ import { Command as SuiCommand } from './Command';
import { SuiNetwork } from './SuiNetwork';
import { getCommandId } from './utils';

const DEFAULT_GAS_LIMIT = BigInt(8e6);

export class SuiRelayer extends Relayer {
private suiNetwork: SuiNetwork;
private lastQueryMs: number = new Date().getTime();
Expand Down Expand Up @@ -48,7 +49,7 @@ export class SuiRelayer extends Relayer {
async executeSuiToEvm(commandList: RelayCommand) {
for (const to of networks) {
const commands = commandList[to.name];
if (commands.length == 0) continue;
if (commands.length === 0) continue;

const execution = await this.executeEvmGateway(to, commands);
await this.executeEvmExecutable(to, commands, execution);
Expand Down Expand Up @@ -86,7 +87,7 @@ export class SuiRelayer extends Relayer {

return to.gateway
.connect(to.ownerWallet)
.execute(signedData, { gasLimit: BigInt(8e6) })
.execute(signedData, { gasLimit: DEFAULT_GAS_LIMIT })
.then((tx: any) => tx.wait());
}

Expand Down Expand Up @@ -127,9 +128,16 @@ export class SuiRelayer extends Relayer {
const commandId = getCommandId(event.id);
const eventParams = event.parsedJson as any;

const { destination_address: destinationAddress, destination_chain: destinationChain, payload } = eventParams;
const {
destination_address: destinationAddress,
destination_chain: destinationChain,
payload,
payload_hash: _payloadHash,
} = eventParams;

const payloadHash = ethers.utils.keccak256(this.convertUint8ArrayToUtf8String(payload));
// TODO: Investigate why using the payload hash directly causes relay failure.
// Current workaround: use keccak256 hash of the payload.
const payloadHash = keccak256(this.convertUint8ArrayToUtf8String(payload));

const contractCallArgs: CallContractArgs = {
from: 'sui',
Expand All @@ -138,6 +146,7 @@ export class SuiRelayer extends Relayer {
payload: this.convertUint8ArrayToUtf8String(payload),
sourceAddress: event.packageId,
transactionHash: event.id.txDigest,
// payloadHash: hexlify(_payloadHash),
payloadHash,
sourceEventIndex: parseInt(event.id.eventSeq),
};
Expand Down

0 comments on commit d1a84de

Please sign in to comment.