Skip to content

Commit

Permalink
updated foundry tests with custom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
koloz193 committed Jun 3, 2024
1 parent 35809ef commit 63c9bcd
Show file tree
Hide file tree
Showing 70 changed files with 885 additions and 519 deletions.
32 changes: 4 additions & 28 deletions l1-contracts/contracts/bridge/L1SharedBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,7 @@ import {ETH_TOKEN_ADDRESS, TWO_BRIDGES_MAGIC_VALUE} from "../common/Config.sol";
import {IBridgehub, L2TransactionRequestTwoBridgesInner, L2TransactionRequestDirect} from "../bridgehub/IBridgehub.sol";
import {IGetters} from "../state-transition/chain-interfaces/IGetters.sol";
import {L2_BASE_TOKEN_SYSTEM_CONTRACT_ADDR} from "../common/L2ContractAddresses.sol";
import {
Unauthorized,
ZeroAddress,
SharedBridgeValueAlreadySet,
SharedBridgeKey,
NoFundsTransferred,
ZeroBalance,
ValueMismatch,
NonEmptyMsgValue,
L2BridgeNotDeployed,
TokenNotSupported,
WithdrawIncorrectAmount,
EmptyDeposit,
DepositExists,
AddressAlreadyUsed,
InvalidProof,
DepositDNE,
InsufficientFunds,
DepositFailed,
ShareadBridgeValueNotSet,
WithdrawalAlreadyFinalized,
WithdrawFailed,
MalformedMessage,
InvalidSelector
} from "../common/L1ContractErrors.sol";
import {Unauthorized, ZeroAddress, SharedBridgeValueAlreadySet, SharedBridgeKey, NoFundsTransferred, ZeroBalance, ValueMismatch, NonEmptyMsgValue, L2BridgeNotDeployed, TokenNotSupported, WithdrawIncorrectAmount, EmptyDeposit, DepositExists, AddressAlreadyUsed, InvalidProof, DepositDNE, InsufficientFunds, DepositFailed, ShareadBridgeValueNotSet, WithdrawalAlreadyFinalized, WithdrawFailed, MalformedMessage, InvalidSelector} from "../common/L1ContractErrors.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
Expand Down Expand Up @@ -326,12 +302,12 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade
// The token has non-standard transfer logic
if (withdrawAmount != _depositAmount) {
revert WithdrawIncorrectAmount();
}
}
}
// empty deposit amount
if (amount == 0) {
revert EmptyDeposit();
}
}

