Skip to content
Draft
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
92 changes: 46 additions & 46 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
EscrowFactoryTest:test_MultipleFillsInvalidKey() (gas: 474157)
EscrowFactoryTest:test_MultipleFillsInvalidSecretsAmount() (gas: 473799)
EscrowFactoryTest:test_MultipleFillsInvalidKey() (gas: 474211)
EscrowFactoryTest:test_MultipleFillsInvalidSecretsAmount() (gas: 473853)
EscrowFactoryTest:test_NoDeploymentForNotResolver() (gas: 195258)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMaker() (gas: 128468)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMaker() (gas: 128523)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForTaker() (gas: 27118)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForMaker() (gas: 121693)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForMaker() (gas: 121748)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForTaker() (gas: 27377)
EscrowFactoryTest:test_NoUnsafeDeploymentForTaker() (gas: 34495)
EscrowTest:test_CancelDst() (gas: 116076)
EscrowTest:test_CancelDstDifferentTarget() (gas: 143334)
EscrowTest:test_CancelDstWithNativeToken() (gas: 93670)
EscrowTest:test_CancelPublicSrc() (gas: 170900)
EscrowTest:test_CancelResolverSrc() (gas: 168607)
EscrowTest:test_CancelResolverSrcReceiver() (gas: 179361)
EscrowTest:test_NoAnyoneCancelDuringResolverCancelSrc() (gas: 163836)
EscrowTest:test_NoCallsWithInvalidImmutables() (gas: 286516)
EscrowTest:test_CancelPublicSrc() (gas: 170955)
EscrowTest:test_CancelResolverSrc() (gas: 168679)
EscrowTest:test_CancelResolverSrcReceiver() (gas: 179430)
EscrowTest:test_NoAnyoneCancelDuringResolverCancelSrc() (gas: 163911)
EscrowTest:test_NoCallsWithInvalidImmutables() (gas: 286571)
EscrowTest:test_NoCancelByAnyoneDst() (gas: 121726)
EscrowTest:test_NoCancelDuringWithdrawalDst() (gas: 121486)
EscrowTest:test_NoCancelDuringWithdrawalSrc() (gas: 164001)
EscrowTest:test_NoFailedNativeTokenTransferCancelSrc() (gas: 216919)
EscrowTest:test_NoCancelDuringWithdrawalSrc() (gas: 164014)
EscrowTest:test_NoFailedNativeTokenTransferCancelSrc() (gas: 216974)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDst() (gas: 192056)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDstNative() (gas: 84157)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalSrc() (gas: 349798)
EscrowTest:test_NoPublicCallsByAnyone() (gas: 287575)
EscrowTest:test_NoPublicCancelDuringPrivateCancellationSrc() (gas: 168572)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalSrc() (gas: 349853)
EscrowTest:test_NoPublicCallsByAnyone() (gas: 287630)
EscrowTest:test_NoPublicCancelDuringPrivateCancellationSrc() (gas: 168647)
EscrowTest:test_NoPublicWithdrawOutsideOfAllowedPeriodDst() (gas: 137737)
EscrowTest:test_NoPublicWithdrawalOutsideOfAllowedPeriodSrc() (gas: 179922)
EscrowTest:test_NoPublicWithdrawalOutsideOfAllowedPeriodSrc() (gas: 179977)
EscrowTest:test_NoRescueFundsByAnyoneDst() (gas: 176333)
EscrowTest:test_NoRescueFundsByAnyoneSrc() (gas: 209079)
EscrowTest:test_NoRescueFundsByAnyoneSrc() (gas: 209119)
EscrowTest:test_NoRescueFundsEarlierDst() (gas: 175721)
EscrowTest:test_NoRescueFundsEarlierSrc() (gas: 209019)
EscrowTest:test_NoWithdrawalByAnyoneSrc() (gas: 160873)
EscrowTest:test_NoRescueFundsEarlierSrc() (gas: 209074)
EscrowTest:test_NoWithdrawalByAnyoneSrc() (gas: 160928)
EscrowTest:test_NoWithdrawalByNonResolverDst() (gas: 121439)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodDst() (gas: 126326)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodSrc() (gas: 169636)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodSrc() (gas: 169691)
EscrowTest:test_NoWithdrawalWithWrongSecretDst() (gas: 122798)
EscrowTest:test_NoWithdrawalWithWrongSecretSrc() (gas: 164478)
EscrowTest:test_PublicWithdrawSrc() (gas: 187170)
EscrowTest:test_NoWithdrawalWithWrongSecretSrc() (gas: 164533)
EscrowTest:test_PublicWithdrawSrc() (gas: 187225)
EscrowTest:test_RescueFundsDst() (gas: 158237)
EscrowTest:test_RescueFundsDstNative() (gas: 186700)
EscrowTest:test_RescueFundsSrc() (gas: 195453)
EscrowTest:test_RescueFundsSrcNative() (gas: 197742)
EscrowTest:test_RescueFundsSrc() (gas: 195508)
EscrowTest:test_RescueFundsSrcNative() (gas: 197797)
EscrowTest:test_WithdrawByAnyoneDst() (gas: 146701)
EscrowTest:test_WithdrawByResolverDst() (gas: 142374)
EscrowTest:test_WithdrawByResolverDstNative() (gas: 97859)
EscrowTest:test_WithdrawByResolverPublicDst() (gas: 141720)
EscrowTest:test_WithdrawSrc() (gas: 186522)
EscrowTest:test_WithdrawSrcTo() (gas: 191352)
IntegrationEscrowFactoryTest:test_DeployCloneForMakerNonWhitelistedResolverInt() (gas: 510255)
IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 341345)
IntegrationEscrowFactoryTest:test_NoResolverReentrancy() (gas: 2065268)
EscrowTest:test_WithdrawSrc() (gas: 186577)
EscrowTest:test_WithdrawSrcTo() (gas: 191407)
IntegrationEscrowFactoryTest:test_DeployCloneForMakerNonWhitelistedResolverInt() (gas: 510310)
IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 341400)
IntegrationEscrowFactoryTest:test_NoResolverReentrancy() (gas: 2065322)
IntegrationResolverMockTest:test_MockCancelDst() (gas: 157134)
IntegrationResolverMockTest:test_MockCancelSrc() (gas: 354038)
IntegrationResolverMockTest:test_MockCancelSrc() (gas: 354108)
IntegrationResolverMockTest:test_MockDeployDst() (gas: 151470)
IntegrationResolverMockTest:test_MockDeploySrc() (gas: 365135)
IntegrationResolverMockTest:test_MockPublicCancelSrc() (gas: 397961)
IntegrationResolverMockTest:test_MockDeploySrc() (gas: 365039)
IntegrationResolverMockTest:test_MockPublicCancelSrc() (gas: 398059)
IntegrationResolverMockTest:test_MockPublicWithdrawDst() (gas: 170216)
IntegrationResolverMockTest:test_MockRescueFundsDst() (gas: 161053)
IntegrationResolverMockTest:test_MockRescueFundsSrc() (gas: 382703)
IntegrationResolverMockTest:test_MockRescueFundsSrc() (gas: 382758)
IntegrationResolverMockTest:test_MockWithdrawDst() (gas: 182875)
IntegrationResolverMockTest:test_MockWithdrawToSrc() (gas: 354920)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllExtra() (gas: 923635)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllFromLast() (gas: 922419)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllTwoFills() (gas: 922239)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirst() (gas: 707710)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirstTwoFills() (gas: 933041)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillLast() (gas: 707378)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoDeploymentWithoutValidation() (gas: 301537)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoReuseOfSecrets() (gas: 1068098)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoSecondDeploymentWithTheSameIndex() (gas: 786059)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOddDivision() (gas: 444873)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOneFill() (gas: 707726)
MerkleStorageInvalidatorIntTest:test_MultipleFillsTwoFills() (gas: 921521)
MerkleStorageInvalidatorTest:test_ShortenedProofIsNotValid() (gas: 230634)
IntegrationResolverMockTest:test_MockWithdrawToSrc() (gas: 355025)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllExtra() (gas: 923745)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllFromLast() (gas: 922529)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllTwoFills() (gas: 922348)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirst() (gas: 707774)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirstTwoFills() (gas: 933173)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillLast() (gas: 707433)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoDeploymentWithoutValidation() (gas: 301591)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoReuseOfSecrets() (gas: 1068207)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoSecondDeploymentWithTheSameIndex() (gas: 786168)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOddDivision() (gas: 444928)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOneFill() (gas: 707781)
MerkleStorageInvalidatorIntTest:test_MultipleFillsTwoFills() (gas: 921631)
MerkleStorageInvalidatorTest:test_ShortenedProofIsNotValid() (gas: 230633)
TimelocksLibTest:test_NoTimelocksOverflow() (gas: 193707)
TimelocksLibTest:test_getStartTimestamps() (gas: 16207)
TimelocksLibTest:test_setDeployedAt() (gas: 5741)
12 changes: 9 additions & 3 deletions contracts/BaseEscrowFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Timelocks, TimelocksLib } from "./libraries/TimelocksLib.sol";

