|
| 1 | +""" |
| 2 | +abstract: Tests [EIP-7251: Execution layer triggerable consolidation](https://eips.ethereum.org/EIPS/eip-7251) |
| 3 | + Test execution layer triggered exits [EIP-7251: Execution layer triggerable consolidation](https://eips.ethereum.org/EIPS/eip-7251). |
| 4 | +
|
| 5 | +""" # noqa: E501 |
| 6 | + |
| 7 | +from typing import List |
| 8 | + |
| 9 | +import pytest |
| 10 | + |
| 11 | +from ethereum_test_tools import ( |
| 12 | + Account, |
| 13 | + Alloc, |
| 14 | + Block, |
| 15 | + BlockchainTestFiller, |
| 16 | + Bytecode, |
| 17 | + Transaction, |
| 18 | +) |
| 19 | +from ethereum_test_tools import Macros as Om |
| 20 | +from ethereum_test_tools import Opcodes as Op |
| 21 | +from ethereum_test_types import Requests |
| 22 | + |
| 23 | +from .helpers import ( |
| 24 | + ConsolidationRequest, |
| 25 | + ConsolidationRequestTransaction, |
| 26 | +) |
| 27 | +from .spec import Spec as Spec_EIP7251 |
| 28 | +from .spec import ref_spec_7251 |
| 29 | + |
| 30 | +REFERENCE_SPEC_GIT_PATH: str = ref_spec_7251.git_path |
| 31 | +REFERENCE_SPEC_VERSION: str = ref_spec_7251.version |
| 32 | + |
| 33 | +pytestmark: pytest.MarkDecorator = pytest.mark.valid_from("Prague") |
| 34 | + |
| 35 | + |
| 36 | +def consolidation_list_with_custom_fee(n: int) -> List[ConsolidationRequest]: # noqa: D103 |
| 37 | + return [ |
| 38 | + ConsolidationRequest( |
| 39 | + source_pubkey=0x01, |
| 40 | + target_pubkey=0x02, |
| 41 | + fee=Spec_EIP7251.get_fee(10), |
| 42 | + ) |
| 43 | + for i in range(n) |
| 44 | + ] |
| 45 | + |
| 46 | + |
| 47 | +@pytest.mark.parametrize( |
| 48 | + "requests_list", |
| 49 | + [ |
| 50 | + pytest.param( |
| 51 | + [], |
| 52 | + id="empty_request_list", |
| 53 | + ), |
| 54 | + pytest.param( |
| 55 | + [ |
| 56 | + *consolidation_list_with_custom_fee(1), |
| 57 | + ], |
| 58 | + id="1_consolidation_request", |
| 59 | + ), |
| 60 | + pytest.param( |
| 61 | + [ |
| 62 | + *consolidation_list_with_custom_fee(2), |
| 63 | + ], |
| 64 | + id="2_consolidation_requests", |
| 65 | + ), |
| 66 | + pytest.param( |
| 67 | + [ |
| 68 | + *consolidation_list_with_custom_fee(3), |
| 69 | + ], |
| 70 | + id="3_consolidation_requests", |
| 71 | + ), |
| 72 | + pytest.param( |
| 73 | + [ |
| 74 | + *consolidation_list_with_custom_fee(4), |
| 75 | + ], |
| 76 | + id="4_consolidation_requests", |
| 77 | + ), |
| 78 | + pytest.param( |
| 79 | + [ |
| 80 | + *consolidation_list_with_custom_fee(5), |
| 81 | + ], |
| 82 | + id="5_consolidation_requests", |
| 83 | + ), |
| 84 | + ], |
| 85 | +) |
| 86 | +def test_consolidations_asm_modified( |
| 87 | + blockchain_test: BlockchainTestFiller, |
| 88 | + pre: Alloc, |
| 89 | + requests_list: List[ConsolidationRequest], |
| 90 | +): |
| 91 | + """Test how clients were to behave when more than 2 consolidations (here: 4 consolidations) would be allowed per block.""" # noqa: E501 |
| 92 | + # Source of code (change value of this line to 4 and re-compile with fjl/geas): https://github.com/ethereum/sys-asm/blob/f1c13e285b6aeef2b19793995e00861bf0f32c9a/src/consolidations/main.eas#L31 # noqa: E501, W291 |
| 93 | + modified_code: bytes = b"3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060041160e7575060045b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd" # noqa: E501 |
| 94 | + pre[Spec_EIP7251.CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS] = Account( |
| 95 | + code=modified_code, |
| 96 | + nonce=1, |
| 97 | + balance=0, |
| 98 | + ) |
| 99 | + |
| 100 | + # given a list of consolidation requests construct a consolidation request transaction |
| 101 | + consolidation_request_transaction = ConsolidationRequestTransaction(requests=requests_list) |
| 102 | + # prepare consolidation senders |
| 103 | + consolidation_request_transaction.update_pre(pre=pre) |
| 104 | + # get transaction list |
| 105 | + txs: List[Transaction] = consolidation_request_transaction.transactions() |
| 106 | + |
| 107 | + blockchain_test( |
| 108 | + pre=pre, |
| 109 | + blocks=[ |
| 110 | + Block( |
| 111 | + txs=txs, |
| 112 | + requests_hash=Requests(*requests_list), |
| 113 | + ), |
| 114 | + ], |
| 115 | + post={}, |
| 116 | + ) |
| 117 | + |
| 118 | + |
| 119 | +@pytest.mark.parametrize( |
| 120 | + "requests_list", |
| 121 | + [ |
| 122 | + pytest.param( |
| 123 | + [], |
| 124 | + id="empty_request_list", |
| 125 | + ), |
| 126 | + pytest.param( |
| 127 | + [ |
| 128 | + *consolidation_list_with_custom_fee(1), |
| 129 | + ], |
| 130 | + id="1_consolidation_request", |
| 131 | + ), |
| 132 | + pytest.param( |
| 133 | + [ |
| 134 | + *consolidation_list_with_custom_fee(2), |
| 135 | + ], |
| 136 | + id="2_consolidation_requests", |
| 137 | + ), |
| 138 | + pytest.param( |
| 139 | + [ |
| 140 | + *consolidation_list_with_custom_fee(3), |
| 141 | + ], |
| 142 | + id="3_consolidation_requests", |
| 143 | + ), |
| 144 | + pytest.param( |
| 145 | + [ |
| 146 | + *consolidation_list_with_custom_fee(4), |
| 147 | + ], |
| 148 | + id="4_consolidation_requests", |
| 149 | + ), |
| 150 | + pytest.param( |
| 151 | + [ |
| 152 | + *consolidation_list_with_custom_fee(5), |
| 153 | + ], |
| 154 | + id="5_consolidation_requests", |
| 155 | + ), |
| 156 | + ], |
| 157 | +) |
| 158 | +def test_consolidations_py_modified( |
| 159 | + blockchain_test: BlockchainTestFiller, |
| 160 | + pre: Alloc, |
| 161 | + requests_list: List[ConsolidationRequest], |
| 162 | +): |
| 163 | + """Test how clients were to behave when more than 2 consolidations would be allowed per block.""" |
| 164 | + modified_code: Bytecode = Bytecode() |
| 165 | + memory_offset: int = 0 |
| 166 | + amount_of_requests: int = 0 |
| 167 | + |
| 168 | + for consolidation_request in requests_list: |
| 169 | + # update memory_offset with the correct value |
| 170 | + consolidation_request_bytes_amount: int = len(bytes(consolidation_request)) |
| 171 | + assert consolidation_request_bytes_amount == 116, ( |
| 172 | + "Expected consolidation request to be of size 116 but got size " |
| 173 | + f"{consolidation_request_bytes_amount}" |
| 174 | + ) |
| 175 | + memory_offset += consolidation_request_bytes_amount |
| 176 | + |
| 177 | + modified_code += Om.MSTORE(bytes(consolidation_request), memory_offset) |
| 178 | + amount_of_requests += 1 |
| 179 | + |
| 180 | + modified_code += Op.RETURN(0, Op.MSIZE()) |
| 181 | + |
| 182 | + pre[Spec_EIP7251.CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS] = Account( |
| 183 | + code=modified_code, |
| 184 | + nonce=1, |
| 185 | + balance=0, |
| 186 | + ) |
| 187 | + |
| 188 | + # given a list of consolidation requests construct a consolidation request transaction |
| 189 | + consolidation_request_transaction = ConsolidationRequestTransaction(requests=requests_list) |
| 190 | + # prepare consolidation senders |
| 191 | + consolidation_request_transaction.update_pre(pre=pre) |
| 192 | + # get transaction list |
| 193 | + txs: List[Transaction] = consolidation_request_transaction.transactions() |
| 194 | + |
| 195 | + blockchain_test( |
| 196 | + pre=pre, |
| 197 | + blocks=[ |
| 198 | + Block( |
| 199 | + txs=txs, |
| 200 | + requests_hash=Requests(*requests_list), |
| 201 | + ), |
| 202 | + ], |
| 203 | + post={}, |
| 204 | + ) |
0 commit comments