Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Raid Ateir committed Dec 17, 2024
1 parent 90ec0c0 commit e5f16a1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
8 changes: 4 additions & 4 deletions l1-contracts/contracts/common/L1ContractErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ error GenesisUpgradeZero();
error HashedLogIsDefault();
// 0x0b08d5be
error HashMismatch(bytes32 expected, bytes32 actual);
// 0xb615c2b1
// 0x601b6882
error ZKChainLimitReached();
// 0xdd381a4c
error IncorrectBridgeHubAddress(address bridgehub);
Expand Down Expand Up @@ -277,7 +277,7 @@ error SharedBridgeValueNotSet(SharedBridgeKey);
error SharedBridgeNotSet();
// 0xdf3a8fdd
error SlotOccupied();
// 0xd0bc70cf
// 0xec273439
error CTMAlreadyRegistered();
// 0x09865e10
error CTMNotRegistered();
Expand Down Expand Up @@ -329,11 +329,11 @@ error ZeroAddress();
error ZeroChainId();
// 0x99d8fec9
error EmptyData();
// 0xc99a8360
// 0xf3dd1b9c
error UnsupportedCommitBatchEncoding(uint8 version);
// 0xe167e4a6
error UnsupportedProofBatchEncoding(uint8 version);
// 0xe8e3f6f4
// 0x14d2ed8a
error UnsupportedExecuteBatchEncoding(uint8 version);
// 0xd7d93e1f
error IncorrectBatchBounds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {AlreadyWhitelisted, InvalidSelector, NotWhitelisted, ZeroAddress} from "
import {ITransactionFilterer} from "../state-transition/chain-interfaces/ITransactionFilterer.sol";
import {IBridgehub} from "../bridgehub/IBridgehub.sol";
import {IAssetRouterBase} from "../bridge/asset-router/IAssetRouterBase.sol";
import {IL2AssetRouter} from "../bridge/asset-router/IL2AssetRouter.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
Expand Down Expand Up @@ -81,15 +82,25 @@ contract GatewayTransactionFilterer is ITransactionFilterer, ReentrancyGuard, Ow
) external view returns (bool) {
if (sender == L1_ASSET_ROUTER) {
bytes4 l2TxSelector = bytes4(l2Calldata[:4]);

if (IL2AssetRouter.setAssetHandlerAddress.selector == l2TxSelector) {
(, bytes32 decodedAssetId, ) = abi.decode(l2Calldata[4:], (uint256, bytes32, address));
return _checkCTMAssetId(decodedAssetId);
}

if (IAssetRouterBase.finalizeDeposit.selector != l2TxSelector) {
revert InvalidSelector(l2TxSelector);
}

(, bytes32 decodedAssetId, ) = abi.decode(l2Calldata[4:], (uint256, bytes32, bytes));
address ctmAddress = BRIDGE_HUB.ctmAssetIdToAddress(decodedAssetId);
return (ctmAddress != address(0));
return _checkCTMAssetId(decodedAssetId);
}

return whitelistedSenders[sender];
}

function _checkCTMAssetId(bytes32 assetId) internal view returns (bool) {
address ctmAddress = BRIDGE_HUB.ctmAssetIdToAddress(assetId);
return ctmAddress != address(0);
}
}
2 changes: 1 addition & 1 deletion l1-contracts/test/foundry/l1/unit/concrete/Utils/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ library Utils {
uint256(SystemLogKey.PREV_BATCH_HASH_KEY),
bytes32("")
);
logs[3] = constructL2Log(
logs[5] = constructL2Log(
true,
L2_TO_L1_MESSENGER,
uint256(SystemLogKey.L2_DA_VALIDATOR_OUTPUT_HASH_KEY),
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/test/foundry/l1/unit/concrete/Utils/Utils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ contract UtilsTest is Test {
logs[4],
Utils.constructL2Log(
true,
L2_BOOTLOADER_ADDRESS,
uint256(SystemLogKey.NUMBER_OF_LAYER_1_TXS_KEY),
L2_SYSTEM_CONTEXT_ADDRESS,
uint256(SystemLogKey.PREV_BATCH_HASH_KEY),
bytes32("")
),
"log[4] should be correct"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.24;
import {Test} from "forge-std/Test.sol";
import {MerkleTest} from "contracts/dev-contracts/test/MerkleTest.sol";
import {MerkleTreeNoSort} from "./MerkleTreeNoSort.sol";
import {MerklePathEmpty, MerkleIndexOutOfBounds, MerklePathOutOfBounds, MerklePathLengthMismatch, MerkleIndexOrHeightMismatch, MerkleNothingToProve} from "contracts/common/L1ContractErrors.sol";
import {MerklePathEmpty, MerkleIndexOutOfBounds, MerklePathOutOfBounds} from "contracts/common/L1ContractErrors.sol";

contract MerkleTestTest is Test {
MerkleTreeNoSort merkleTree;
Expand Down Expand Up @@ -97,7 +97,7 @@ contract MerkleTestTest is Test {
(, bytes32[] memory right, bytes32[] memory leaves) = prepareRangeProof(10, 13);
bytes32[] memory leftShortened = new bytes32[](right.length - 1);

vm.expectRevert(abi.encodeWithSelector(MerklePathLengthMismatch.selector, 6, 7));
vm.expectRevert(bytes("Merkle: path length mismatch"));
merkleTest.calculateRoot(leftShortened, right, 10, leaves);
}

Expand All @@ -112,7 +112,7 @@ contract MerkleTestTest is Test {

function testRangeProofWrongIndex_shouldRevert() public {
(bytes32[] memory left, bytes32[] memory right, bytes32[] memory leaves) = prepareRangeProof(10, 13);
vm.expectRevert(MerkleIndexOrHeightMismatch.selector);
vm.expectRevert(bytes("Merkle: index/height mismatch"));
merkleTest.calculateRoot(left, right, 128, leaves);
}

Expand All @@ -126,7 +126,7 @@ contract MerkleTestTest is Test {
bytes32[] memory left = merkleTree.getProof(elements, 10);
bytes32[] memory right = merkleTree.getProof(elements, 10);
bytes32[] memory leaves;
vm.expectRevert(MerkleNothingToProve.selector);
vm.expectRevert(bytes("Merkle: nothing to prove"));
merkleTest.calculateRoot(left, right, 10, leaves);
}

Expand Down

0 comments on commit e5f16a1

Please sign in to comment.