|
| 1 | +"""Tests RIPEMD-160 precompiled contract.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +from execution_testing import ( |
| 5 | + Account, |
| 6 | + Alloc, |
| 7 | + Environment, |
| 8 | + StateTestFiller, |
| 9 | + Transaction, |
| 10 | +) |
| 11 | +from execution_testing.base_types.base_types import Address |
| 12 | +from execution_testing.forks import Byzantium, Istanbul |
| 13 | +from execution_testing.forks.helpers import Fork |
| 14 | +from execution_testing.vm import Opcodes as Op |
| 15 | + |
| 16 | + |
| 17 | +@pytest.mark.valid_from("Byzantium") |
| 18 | +@pytest.mark.parametrize( |
| 19 | + "address,gas_pre_istanbul,gas_post_istanbul", |
| 20 | + [ |
| 21 | + pytest.param(0x06, 500, 150, id="ecadd"), |
| 22 | + pytest.param(0x07, 40_000, 6000, id="ecmul"), |
| 23 | + pytest.param(0x08, 100_000, 45_000, id="ecpairing"), |
| 24 | + ], |
| 25 | +) |
| 26 | +@pytest.mark.parametrize("enough_gas", [True, False]) |
| 27 | +def test_bn254_precompiles_gascosts( |
| 28 | + state_test: StateTestFiller, |
| 29 | + pre: Alloc, |
| 30 | + fork: Fork, |
| 31 | + address: Address, |
| 32 | + gas_pre_istanbul: int, |
| 33 | + gas_post_istanbul: int, |
| 34 | + enough_gas: bool, |
| 35 | +) -> None: |
| 36 | + """ |
| 37 | + Tests the constant gas behavior of `ecadd/ecmul/ecpairing` precompiled |
| 38 | + contract. |
| 39 | + """ |
| 40 | + env = Environment() |
| 41 | + if fork < Istanbul: |
| 42 | + gas = gas_pre_istanbul |
| 43 | + else: |
| 44 | + gas = gas_post_istanbul |
| 45 | + if not enough_gas: |
| 46 | + gas -= 1 |
| 47 | + |
| 48 | + account = pre.deploy_contract( |
| 49 | + code=Op.SSTORE(0, Op.CALL(gas=gas, address=address)), |
| 50 | + storage={0: 0xDEADBEEF}, |
| 51 | + ) |
| 52 | + |
| 53 | + tx = Transaction( |
| 54 | + to=account, |
| 55 | + sender=pre.fund_eoa(), |
| 56 | + gas_limit=100_0000, |
| 57 | + protected=fork >= Byzantium, |
| 58 | + ) |
| 59 | + |
| 60 | + post = {account: Account(storage={0: 1 if enough_gas else 0})} |
| 61 | + |
| 62 | + state_test(env=env, pre=pre, post=post, tx=tx) |
0 commit comments