Skip to content

Commit 8c49b3b

Browse files
authored
feat: Forwards-compatible getRelayDataHash() (#852)
Promoting address (bytes20) -> bytes32 and uint32 -> uint256 produces identical RelayData hashes. This is verified by the existing tests passing (they are verified against the existing SpokePool deployments with address and uint32 in RelayData).
1 parent 9d6ccee commit 8c49b3b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/utils/SpokeUtils.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,26 +222,34 @@ export async function getDepositIdAtBlock(contract: Contract, blockTag: number):
222222
* @returns The corresponding RelayData hash.
223223
*/
224224
export function getRelayDataHash(relayData: RelayData, destinationChainId: number): string {
225+
const _relayData = {
226+
...relayData,
227+
depositor: ethersUtils.hexZeroPad(relayData.depositor, 32),
228+
recipient: ethersUtils.hexZeroPad(relayData.recipient, 32),
229+
inputToken: ethersUtils.hexZeroPad(relayData.inputToken, 32),
230+
outputToken: ethersUtils.hexZeroPad(relayData.outputToken, 32),
231+
exclusiveRelayer: ethersUtils.hexZeroPad(relayData.exclusiveRelayer, 32),
232+
};
225233
return ethersUtils.keccak256(
226234
ethersUtils.defaultAbiCoder.encode(
227235
[
228236
"tuple(" +
229-
"address depositor," +
230-
"address recipient," +
231-
"address exclusiveRelayer," +
232-
"address inputToken," +
233-
"address outputToken," +
237+
"bytes32 depositor," +
238+
"bytes32 recipient," +
239+
"bytes32 exclusiveRelayer," +
240+
"bytes32 inputToken," +
241+
"bytes32 outputToken," +
234242
"uint256 inputAmount," +
235243
"uint256 outputAmount," +
236244
"uint256 originChainId," +
237-
"uint32 depositId," +
245+
"uint256 depositId," +
238246
"uint32 fillDeadline," +
239247
"uint32 exclusivityDeadline," +
240248
"bytes message" +
241249
")",
242250
"uint256 destinationChainId",
243251
],
244-
[relayData, destinationChainId]
252+
[_relayData, destinationChainId]
245253
)
246254
);
247255
}

0 commit comments

Comments
 (0)