Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions contracts/SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ abstract contract SpokePool is
relayData.exclusiveRelayer,
relayData.depositor,
relayData.recipient,
relayData.message
_hashNonEmptyMessage(relayData.message)
);
}

Expand Down Expand Up @@ -1711,10 +1711,10 @@ abstract contract SpokePool is
relayer,
relayData.depositor,
relayData.recipient,
relayData.message,
_hashNonEmptyMessage(relayData.message),
V3RelayExecutionEventInfo({
updatedRecipient: relayExecution.updatedRecipient,
updatedMessage: relayExecution.updatedMessage,
updatedMessageHash: _hashNonEmptyMessage(relayExecution.updatedMessage),
updatedOutputAmount: relayExecution.updatedOutputAmount,
fillType: fillType
})
Expand Down Expand Up @@ -1764,6 +1764,12 @@ abstract contract SpokePool is
return exclusivityDeadline >= currentTime;
}

// Helper for emitting message hash. For easier easier human readability we return bytes32(0) for empty message.
function _hashNonEmptyMessage(bytes memory message) internal pure returns (bytes32) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this a little bit to make it shorter but otherwise looks perfect.

if (message.length == 0) return bytes32(0);
else return keccak256(message);
}

// Implementing contract needs to override this to ensure that only the appropriate cross chain admin can execute
// certain admin functions. For L2 contracts, the cross chain admin refers to some L1 address or contract, and for
// L1, this would just be the same admin of the HubPool.
Expand Down
6 changes: 3 additions & 3 deletions contracts/interfaces/V3SpokePoolInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ interface V3SpokePoolInterface {
// filled so they don't have to be unpacked by all clients.
struct V3RelayExecutionEventInfo {
bytes32 updatedRecipient;
bytes updatedMessage;
bytes32 updatedMessageHash;
uint256 updatedOutputAmount;
FillType fillType;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ interface V3SpokePoolInterface {
bytes32 indexed relayer,
bytes32 depositor,
bytes32 recipient,
bytes message,
bytes32 messageHash,
V3RelayExecutionEventInfo relayExecutionInfo
);

Expand All @@ -168,7 +168,7 @@ interface V3SpokePoolInterface {
bytes32 exclusiveRelayer,
bytes32 depositor,
bytes32 recipient,
bytes message
bytes32 messageHash
);

event ClaimedRelayerRefund(
Expand Down
2 changes: 1 addition & 1 deletion programs/svm-spoke/src/state/instruction_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pub struct ExecuteRelayerRefundLeafParams {
pub root_bundle_id: u32, // ID of the root bundle to be used.
pub relayer_refund_leaf: RelayerRefundLeaf, // Leaf to be verified against the proof and instruct bundle execution.
#[max_len(0)]
pub proof: Vec<[u8; 32]>, // Proof to verify the leaf's inclusion in relayer refund merkle tree.
pub proof: Vec<[u8; 32]>, // Proof to verify the leaf's inclusion in relayer refund merkle tree.
}
21 changes: 11 additions & 10 deletions test/evm/hardhat/SpokePool.Relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
BigNumber,
addressToBytes,
bytes32ToAddress,
hashNonEmptyMessage,
} from "../../../utils/utils";
import {
spokePoolFixture,
Expand Down Expand Up @@ -130,10 +131,10 @@ describe("SpokePool Relayer Logic", async function () {
addressToBytes(relayer.address),
addressToBytes(relayData.depositor),
addressToBytes(relayData.recipient),
relayData.message,
hashNonEmptyMessage(relayData.message),
[
addressToBytes(relayData.recipient),
relayExecution.updatedMessage,
hashNonEmptyMessage(relayExecution.updatedMessage),
relayExecution.updatedOutputAmount,
// Testing that this FillType is not "FastFill"
FillType.ReplacedSlowFill,
Expand Down Expand Up @@ -166,10 +167,10 @@ describe("SpokePool Relayer Logic", async function () {
addressToBytes(relayer.address),
addressToBytes(relayData.depositor),
addressToBytes(relayData.recipient),
relayData.message,
hashNonEmptyMessage(relayData.message),
[
addressToBytes(relayData.recipient),
relayExecution.updatedMessage,
hashNonEmptyMessage(relayExecution.updatedMessage),
relayExecution.updatedOutputAmount,
// Testing that this FillType is "SlowFill"
FillType.SlowFill,
Expand Down Expand Up @@ -201,10 +202,10 @@ describe("SpokePool Relayer Logic", async function () {
addressToBytes(relayer.address),
addressToBytes(relayData.depositor),
addressToBytes(relayData.recipient),
relayData.message,
hashNonEmptyMessage(relayData.message),
[
addressToBytes(relayData.recipient),
relayExecution.updatedMessage,
hashNonEmptyMessage(relayExecution.updatedMessage),
relayExecution.updatedOutputAmount,
FillType.FastFill,
]
Expand Down Expand Up @@ -372,10 +373,10 @@ describe("SpokePool Relayer Logic", async function () {
addressToBytes(relayer.address), // Should be equal to msg.sender of fillRelayV3
addressToBytes(relayData.depositor),
addressToBytes(relayData.recipient),
relayData.message,
hashNonEmptyMessage(relayData.message),
[
addressToBytes(relayData.recipient), // updatedRecipient should be equal to recipient
relayData.message, // updatedMessage should be equal to message
hashNonEmptyMessage(relayData.message), // updatedMessageHash should be equal to message hash
relayData.outputAmount, // updatedOutputAmount should be equal to outputAmount
// Should be FastFill
FillType.FastFill,
Expand Down Expand Up @@ -487,11 +488,11 @@ describe("SpokePool Relayer Logic", async function () {
addressToBytes(relayer.address), // Should be equal to msg.sender
addressToBytes(relayData.depositor),
addressToBytes(relayData.recipient),
relayData.message,
hashNonEmptyMessage(relayData.message),
[
// Should use passed-in updated params:
addressToBytes(updatedRecipient),
updatedMessage,
hashNonEmptyMessage(updatedMessage),
updatedOutputAmount,
// Should be FastFill
FillType.FastFill,
Expand Down
5 changes: 3 additions & 2 deletions test/evm/hardhat/SpokePool.SlowRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
seedContract,
seedWallet,
addressToBytes,
hashNonEmptyMessage,
} from "../../../utils/utils";
import { spokePoolFixture, V3RelayData, getV3RelayHash, V3SlowFill, FillType } from "./fixtures/SpokePool.Fixture";
import { buildV3SlowRelayTree } from "./MerkleLib.utils";
Expand Down Expand Up @@ -309,12 +310,12 @@ describe("SpokePool Slow Relay Logic", async function () {
addressToBytes(consts.zeroAddress), // Sets relayer address to 0x0
addressToBytes(relayData.depositor),
addressToBytes(relayData.recipient),
relayData.message,
hashNonEmptyMessage(relayData.message),
[
// Uses relayData.recipient
addressToBytes(relayData.recipient),
// Uses relayData.message
relayData.message,
hashNonEmptyMessage(relayData.message),
// Uses slow fill leaf's updatedOutputAmount
slowRelayLeaf.updatedOutputAmount,
// Should be SlowFill
Expand Down
10 changes: 10 additions & 0 deletions utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ export function trimSolanaAddress(bytes32Address: string): string {
return ethers.utils.hexZeroPad(ethers.utils.hexlify(uint160Address), 20);
}

export function hashNonEmptyMessage(message: string) {
if (!ethers.utils.isHexString(message) || message.length % 2 !== 0) throw new Error("Invalid hex message bytes");

// account for 0x prefix when checking length
if (message.length > 2) {
return ethers.utils.keccak256(message);
}
return ethers.utils.hexlify(new Uint8Array(32));
}

const { defaultAbiCoder, keccak256 } = ethers.utils;

export { avmL1ToL2Alias, expect, Contract, ethers, BigNumber, defaultAbiCoder, keccak256, FakeContract, Signer };
Loading