|
| 1 | +pragma solidity 0.8.20; |
| 2 | + |
| 3 | +import {TransactionValidatorSharedTest} from "./_TransactionValidator_Shared.t.sol"; |
| 4 | +import {IMailbox} from "solpp/zksync/interfaces/IMailbox.sol"; |
| 5 | +import {TransactionValidator} from "solpp/zksync/libraries/TransactionValidator.sol"; |
| 6 | + |
| 7 | +contract ValidateUpgradeTxTest is TransactionValidatorSharedTest { |
| 8 | + function test_BasicRequest() public pure { |
| 9 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 10 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 11 | + } |
| 12 | + |
| 13 | + function test_RevertWhen_RequestNotFromSystemContract() public { |
| 14 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 15 | + // only system contracts (address < 2^16) are allowed to send upgrade transactions. |
| 16 | + testTx.from = uint256(1000000000); |
| 17 | + vm.expectRevert(bytes("ua")); |
| 18 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 19 | + } |
| 20 | + |
| 21 | + function test_RevertWhen_RequestNotToSystemContract() public { |
| 22 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 23 | + // Now the 'to' address it too large. |
| 24 | + testTx.to = uint256(type(uint160).max) + 100; |
| 25 | + vm.expectRevert(bytes("ub")); |
| 26 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 27 | + } |
| 28 | + |
| 29 | + function test_RevertWhen_PaymasterIsNotZero() public { |
| 30 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 31 | + // Paymaster must be 0 - otherwise we revert. |
| 32 | + testTx.paymaster = 1; |
| 33 | + vm.expectRevert(bytes("uc")); |
| 34 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 35 | + } |
| 36 | + |
| 37 | + function test_RevertWhen_ValueIsNotZero() public { |
| 38 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 39 | + // Value must be 0 - otherwise we revert. |
| 40 | + testTx.value = 1; |
| 41 | + vm.expectRevert(bytes("ud")); |
| 42 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 43 | + } |
| 44 | + |
| 45 | + function test_RevertWhen_Reserved0IsNonZero() public { |
| 46 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 47 | + // reserved 0 must be 0 - otherwise we revert. |
| 48 | + testTx.reserved[0] = 1; |
| 49 | + vm.expectRevert(bytes("ue")); |
| 50 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 51 | + } |
| 52 | + |
| 53 | + function test_RevertWhen_Reserved1IsTooLarge() public { |
| 54 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 55 | + // reserved 1 must be a valid address |
| 56 | + testTx.reserved[1] = uint256(type(uint160).max) + 100; |
| 57 | + vm.expectRevert(bytes("uf")); |
| 58 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 59 | + } |
| 60 | + |
| 61 | + function test_RevertWhen_Reserved2IsNonZero() public { |
| 62 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 63 | + // reserved 2 must be 0 - otherwise we revert. |
| 64 | + testTx.reserved[2] = 1; |
| 65 | + vm.expectRevert(bytes("ug")); |
| 66 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 67 | + } |
| 68 | + |
| 69 | + function test_RevertWhen_Reserved3IsNonZero() public { |
| 70 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 71 | + // reserved 3 be 0 - otherwise we revert. |
| 72 | + testTx.reserved[3] = 1; |
| 73 | + vm.expectRevert(bytes("uo")); |
| 74 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 75 | + } |
| 76 | + |
| 77 | + function test_RevertWhen_NonZeroSignature() public { |
| 78 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 79 | + // Signature must be 0 - otherwise we revert. |
| 80 | + testTx.signature = bytes("hello"); |
| 81 | + vm.expectRevert(bytes("uh")); |
| 82 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 83 | + } |
| 84 | + |
| 85 | + function test_RevertWhen_PaymasterInputNonZero() public { |
| 86 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 87 | + // PaymasterInput must be 0 - otherwise we revert. |
| 88 | + testTx.paymasterInput = bytes("hi"); |
| 89 | + vm.expectRevert(bytes("ul")); |
| 90 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 91 | + } |
| 92 | + |
| 93 | + function test_RevertWhen_ReservedDynamicIsNonZero() public { |
| 94 | + IMailbox.L2CanonicalTransaction memory testTx = createUpgradeTransaction(); |
| 95 | + // ReservedDynamic must be 0 - otherwise we revert. |
| 96 | + testTx.reservedDynamic = bytes("something"); |
| 97 | + vm.expectRevert(bytes("um")); |
| 98 | + TransactionValidator.validateUpgradeTransaction(testTx); |
| 99 | + } |
| 100 | +} |
0 commit comments