import { IEscrowFactory } from "./interfaces/IEscrowFactory.sol";
import { IBaseEscrow } from "./interfaces/IBaseEscrow.sol";
import { SRC_IMMUTABLES_LENGTH } from "./EscrowFactoryContext.sol";
import { CHAIN_ID_MASK, SRC_IMMUTABLES_LENGTH } from "./EscrowFactoryContext.sol";
import { MerkleStorageInvalidator } from "./MerkleStorageInvalidator.sol";

/**
Expand Down Expand Up @@ -72,6 +72,12 @@ abstract contract BaseEscrowFactory is IEscrowFactory, ResolverValidationExtensi
extraDataArgs := add(extraData.offset, superArgsLength)
}

bool dstChainIsNotEVM = (extraDataArgs.dstChainId >> 255) == 1;
Address receiver = order.receiver;
bool receiverIsZero = Address.unwrap(receiver) == 0;

if (dstChainIsNotEVM && receiverIsZero) revert InvalidReceiverAddress();

bytes32 hashlock;

if (MakerTraitsLib.allowMultipleFills(order.makerTraits)) {
Expand Down Expand Up @@ -99,11 +105,11 @@ abstract contract BaseEscrowFactory is IEscrowFactory, ResolverValidationExtensi
});

DstImmutablesComplement memory immutablesComplement = DstImmutablesComplement({
maker: order.receiver.get() == address(0) ? order.maker : order.receiver,
maker: receiver.get() == address(0) ? order.maker : receiver,
amount: takingAmount,
token: extraDataArgs.dstToken,
safetyDeposit: extraDataArgs.deposits & type(uint128).max,
chainId: extraDataArgs.dstChainId
chainId: extraDataArgs.dstChainId & CHAIN_ID_MASK
});

emit SrcEscrowCreated(immutables, immutablesComplement);
Expand Down
1 change: 1 addition & 0 deletions contracts/EscrowFactoryContext.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

pragma solidity 0.8.23;

uint256 constant CHAIN_ID_MASK = type(uint256).max >> 1;
uint256 constant SRC_IMMUTABLES_LENGTH = 160;
5 changes: 3 additions & 2 deletions contracts/interfaces/IEscrowFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { IBaseEscrow } from "./IBaseEscrow.sol";
interface IEscrowFactory {
struct ExtraDataArgs {
bytes32 hashlockInfo; // Hash of the secret or the Merkle tree root if multiple fills are allowed
uint256 dstChainId;
uint256 dstChainId; // MSB (bit 255) = non-EVM chain flag, lower 255 bits = actual chain ID
Address dstToken;
uint256 deposits;
uint256 deposits; // Upper 128: src safety deposit, lower 128: dst safety deposit
Timelocks timelocks;
}

Expand All @@ -33,6 +33,7 @@ interface IEscrowFactory {
error InsufficientEscrowBalance();
error InvalidCreationTime();
error InvalidPartialFill();
error InvalidReceiverAddress();
error InvalidSecretsAmount();

/**
Expand Down
Loading