Skip to content

Commit

Permalink
Merge branch 'main' of github.com:lifinance/contracts into deprecate-…
Browse files Browse the repository at this point in the history
…unused-interfaces
  • Loading branch information
0xDEnYO committed Feb 26, 2025
2 parents ccb6eca + 46e2315 commit aa669e4
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 366 deletions.
4 changes: 4 additions & 0 deletions archive/config/stargateV1.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"chainId": 122,
"endpointId": 30138
}
<<<<<<<< HEAD:archive/config/stargateV1.json
],
"chains": [
{
Expand Down Expand Up @@ -227,4 +228,7 @@
"mumbai": "0x817436a076060D158204d955E5403b6Ed0A5fac0",
"sepolia": "0x0000000000000000000000000000000000000000"
}
========
]
>>>>>>>> 46e2315d1d4ef35f31d403f018a62a06eeda3ef2:config/stargate.json
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 9 additions & 1 deletion audit/auditLog.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@
"auditorGitHandle": "sujithsomraaj",
"auditReportPath": "./audit/reports/2025.01.17_LiFiDexAggregator(v1.4.0).pdf",
"auditCommitHash": "n/a (one deployed contract instance was audited)"
},
"audit20250220": {
"auditCompletedOn": "20.02.2025",
"auditedBy": "Sujith Somraaj (individual security researcher)",
"auditorGitHandle": "sujithsomraaj",
"auditReportPath": "./audit/reports/2025.02.20_CalldataVerificationFacet(v1.3.0).pdf",
"auditCommitHash": "48427d21160585f276d206f0e103ce6bd42c4c03"
}
},
"auditedContracts": {
Expand All @@ -172,7 +179,8 @@
"1.2.0": ["audit20241206"]
},
"CalldataVerificationFacet": {
"1.2.0": ["audit20240902"]
"1.2.0": ["audit20240902"],
"1.3.0": ["audit20250220"]
},
"DeBridgeDlnFacet": {
"1.0.0": ["audit20241205"]
Expand Down
Binary file not shown.
82 changes: 12 additions & 70 deletions src/Facets/CalldataVerificationFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { ILiFi } from "../Interfaces/ILiFi.sol";
import { LibSwap } from "../Libraries/LibSwap.sol";
import { AcrossFacetV3 } from "./AcrossFacetV3.sol";
import { StargateFacetV2 } from "./StargateFacetV2.sol";
import { AcrossFacetV3 } from "./AcrossFacetV3.sol";
import { CelerIMFacetBase, CelerIM } from "lifi/Helpers/CelerIMFacetBase.sol";
import { StandardizedCallFacet } from "lifi/Facets/StandardizedCallFacet.sol";
import { LibBytes } from "../Libraries/LibBytes.sol";
import { GenericSwapFacetV3 } from "lifi/Facets/GenericSwapFacetV3.sol";
import { InvalidCallData } from "../Errors/GenericErrors.sol";
Expand Down Expand Up @@ -109,16 +107,7 @@ contract CalldataVerificationFacet {
function extractNonEVMAddress(
bytes calldata data
) external pure returns (bytes32 nonEVMAddress) {
bytes memory callData;

if (
bytes4(data[:4]) == StandardizedCallFacet.standardizedCall.selector
) {
// standardizedCall
callData = abi.decode(data[4:], (bytes));
} else {
callData = data;
}
bytes memory callData = data;

// Non-EVM address is always the first parameter of bridge specific data
if (_extractBridgeData(data).hasSourceSwaps) {
Expand Down Expand Up @@ -167,22 +156,8 @@ contract CalldataVerificationFacet {
}

LibSwap.SwapData[] memory swapData;
bytes memory callData;
bytes4 functionSelector = bytes4(data[:4]);

// check if this is a call via StandardizedCallFacet
if (
functionSelector == StandardizedCallFacet.standardizedCall.selector
) {
// extract nested function selector and calldata
// will always start at position 68
functionSelector = bytes4(data[68:72]);
callData = data[68:];
// callData = abi.decode(data[4:], (bytes)); // this one is also valid, even though the calldata differs slightly (add. padding)
} else {
callData = data;
}

if (
functionSelector ==
GenericSwapFacetV3.swapTokensSingleV3ERC20ToERC20.selector ||
Expand All @@ -196,13 +171,13 @@ contract CalldataVerificationFacet {

// extract parameters from calldata
(, , , receiver, receivingAmount, swapData[0]) = abi.decode(
callData.slice(4, callData.length - 4),
data[4:],
(bytes32, string, string, address, uint256, LibSwap.SwapData)
);
} else {
// multi swap or GenericSwap V1 call
(, , , receiver, receivingAmount, swapData) = abi.decode(
callData.slice(4, callData.length - 4),
data[4:],
(bytes32, string, string, address, uint256, LibSwap.SwapData[])
);
}
Expand Down Expand Up @@ -271,16 +246,7 @@ contract CalldataVerificationFacet {
bytes calldata callTo,
bytes calldata dstCalldata
) external pure returns (bool isValid) {
bytes memory callData = data;

// Handle standardizedCall
if (
bytes4(data[:4]) == StandardizedCallFacet.standardizedCall.selector
) {
callData = abi.decode(data[4:], (bytes));
}

bytes4 selector = abi.decode(callData, (bytes4));
bytes4 selector = bytes4(data[:4]);

// ---------------------------------------
// Case: StargateV2
Expand All @@ -290,7 +256,7 @@ contract CalldataVerificationFacet {
) {
(, StargateFacetV2.StargateData memory stargateDataV2) = abi
.decode(
callData.slice(4, callData.length - 4),
data[4:],
(ILiFi.BridgeData, StargateFacetV2.StargateData)
);

Expand All @@ -308,7 +274,7 @@ contract CalldataVerificationFacet {
) {
(, , StargateFacetV2.StargateData memory stargateDataV2) = abi
.decode(
callData.slice(4, callData.length - 4),
data[4:],
(
ILiFi.BridgeData,
LibSwap.SwapData[],
Expand All @@ -331,7 +297,7 @@ contract CalldataVerificationFacet {
selector == CelerIMFacetBase.startBridgeTokensViaCelerIM.selector
) {
(, CelerIM.CelerIMData memory celerIMData) = abi.decode(
callData.slice(4, callData.length - 4),
data[4:],
(ILiFi.BridgeData, CelerIM.CelerIMData)
);
return
Expand All @@ -343,7 +309,7 @@ contract CalldataVerificationFacet {
CelerIMFacetBase.swapAndStartBridgeTokensViaCelerIM.selector
) {
(, , CelerIM.CelerIMData memory celerIMData) = abi.decode(
callData.slice(4, callData.length - 4),
data[4:],
(ILiFi.BridgeData, LibSwap.SwapData[], CelerIM.CelerIMData)
);
return
Expand All @@ -353,7 +319,7 @@ contract CalldataVerificationFacet {
// Case: AcrossV3
if (selector == AcrossFacetV3.startBridgeTokensViaAcrossV3.selector) {
(, AcrossFacetV3.AcrossV3Data memory acrossV3Data) = abi.decode(
callData.slice(4, callData.length - 4),
data[4:],
(ILiFi.BridgeData, AcrossFacetV3.AcrossV3Data)
);

Expand All @@ -367,7 +333,7 @@ contract CalldataVerificationFacet {
AcrossFacetV3.swapAndStartBridgeTokensViaAcrossV3.selector
) {
(, , AcrossFacetV3.AcrossV3Data memory acrossV3Data) = abi.decode(
callData.slice(4, callData.length - 4),
data[4:],
(
ILiFi.BridgeData,
LibSwap.SwapData[],
Expand All @@ -384,7 +350,7 @@ contract CalldataVerificationFacet {
// Case: AcrossV3
if (selector == AcrossFacetV3.startBridgeTokensViaAcrossV3.selector) {
(, AcrossFacetV3.AcrossV3Data memory acrossV3Data) = abi.decode(
callData.slice(4, callData.length - 4),
data[4:],
(ILiFi.BridgeData, AcrossFacetV3.AcrossV3Data)
);

Expand All @@ -398,7 +364,7 @@ contract CalldataVerificationFacet {
AcrossFacetV3.swapAndStartBridgeTokensViaAcrossV3.selector
) {
(, , AcrossFacetV3.AcrossV3Data memory acrossV3Data) = abi.decode(
callData.slice(4, callData.length - 4),
data[4:],
(
ILiFi.BridgeData,
LibSwap.SwapData[],
Expand All @@ -423,18 +389,6 @@ contract CalldataVerificationFacet {
function _extractBridgeData(
bytes calldata data
) internal pure returns (ILiFi.BridgeData memory bridgeData) {
if (
bytes4(data[:4]) == StandardizedCallFacet.standardizedCall.selector
) {
// StandardizedCall
bytes memory unwrappedData = abi.decode(data[4:], (bytes));
bridgeData = abi.decode(
unwrappedData.slice(4, unwrappedData.length - 4),
(ILiFi.BridgeData)
);
return bridgeData;
}
// normal call
bridgeData = abi.decode(data[4:], (ILiFi.BridgeData));
}

Expand All @@ -444,18 +398,6 @@ contract CalldataVerificationFacet {
function _extractSwapData(
bytes calldata data
) internal pure returns (LibSwap.SwapData[] memory swapData) {
if (
bytes4(data[:4]) == StandardizedCallFacet.standardizedCall.selector
) {
// standardizedCall
bytes memory unwrappedData = abi.decode(data[4:], (bytes));
(, swapData) = abi.decode(
unwrappedData.slice(4, unwrappedData.length - 4),
(ILiFi.BridgeData, LibSwap.SwapData[])
);
return swapData;
}
// normal call
(, swapData) = abi.decode(
data[4:],
(ILiFi.BridgeData, LibSwap.SwapData[])
Expand Down
Loading

0 comments on commit aa669e4

Please sign in to comment.