Verified contractExactMIT
ConfidoMementoBridgeAdapterV1
Address0x7df6aa8e9a5e66fe467af11b9f735f2ffb44cb9b
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.24
- Same code
1 more contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,182,482
- Creation transaction
- 0xc46a2913d3…092c3fcb8d
12 files
- contracts/confido/ConfidoMementoBridgeAdapterV1.solmain18.35 KB
- @openzeppelin/contracts/interfaces/IERC1363.sol4.45 KB
- @openzeppelin/contracts/interfaces/IERC165.sol192 B
- @openzeppelin/contracts/interfaces/IERC20.sol181 B
- @openzeppelin/contracts/token/ERC20/IERC20.sol2.78 KB
- @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol10.08 KB
- @openzeppelin/contracts/utils/Context.sol963 B
- @openzeppelin/contracts/utils/Pausable.sol2.71 KB
- @openzeppelin/contracts/utils/ReentrancyGuard.sol3.38 KB
- @openzeppelin/contracts/utils/introspection/IERC165.sol870 B
- contracts/confido/IBridgeAdapter.sol920 B
- contracts/confido/IZKStackV33.sol3.61 KB
contracts/confido/ConfidoMementoBridgeAdapterV1.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
import {
IL1AssetRouter,
IL1Bridgehub,
IL1NativeTokenVault,
IL1Nullifier,
L2TransactionRequestTwoBridgesOuter,
NEW_ENCODING_VERSION
} from "./IZKStackV33.sol";
import {IBridgeAdapter} from "./IBridgeAdapter.sol";
interface IConfidoIngressRecovery {
function onBridgeAssetsRecovered(bytes32 canonicalTxHash, address token, uint256 amount) external;
}
/**
* @title ConfidoMementoBridgeAdapterV1
*
* @notice Bridges Confido assets from Ethereum to Memento Chain using
* the ZK Stack Asset Router architecture.
*
* @dev V1 supports ERC20 non-base assets only.
*
* Memento uses ETH as its base token. ETH supplied as msg.value
* funds the L1 -> L2 priority transaction and is not itself the
* bridged Confido asset.
*
* Native ETH as a Confido asset may be added in a future version.
*/
contract ConfidoMementoBridgeAdapterV1 is IBridgeAdapter, ReentrancyGuard, Pausable {
using SafeERC20 for IERC20;
// -------------------------------------------------------------------------
// Storage
// -------------------------------------------------------------------------
// Administrative state
address public admin;
address public pendingAdmin;
// The address that will receive unused L2 execution funds
address public refundRecipient;
// -------------------------------------------------------------------------
// Immutable configuration
// -------------------------------------------------------------------------
address public immutable confidoIngress;
uint256 public immutable mementoChainId;
// Memento-chain recipient of bridged Confido assets. This address is
// encoded into the NativeTokenVault asset data for every L1 -> L2 deposit.
//
// It may be a Keeper-controlled wallet or a protocol contract through
// which the Keeper performs the next processing or withdrawal step.
address public immutable mementoReceiver;
IL1Bridgehub public immutable bridgeHub;
IL1AssetRouter public immutable l1AssetRouter;
IL1NativeTokenVault public immutable l1NativeTokenVault;
IL1Nullifier public immutable l1Nullifier;
// -------------------------------------------------------------------------
// Errors
// -------------------------------------------------------------------------
error UnauthorizedAdmin();
error UnauthorizedPendingAdmin();
error AdminAlreadySet();
error NoPendingAdmin();
error RefundRecipientAlreadySet();
error UnauthorizedCaller();
error ZeroAddress();
error InvalidChainId();
error InvalidBridgeConfiguration();
error InvalidAmount();
error InvalidL2GasLimit();
error InvalidL2GasPerPubdataByteLimit();
error NativeAssetNotSupported();
error BaseAssetNotSupported();
error UnknownAsset(address token);
error InsufficientTokenBalance(uint256 available, uint256 required);
error UnexpectedBridgedAmount(uint256 bridged, uint256 expected);
error InvalidBridgeFee(uint256 supplied, uint256 required);
error UnexpectedRecoveredAmount(uint256 recovered, uint256 expected);
// -------------------------------------------------------------------------
// Events
// -------------------------------------------------------------------------
event AdminTransferStarted(address indexed currentAdmin, address indexed pendingAdmin);
event AdminTransferred(address indexed previousAdmin, address indexed newAdmin);
event RefundRecipientUpdated(address indexed previousRecipient, address indexed newRecipient);
event BridgeInitiated(
bytes32 indexed canonicalTxHash,
address indexed token,
uint256 amount,
uint256 mintValue,
uint256 l2GasLimit,
uint256 l2GasPerPubdataByteLimit
);
event FailedDepositRecovered(bytes32 indexed l2TxHash, address indexed token, uint256 amount);
// -------------------------------------------------------------------------
// Modifiers
// -------------------------------------------------------------------------
modifier onlyAdmin() {
if (msg.sender != admin) {
revert UnauthorizedAdmin();
}
_;
}
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
/**
* @param admin_ Administrator of this adapter.
* @param confidoIngress_ The only contract allowed to call `bridge`.
* @param mementoChainId_ ZK chain ID of Memento.
* @param mementoReceiver_ Memento-chain recipient of every bridged asset.
* @param refundRecipient_ Recipient of unused L1 -> L2 execution funds.
* @param bridgeHub_ The v33 L1 Bridgehub proxy. Every other ZK Stack
* address is derived from it, so they cannot disagree.
*/
constructor(
address admin_,
address confidoIngress_,
uint256 mementoChainId_,
address mementoReceiver_,
address refundRecipient_,
address bridgeHub_
) {
if (
admin_ == address(0) ||
confidoIngress_ == address(0) ||
mementoReceiver_ == address(0) ||
refundRecipient_ == address(0) ||
bridgeHub_ == address(0)
) {
revert ZeroAddress();
}
if (mementoChainId_ == 0) {
revert InvalidChainId();
}
admin = admin_;
confidoIngress = confidoIngress_;
mementoChainId = mementoChainId_;
mementoReceiver = mementoReceiver_;
refundRecipient = refundRecipient_;
bridgeHub = IL1Bridgehub(bridgeHub_);
/*
* Derive the rest of the v33 bridge deployment from the Bridgehub.
*
* bridgehub -> assetRouter -> nativeTokenVault / L1_NULLIFIER
*
* All three are proxies whose addresses survive a protocol upgrade.
*/
IL1AssetRouter assetRouter = IL1AssetRouter(bridgeHub.assetRouter());
IL1NativeTokenVault nativeTokenVault = IL1NativeTokenVault(assetRouter.nativeTokenVault());
IL1Nullifier nullifier = IL1Nullifier(assetRouter.L1_NULLIFIER());
l1AssetRouter = assetRouter;
l1NativeTokenVault = nativeTokenVault;
l1Nullifier = nullifier;
if (
address(assetRouter) == address(0) || address(nativeTokenVault) == address(0) || address(nullifier) == address(0)
) {
revert ZeroAddress();
}
if (nullifier.BRIDGE_HUB() != bridgeHub_) {
revert InvalidBridgeConfiguration();
}
if (nullifier.l1AssetRouter() != address(assetRouter)) {
revert InvalidBridgeConfiguration();
}
if (nullifier.l1NativeTokenVault() != address(nativeTokenVault)) {
revert InvalidBridgeConfiguration();
}
if (bridgeHub.L1_CHAIN_ID() != block.chainid) {
revert InvalidBridgeConfiguration();
}
/*
* Memento must be a chain this Bridgehub actually knows about,
* otherwise every bridge call would revert deep inside the Bridgehub.
*/
if (bridgeHub.getZKChain(mementoChainId_) == address(0)) {
revert InvalidChainId();
}
}
// -------------------------------------------------------------------------
// Bridge
// -------------------------------------------------------------------------
/**
* @inheritdoc IBridgeAdapter
*
* @dev ConfidoIngress must transfer `amount` of `token` to this
* adapter immediately before calling this function, in the
* same Ethereum transaction.
*
* msg.value must equal the exact ZK Stack base cost calculated
* for the requested L2 gas parameters. V1 does not allow an
* additional operator tip.
*/
function bridge(
address token,
uint256 amount,
uint256 l2GasLimit,
uint256 l2GasPerPubdataByteLimit
) external payable override nonReentrant whenNotPaused returns (bytes32 canonicalTxHash) {
if (msg.sender != confidoIngress) {
revert UnauthorizedCaller();
}
if (token == address(0)) {
revert NativeAssetNotSupported();
}
if (amount == 0) {
revert InvalidAmount();
}
if (l2GasLimit == 0) {
revert InvalidL2GasLimit();
}
if (l2GasPerPubdataByteLimit == 0) {
revert InvalidL2GasPerPubdataByteLimit();
}
/*
* The adapter must hold at least the amount being bridged.
*
* A pre-existing balance must not block bridging because anyone can
* transfer ERC20 dust directly to the adapter. The exact amount
* consumed by the bridge is verified after the BridgeHub call.
*/
uint256 balanceBefore = IERC20(token).balanceOf(address(this));
if (balanceBefore < amount) {
revert InsufficientTokenBalance(balanceBefore, amount);
}
uint256 baseCost = bridgeHub.l2TransactionBaseCost(
mementoChainId,
tx.gasprice,
l2GasLimit,
l2GasPerPubdataByteLimit
);
/*
* V1 intentionally disallows overfunding.
*
* This prevents the caller from using protocol ETH to provide an
* arbitrary ZK Stack operator tip.
*/
if (msg.value != baseCost) {
revert InvalidBridgeFee(msg.value, baseCost);
}
uint256 mintValue = baseCost;
{
/*
* Register the token in the vault if needed, so the asset ID used
* here is by construction the one the deposit is burned under and
* the one failed-deposit recovery must reconstruct.
*/
bytes32 assetId = l1NativeTokenVault.ensureTokenIsRegistered(token);
/*
* Memento's base token is bridged by the Bridgehub itself as
* `mintValue`, never through the asset router.
*/
if (assetId == bridgeHub.baseTokenAssetId(mementoChainId)) {
revert BaseAssetNotSupported();
}
bytes memory assetData = _encodeAssetData(token, amount);
/*
* v33 asset router payload:
*
* NEW_ENCODING_VERSION || abi.encode(assetId, assetData)
*
* `assetData` contains the amount, Memento receiver and token.
*/
bytes memory secondBridgeCalldata = bytes.concat(NEW_ENCODING_VERSION, abi.encode(assetId, assetData));
/*
* L1NativeTokenVault is the spender for the deposited ERC20.
*/
IERC20(token).forceApprove(address(l1NativeTokenVault), amount);
L2TransactionRequestTwoBridgesOuter memory request = L2TransactionRequestTwoBridgesOuter({
chainId: mementoChainId,
mintValue: mintValue,
l2Value: 0,
l2GasLimit: l2GasLimit,
l2GasPerPubdataByteLimit: l2GasPerPubdataByteLimit,
refundRecipient: refundRecipient,
secondBridgeAddress: address(l1AssetRouter),
secondBridgeValue: 0,
secondBridgeCalldata: secondBridgeCalldata
});
canonicalTxHash = bridgeHub.requestL2TransactionTwoBridges{value: mintValue}(request);
}
/*
* Defensive cleanup.
*
* Regardless of how much allowance was consumed during the bridge,
* no residual approval to L1NativeTokenVault should survive a
* successful operation.
*/
IERC20(token).forceApprove(address(l1NativeTokenVault), 0);
/*
* Verify that this bridge operation consumed exactly `amount`.
*
* Pre-existing token dust is tolerated, but it must not be included
* in the current Confido bridge operation.
*/
uint256 balanceAfter = IERC20(token).balanceOf(address(this));
uint256 bridged = balanceBefore - balanceAfter;
if (bridged != amount) {
revert UnexpectedBridgedAmount(bridged, amount);
}
emit BridgeInitiated(canonicalTxHash, token, amount, mintValue, l2GasLimit, l2GasPerPubdataByteLimit);
}
// -------------------------------------------------------------------------
// Failed-deposit recovery
// -------------------------------------------------------------------------
/**
* @notice Recovers an ERC20 deposit whose L1 -> L2 transaction
* failed.
*
* @dev Permissionless by design.
*
* A caller cannot redirect recovered funds because:
*
* - the destination chain is immutable;
* - depositSender is always this adapter;
* - assetId and assetData are reconstructed internally;
* - L1Nullifier verifies the failure proof;
* - recovered assets are always returned to ConfidoIngress.
*
* L1Nullifier prevents the same deposit from being claimed
* more than once.
*
* The failed L1 -> L2 transaction hash is propagated to ConfidoIngress
* so the recovery remains attributable to the original bridge operation.
*/
function recoverFailedDeposit(
address token,
uint256 amount,
bytes32 l2TxHash,
uint256 l2BatchNumber,
uint256 l2MessageIndex,
uint16 l2TxNumberInBatch,
bytes32[] calldata merkleProof
) external nonReentrant {
if (token == address(0)) {
revert NativeAssetNotSupported();
}
if (amount == 0) {
revert InvalidAmount();
}
/*
* A recoverable deposit necessarily registered the token, so the
* vault's own asset ID is authoritative here. If the vault does not
* know the token, there cannot be a matching deposit for this
* adapter to recover.
*/
bytes32 assetId = l1NativeTokenVault.assetId(token);
if (assetId == bytes32(0)) {
revert UnknownAsset(token);
}
bytes memory assetData = _encodeAssetData(token, amount);
/*
* Measure the exact balance increase caused by this recovery.
*
* This prevents an unrelated existing adapter balance from
* being accidentally included in the recovery.
*/
uint256 balanceBefore = IERC20(token).balanceOf(address(this));
l1Nullifier.bridgeRecoverFailedTransfer(
mementoChainId,
address(this),
assetId,
assetData,
l2TxHash,
l2BatchNumber,
l2MessageIndex,
l2TxNumberInBatch,
merkleProof
);
uint256 balanceAfter = IERC20(token).balanceOf(address(this));
uint256 recovered = balanceAfter - balanceBefore;
if (recovered != amount) {
revert UnexpectedRecoveredAmount(recovered, amount);
}
/*
* Recovery must end with the assets back under ConfidoIngress
* custody. The adapter never retains recovered user assets.
*
* Approve exactly the recovered amount, then let ConfidoIngress
* pull and account for the assets atomically through its recovery
* callback.
*/
IERC20(token).forceApprove(confidoIngress, recovered);
IConfidoIngressRecovery(confidoIngress).onBridgeAssetsRecovered(l2TxHash, token, recovered);
/*
* Defensive cleanup: no residual approval to ConfidoIngress should
* survive a successful recovery operation.
*/
IERC20(token).forceApprove(confidoIngress, 0);
emit FailedDepositRecovered(l2TxHash, token, recovered);
}
// -------------------------------------------------------------------------
// Internal helpers
// -------------------------------------------------------------------------
/**
* @notice Encode the NativeTokenVault bridge-burn data for an ERC20.
*
* @dev The encoded payload is:
*
* abi.encode(
* amount,
* mementoReceiver,
* token
* )
*
* Passing the token address allows the ZK Stack bridge
* infrastructure to register the asset when required.
*
* The exact same encoding must be reconstructed when recovering
* a failed deposit, because L1Nullifier validates the recovery
* against the original deposit data.
*
* @param token Ethereum ERC20 token address.
* @param amount Amount of the token being bridged or recovered.
*
* @return assetData Encoded NativeTokenVault asset-transfer data.
*/
function _encodeAssetData(address token, uint256 amount) internal view returns (bytes memory) {
return abi.encode(amount, mementoReceiver, token);
}
// -------------------------------------------------------------------------
// Administration
// -------------------------------------------------------------------------
/**
* @notice Starts a two-step admin transfer.
*
* @dev The new admin must explicitly accept the role. This avoids
* permanently losing administrative control because of an
* incorrectly specified address.
*
* @param newAdmin Address proposed as the new admin.
*/
function transferAdmin(address newAdmin) external onlyAdmin {
if (newAdmin == address(0)) {
revert ZeroAddress();
}
if (newAdmin == admin) {
revert AdminAlreadySet();
}
pendingAdmin = newAdmin;
emit AdminTransferStarted(admin, newAdmin);
}
/**
* @notice Accepts a pending admin transfer.
*/
function acceptAdmin() external {
if (pendingAdmin == address(0)) {
revert NoPendingAdmin();
}
if (msg.sender != pendingAdmin) {
revert UnauthorizedPendingAdmin();
}
address previousAdmin = admin;
admin = pendingAdmin;
pendingAdmin = address(0);
emit AdminTransferred(previousAdmin, admin);
}
/**
* @notice Updates the recipient of unused L1 -> L2 execution funds.
*
* @dev The refund recipient is protocol-controlled and cannot be
* selected by the Keeper for individual bridge operations.
* Updating it affects only bridge operations initiated after the
* change.
*
* @param newRefundRecipient New refund recipient address.
*/
function setRefundRecipient(address newRefundRecipient) external onlyAdmin {
if (newRefundRecipient == address(0)) {
revert ZeroAddress();
}
if (newRefundRecipient == refundRecipient) {
revert RefundRecipientAlreadySet();
}
address previousRecipient = refundRecipient;
refundRecipient = newRefundRecipient;
emit RefundRecipientUpdated(previousRecipient, newRefundRecipient);
}
/**
* @notice Pauses new bridge operations.
*/
function pause() external onlyAdmin {
_pause();
}
/**
* @notice Resumes new bridge operations.
*/
function unpause() external onlyAdmin {
_unpause();
}
}
@openzeppelin/contracts/interfaces/IERC1363.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
@openzeppelin/contracts/interfaces/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
@openzeppelin/contracts/interfaces/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
@openzeppelin/contracts/utils/Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
bool private _paused;
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
@openzeppelin/contracts/utils/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
contracts/confido/IBridgeAdapter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IBridgeAdapter {
/**
* @notice Bridge an asset from Ethereum to Memento Chain.
*
* @dev For ERC20 assets, the caller must transfer `amount` to the
* adapter before invoking this function.
*
* msg.value is used to fund the L1 -> L2 transaction.
*
* Future implementations may also support native ETH as the
* bridged asset.
*
* @param token ERC20 token being bridged.
* @param amount Amount of token being bridged.
* @param l2GasLimit Gas limit for the L2 priority transaction.
* @param l2GasPerPubdataByteLimit Gas-per-pubdata limit.
*
* @return canonicalTxHash Canonical L1 -> L2 transaction hash.
*/
function bridge(
address token,
uint256 amount,
uint256 l2GasLimit,
uint256 l2GasPerPubdataByteLimit
) external payable returns (bytes32 canonicalTxHash);
}
contracts/confido/IZKStackV33.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @title ZK Stack v33 L1 bridging interfaces
*
* @notice Minimal, self-contained declarations of the v33 L1 contracts that
* `ConfidoMementoBridgeAdapterV1` talks to.
*
* @dev The previously used imports from `@matterlabs/zksync-contracts`
* expose the pre-v33 contract layout (`l1-contracts/bridgehub/…`,
* `IBridgehub`, an `IL1NativeTokenVault` interface with getters that
* are not part of the v33 interface surface), so the adapter uses
* these minimal local declarations for the v33 ecosystem.
*
* Declaring only the handful of functions the adapter actually calls
* keeps the adapter independent of the package's release cadence and
* makes the exact v33 surface it depends on auditable in one place.
*
* In v33 the L1 contracts were reorganised (`core/bridgehub/IL1Bridgehub`,
* `bridge/asset-router/IL1AssetRouter`, …) but the L1 -> L2 deposit
* mechanism itself — `requestL2TransactionTwoBridges` with an asset
* router payload — is unchanged. See `protocol-docs/bridging.md` in
* era-contracts, section "Deposit initiation (source side)".
*/
/// @dev Outer request passed to `IL1Bridgehub.requestL2TransactionTwoBridges`.
struct L2TransactionRequestTwoBridgesOuter {
uint256 chainId;
uint256 mintValue;
uint256 l2Value;
uint256 l2GasLimit;
uint256 l2GasPerPubdataByteLimit;
address refundRecipient;
address secondBridgeAddress;
uint256 secondBridgeValue;
bytes secondBridgeCalldata;
}
/// @dev The encoding version prefixing an asset-transfer payload handed to the asset router.
/// v33 accepts only this version for asset transfers (`NEW_ENCODING_VERSION`).
bytes1 constant NEW_ENCODING_VERSION = 0x01;
interface IL1Bridgehub {
function L1_CHAIN_ID() external view returns (uint256);
function assetRouter() external view returns (address);
function baseTokenAssetId(uint256 _chainId) external view returns (bytes32);
function getZKChain(uint256 _chainId) external view returns (address);
function l2TransactionBaseCost(
uint256 _chainId,
uint256 _gasPrice,
uint256 _l2GasLimit,
uint256 _l2GasPerPubdataByteLimit
) external view returns (uint256);
function requestL2TransactionTwoBridges(
L2TransactionRequestTwoBridgesOuter calldata _request
) external payable returns (bytes32 canonicalTxHash);
}
interface IL1AssetRouter {
function nativeTokenVault() external view returns (address);
function L1_NULLIFIER() external view returns (address);
}
interface IL1NativeTokenVault {
function assetId(address _token) external view returns (bytes32);
function tokenAddress(bytes32 _assetId) external view returns (address);
/// @notice Registers `_nativeToken` in the vault if it is not registered yet and returns its asset ID.
/// @dev Permissionless and idempotent.
function ensureTokenIsRegistered(address _nativeToken) external returns (bytes32);
}
interface IL1Nullifier {
function BRIDGE_HUB() external view returns (address);
function l1AssetRouter() external view returns (address);
function l1NativeTokenVault() external view returns (address);
function depositHappened(uint256 _chainId, bytes32 _l2TxHash) external view returns (bytes32);
function bridgeRecoverFailedTransfer(
uint256 _chainId,
address _depositSender,
bytes32 _assetId,
bytes memory _assetData,
bytes32 _l2TxHash,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes32[] calldata _merkleProof
) external;
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.