bytes32 txDataHash = keccak256(abi.encode(_prevMsgSender, _l1Token, amount));
if (!hyperbridgingEnabled[_chainId]) {
Expand Down Expand Up @@ -539,7 +515,7 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade
/// @param _l2BatchNumber The L2 batch number for the withdrawal.
/// @return Whether withdrawal was initiated on zkSync Era before Legacy Bridge upgrade.
function _isEraLegacyTokenWithdrawal(uint256 _chainId, uint256 _l2BatchNumber) internal view returns (bool) {
if((_chainId == ERA_CHAIN_ID) && eraPostLegacyBridgeUpgradeFirstBatch == 0) {
if ((_chainId == ERA_CHAIN_ID) && eraPostLegacyBridgeUpgradeFirstBatch == 0) {
revert ShareadBridgeValueNotSet(SharedBridgeKey.LegacyBridgeFirstBatch);
}
return (_chainId == ERA_CHAIN_ID) && (_l2BatchNumber < eraPostLegacyBridgeUpgradeFirstBatch);
Expand Down
17 changes: 2 additions & 15 deletions l1-contracts/contracts/bridgehub/Bridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,7 @@ import {IZkSyncHyperchain} from "../state-transition/chain-interfaces/IZkSyncHyp
import {ETH_TOKEN_ADDRESS, TWO_BRIDGES_MAGIC_VALUE, BRIDGEHUB_MIN_SECOND_BRIDGE_ADDRESS} from "../common/Config.sol";
import {BridgehubL2TransactionRequest, L2Message, L2Log, TxStatus} from "../common/Messaging.sol";
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol";
import {
Unauthorized,
STMAlreadyRegistered,
STMNotRegistered,
TokenAlreadyRegistered,
TokenNotRegistered,
InvalidChainId,
WethBridgeNotSet,
BridgeHubAlreadyRegistered,
ValueMismatch,
InsufficientFunds,
NonEmptyMsgValue,
AddressTooLow
} from "../common/L1ContractErrors.sol";
import {Unauthorized, STMAlreadyRegistered, STMNotRegistered, TokenAlreadyRegistered, TokenNotRegistered, InvalidChainId, WethBridgeNotSet, BridgeHubAlreadyRegistered, ValueMismatch, InsufficientFunds, NonEmptyMsgValue, AddressTooLow} from "../common/L1ContractErrors.sol";

contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, PausableUpgradeable {
/// @notice all the ether is held by the weth bridge
Expand Down Expand Up @@ -145,7 +132,7 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
if (_chainId == 0) {
revert InvalidChainId();
}
if (_chainId <= type(uint48).max) {
if (_chainId > type(uint48).max) {
revert InvalidChainId();
}

Expand Down
140 changes: 139 additions & 1 deletion l1-contracts/contracts/common/L1ContractErrors.sol
Original file line number Diff line number Diff line change
@@ -1,55 +1,177 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

// 0x8e4a23d6
error Unauthorized(address caller);
// 0x95b66fe9
error EmptyDeposit();
// 0x626ade30
error ValueMismatch(uint256 expected, uint256 actual);
// 0xae899454
error WithdrawalAlreadyFinalized();
// 0xd92e233d
error ZeroAddress();
// 0xcac5fc40
error SharedBridgeValueAlreadySet(SharedBridgeKey);
// 0xcab098d8
error NoFundsTransferred();
// 0x669567ea
error ZeroBalance();
// 0x536ec84b
error NonEmptyMsgValue();
// 0xa4f62e33
error L2BridgeNotDeployed(uint256 chainId);
// 0x06439c6b
error TokenNotSupported(address token);
// 0xc92b7c8f
error WithdrawIncorrectAmount();
// 0xad2fa98e
error DepositExists();
// 0x1ff9d522
error AddressAlreadyUsed(address addr);
// 0x09bde339
error InvalidProof();
// 0x8c04ba2d
error DepositDNE();
// 0x356680b7
error InsufficientFunds();
// 0x79cacff1
error DepositFailed();
// 0xfc1a3c3a
error ShareadBridgeValueNotSet(SharedBridgeKey);
// 0x750b219c
error WithdrawFailed();
// 0x16509b9a
error MalformedMessage();
// 0x12ba286f
error InvalidSelector(bytes4 func);
// 0xd0bc70cf
error STMAlreadyRegistered();
// 0x09865e10
error STMNotRegistered();
// 0x4f4b634e
error TokenAlreadyRegistered(address token);
// 0xddef98d7
error TokenNotRegistered(address token);
// 0x7a47c9a2
error InvalidChainId();
// 0xe4ed5fcc
error WethBridgeNotSet();
// 0x6cf12312
error BridgeHubAlreadyRegistered();
// 0x1eee5481
error AddressTooLow(address);
// 0xdf3a8fdd
error SlotOccupied();
// 0x43e266b0
error MalformedBytecode(BytecodeError);
// 0x72afcbf4
error OperationShouldBeReady();
// 0xee454a75
error OperationShouldBePending();
// 0x1a21feed
error OperationExists();
// 0x4fbe5dba
error InvalidDelay();
// 0x9b48e060
error PreviousOperationNotExecuted();
// 0x0b08d5be
error HashMismatch(bytes32 expected, bytes32 actual);
// 0xb615c2b1
error HyperchainLimitReached();
// 0x71dcf049
error TimeNotReached();
// 0xf0b4e88f
error TooMuchGas();
// 0x59170bf0
error MalformedCalldata();
// 0x79e12cc3
error FacetIsFrozen(bytes4 func);
error PubdataBatchIsLessThanTxn();
// 0x2a4a14df
error PubdataPerBatchIsLessThanTxn();
// 0x6f1cf752
error InvalidPubdataPricingMode();
// 0xaa7feadc
error InvalidValue();
// 0x78d2ed02
error ChainAlreadyLive();
// 0x5428eae7
error InvalidProtocolVersion();
// 0x682dabb4
error DiamondFreezeIncorrectState();
// 0xc5d09071
error InvalidPubdataMode();
// 0x0af806e0
error InvalidHash();
// 0x9094af7e
error InvalidPubdataLength();
// 0xd018e08e
error NonIncreasingTimestamp();
// 0x2d50c33b
error TimestampError();
// 0x1b6825bb
error LogAlreadyProcessed(uint8);
// 0xc1780bd6
error InvalidLogSender(address sender, uint256 logKey);
// 0x6aa39880
error UnexpectedSystemLog(uint256 logKey);
// 0xfa44b527
error MissingSystemLogs(uint256 expected, uint256 actual);
// 0xe85392f9
error CanOnlyProcessOneBatch();
// 0x55ad3fd3
error BatchHashMismatch(bytes32 exected, bytes32 actual);

Check warning on line 123 in l1-contracts/contracts/common/L1ContractErrors.sol

View workflow job for this annotation

GitHub Actions / typos

"exected" should be "executed" or "expected".
// 0xf093c2e5
error UpgradeBatchNumberIsNotZero();
// 0x0105f9c0
error NonSequentialBatch();
// 0x00c6ead2
error CantExecuteUnprovenBatches();
// 0x213eb372
error SystemLogsSizeOverflow();
// 0xd8e9405c
error InvalidNumberOfBlobs(uint256 expected, uint256 numCommitments, uint256 numHashes);
// 0x2dbdba00
error VerifyProofCommittedVerifiedMismatch();
// 0xdab52f4b
error RevertedBatchBeforeNewBatch();
// 0xe18cb383
error CantRevertExecutedBatch();
// 0x4daa985d
error PointEvalFailed(bytes);
// 0xfc7ab1d3
error EmptyBlobVersionHash(uint256 index);
// 0x92290acc
error TxHashMismatch();
error NonEmptyBlobVersionHash(uint256 index);
error BlobHashCommitmentError(uint256 index, bool blobHashEmpty, bool blobCommitmentEmpty);
error OnlyEraSupported();
error BatchNotExecuted(uint256 batchNumber);
error HashedLogIsDefault();
error BaseTokenGasPriceDenominatorNotSet();
error TransactionNotAllowed();
error GasPerPubdataMismatch();
error TooManyFactoryDeps();
error MsgValueTooLow(uint256 required, uint256 provided);
error NoFunctionsForDiamondCut();
error UndefinedDiamondCutAction();
error AddressHasNoCode(address);
error FacetExists(bytes4 selector, address);
error NonZeroAddress(address);
error SelectorsMustAllHaveSameFreezability();
error NonEmptyCalldata();
error BadReturnData();
error MerklePathEmpty();
error MerklePathOutOfBounds();
error MerkleIndexOutOfBounds();
error QueueIsEmpty();
error InvalidUpgradeTxn(UpgradeTxVerifyParam);
error NotEnoughGas();
error InvalidTxType(uint256 txType);
error NewProtocolVersionNotInUpgradeTxn();
error UnexpectedNumberOfFactoryDeps();
error PreviousUpgradeNotFinalized(bytes32 txHash);
error PreviousUpgradeNotCleaned();

enum SharedBridgeKey {
PostUpgradeFirstBatch,
Expand All @@ -64,3 +186,19 @@ enum BytecodeError {
Length,
WordsMustBeOdd
}

enum UpgradeTxVerifyParam {
From,
To,
Paymaster,
Value,
MaxFeePerGas,
MaxPriorityFeePerGas,
Reserved0,
Reserved1,
Reserved2,
Reserved3,
Signature,
PaymasterInput,
ReservedDynamic
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ library L2ContractHelper {
// bytecode length in words must be odd
if (bytecodeLenInWords % 2 == 0) {
revert MalformedBytecode(BytecodeError.WordsMustBeOdd);
}
}
hashedBytecode = sha256(_bytecode) & 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
// Setting the version of the hash
hashedBytecode = (hashedBytecode | bytes32(uint256(1 << 248)));
Expand Down
10 changes: 1 addition & 9 deletions l1-contracts/contracts/governance/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ pragma solidity 0.8.24;

import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {IGovernance} from "./IGovernance.sol";
import {
ZeroAddress,
Unauthorized,
OperationShouldBeReady,
OperationShouldBePending,
OperationExists,
InvalidDelay,
PreviousOperationNotExecuted
} from "../common/L1ContractErrors.sol";
import {ZeroAddress, Unauthorized, OperationShouldBeReady, OperationShouldBePending, OperationExists, InvalidDelay, PreviousOperationNotExecuted} from "../common/L1ContractErrors.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ import {ProposedUpgrade} from "../upgrades/BaseZkSyncUpgrade.sol";
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";
import {REQUIRED_L2_GAS_PRICE_PER_PUBDATA, L2_TO_L1_LOG_SERIALIZE_SIZE, DEFAULT_L2_LOGS_TREE_ROOT_HASH, EMPTY_STRING_KECCAK, SYSTEM_UPGRADE_L2_TX_TYPE, PRIORITY_TX_MAX_GAS_LIMIT} from "../common/Config.sol";
import {VerifierParams} from "./chain-interfaces/IVerifier.sol";
import {
Unauthorized,
ZeroAddress,
HashMismatch,
HyperchainLimitReached
} from "../common/L1ContractErrors.sol";
import {Unauthorized, ZeroAddress, HashMismatch, HyperchainLimitReached} from "../common/L1ContractErrors.sol";

/// @title State Transition Manager contract
/// @author Matter Labs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,7 @@ import {MAX_GAS_PER_TRANSACTION} from "../../../common/Config.sol";
import {FeeParams, PubdataPricingMode} from "../ZkSyncHyperchainStorage.sol";
import {ZkSyncHyperchainBase} from "./ZkSyncHyperchainBase.sol";
import {IStateTransitionManager} from "../../IStateTransitionManager.sol";
import {
Unauthorized,
TooMuchGas,
PubdataBatchIsLessThanTxn,
InvalidPubdataPricingMode,
InvalidValue,
ChainAlreadyLive,
HashMismatch,
ValueMismatch,
InvalidProtocolVersion,
DiamondFreezeIncorrectState
} from "../../../common/L1ContractErrors.sol";
import {Unauthorized, TooMuchGas, PubdataPerBatchIsLessThanTxn, InvalidPubdataPricingMode, InvalidValue, ChainAlreadyLive, HashMismatch, ValueMismatch, InvalidProtocolVersion, DiamondFreezeIncorrectState} from "../../../common/L1ContractErrors.sol";

// While formally the following import is not used, it is needed to inherit documentation from it
import {IZkSyncHyperchainBase} from "../../chain-interfaces/IZkSyncHyperchainBase.sol";
Expand Down Expand Up @@ -85,15 +74,15 @@ contract AdminFacet is ZkSyncHyperchainBase, IAdmin {
// Double checking that the new fee params are valid, i.e.
// the maximal pubdata per batch is not less than the maximal pubdata per priority transaction.
if (_newFeeParams.maxPubdataPerBatch < _newFeeParams.priorityTxMaxPubdata) {
revert PubdataBatchIsLessThanTxn();
revert PubdataPerBatchIsLessThanTxn();
}

FeeParams memory oldFeeParams = s.feeParams;

// we cannot change pubdata pricing mode
if (_newFeeParams.pubdataPricingMode != oldFeeParams.pubdataPricingMode) {
revert InvalidPubdataPricingMode();
}
}

s.feeParams = _newFeeParams;

Expand Down Expand Up @@ -170,9 +159,9 @@ contract AdminFacet is ZkSyncHyperchainBase, IAdmin {
Diamond.DiamondStorage storage diamondStorage = Diamond.getDiamondStorage();

// diamond proxy is frozen already
if (diamondStorage.isFrozen) {
revert DiamondFreezeIncorrectState();
}
if (diamondStorage.isFrozen) {
revert DiamondFreezeIncorrectState();
}
diamondStorage.isFrozen = true;

emit Freeze();
Expand All @@ -183,9 +172,9 @@ contract AdminFacet is ZkSyncHyperchainBase, IAdmin {
Diamond.DiamondStorage storage diamondStorage = Diamond.getDiamondStorage();

// diamond proxy is not frozen
if (!diamondStorage.isFrozen) {
revert DiamondFreezeIncorrectState();
}
if (!diamondStorage.isFrozen) {
revert DiamondFreezeIncorrectState();
}
diamondStorage.isFrozen = false;

emit Unfreeze();
Expand Down
Loading

0 comments on commit 63c9bcd

Please sign in to comment.