Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridgehub test coverage increase + change in bridgehub! #15

Closed
wants to merge 6 commits into from
Closed
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
9 changes: 5 additions & 4 deletions l1-contracts/contracts/bridgehub/Bridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus

address hyperchain = getHyperchain(_request.chainId);

require(
_request.secondBridgeAddress > BRIDGEHUB_MIN_SECOND_BRIDGE_ADDRESS,
"Bridgehub: second bridge address too low"
); // to avoid calls to precompiles

// slither-disable-next-line arbitrary-send-eth
L2TransactionRequestTwoBridgesInner memory outputRequest = IL1SharedBridge(_request.secondBridgeAddress)
.bridgehubDeposit{value: _request.secondBridgeValue}(
Expand All @@ -301,10 +306,6 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus

address refundRecipient = AddressAliasHelper.actualRefundRecipient(_request.refundRecipient, msg.sender);

require(
_request.secondBridgeAddress > BRIDGEHUB_MIN_SECOND_BRIDGE_ADDRESS,
"Bridgehub: second bridge address too low"
); // to avoid calls to precompiles
canonicalTxHash = IZkSyncHyperchain(hyperchain).bridgehubRequestL2Transaction(
BridgehubL2TransactionRequest({
sender: _request.secondBridgeAddress,
Expand Down
36 changes: 28 additions & 8 deletions l1-contracts/contracts/dev-contracts/test/DummySharedBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ pragma solidity 0.8.24;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import {L2TransactionRequestTwoBridgesInner} from "../../bridgehub/IBridgehub.sol";
import {TWO_BRIDGES_MAGIC_VALUE} from "../../common/Config.sol";
import {TWO_BRIDGES_MAGIC_VALUE, ETH_TOKEN_ADDRESS} from "../../common/Config.sol";
import {IL2Bridge} from "../../bridge/interfaces/IL2Bridge.sol";

contract DummySharedBridge {
event BridgehubDepositBaseTokenInitiated(
Expand Down Expand Up @@ -108,14 +109,33 @@ contract DummySharedBridge {
}

function bridgehubDeposit(
uint256, //_chainId,
address, //_prevMsgSender,
uint256, // l2Value, needed for Weth deposits in the future
bytes calldata //_data
uint256,
address _prevMsgSender,
uint256,
bytes calldata _data
) external payable returns (L2TransactionRequestTwoBridgesInner memory request) {
// Request the finalization of the deposit on the L2 side
bytes memory l2TxCalldata = bytes("0xabcd123");
bytes32 txDataHash = bytes32("0x1212121212abf");
(address _l1Token, uint256 _depositAmount, address _l2Receiver) = abi.decode(
_data,
(address, uint256, address)
);
uint256 amount;

if (_l1Token == ETH_TOKEN_ADDRESS) {
amount = msg.value;
require(_depositAmount == 0, "ShB wrong withdraw amount");
} else {
require(msg.value == 0, "ShB m.v > 0 for BH d.it 2");
amount = _depositAmount;

uint256 withdrawAmount = _depositFunds(_prevMsgSender, IERC20(_l1Token), _depositAmount);
require(withdrawAmount == _depositAmount, "5T"); // The token has non-standard transfer logic
}

bytes memory l2TxCalldata = abi.encodeCall(
IL2Bridge.finalizeDeposit,
(_prevMsgSender, _l2Receiver, _l1Token, amount, new bytes(0))
);
bytes32 txDataHash = keccak256(abi.encode(_prevMsgSender, _l1Token, amount));

request = L2TransactionRequestTwoBridgesInner({
magicValue: TWO_BRIDGES_MAGIC_VALUE,
Expand Down
Loading
Loading