Skip to content

Commit f9b7ddc

Browse files
authored
[CHIA-1976] bump chia_rs to 0.16.0 and introduce soft-fork6 (#18988)
* bump chia_rs to 0.16.0 and introduce soft-fork6 * add test for keccak256 operator
1 parent c59eeec commit f9b7ddc

16 files changed

+141
-57
lines changed

chia/_tests/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ def get_keychain():
197197
class ConsensusMode(ComparableEnum):
198198
PLAIN = 0
199199
HARD_FORK_2_0 = 1
200-
SOFT_FORK_5 = 2
200+
SOFT_FORK_6 = 2
201201

202202

203203
@pytest.fixture(
204204
scope="session",
205-
params=[ConsensusMode.PLAIN, ConsensusMode.HARD_FORK_2_0, ConsensusMode.SOFT_FORK_5],
205+
params=[ConsensusMode.PLAIN, ConsensusMode.HARD_FORK_2_0, ConsensusMode.SOFT_FORK_6],
206206
)
207207
def consensus_mode(request):
208208
return request.param
@@ -218,9 +218,9 @@ def blockchain_constants(consensus_mode: ConsensusMode) -> ConsensusConstants:
218218
PLOT_FILTER_64_HEIGHT=uint32(15),
219219
PLOT_FILTER_32_HEIGHT=uint32(20),
220220
)
221-
if consensus_mode >= ConsensusMode.SOFT_FORK_5:
221+
if consensus_mode >= ConsensusMode.SOFT_FORK_6:
222222
ret = ret.replace(
223-
SOFT_FORK5_HEIGHT=uint32(2),
223+
SOFT_FORK6_HEIGHT=uint32(2),
224224
)
225225
return ret
226226

@@ -269,7 +269,7 @@ def db_version(request) -> int:
269269
return request.param
270270

271271

272-
SOFTFORK_HEIGHTS = [1000000, 5496000, 5496100, 5716000, 5940000]
272+
SOFTFORK_HEIGHTS = [1000000, 5496000, 5496100, 5716000, 6800000]
273273

274274

275275
@pytest.fixture(scope="function", params=SOFTFORK_HEIGHTS)

chia/_tests/core/full_node/test_generator_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868

6969
def test_tx_removals_and_additions() -> None:
70-
conditions = SpendBundleConditions(spends, uint64(0), uint32(0), uint64(0), None, None, [], uint64(0), 0, 0)
70+
conditions = SpendBundleConditions(spends, uint64(0), uint32(0), uint64(0), None, None, [], uint64(0), 0, 0, False)
7171
expected_rems = [coin_ids[0], coin_ids[1]]
7272
expected_additions = []
7373
for spend in spends:

chia/_tests/core/mempool/test_mempool.py

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
from typing import Callable, Dict, List, Optional, Tuple
77

88
import pytest
9-
from chia_rs import G1Element, G2Element
9+
from chia_rs import G1Element, G2Element, get_flags_for_height_and_constants
1010
from clvm.casts import int_to_bytes
1111
from clvm_tools import binutils
12+
from clvm_tools.binutils import assemble
1213

1314
from chia._tests.blockchain.blockchain_test_utils import _validate_and_add_block
1415
from chia._tests.connection_utils import add_dummy_connection, connect_and_get_peer
@@ -27,6 +28,7 @@
2728
from chia._tests.util.time_out_assert import time_out_assert
2829
from chia.consensus.condition_costs import ConditionCost
2930
from chia.consensus.cost_calculator import NPCResult
31+
from chia.consensus.default_constants import DEFAULT_CONSTANTS
3032
from chia.full_node.bitcoin_fee_estimator import create_bitcoin_fee_estimator
3133
from chia.full_node.fee_estimation import EmptyMempoolInfo, MempoolInfo
3234
from chia.full_node.full_node_api import FullNodeAPI
@@ -107,7 +109,7 @@ def make_item(
107109
return MempoolItem(
108110
SpendBundle([], G2Element()),
109111
fee,
110-
SpendBundleConditions([], 0, 0, 0, None, None, [], cost, 0, 0),
112+
SpendBundleConditions([], 0, 0, 0, None, None, [], cost, 0, 0, False),
111113
spend_bundle_name,
112114
uint32(0),
113115
assert_height,
@@ -3178,3 +3180,79 @@ def test_get_puzzle_and_solution_for_coin_failure() -> None:
31783180
ValueError, match=f"Failed to get puzzle and solution for coin {TEST_COIN}, error: \\('coin not found', '80'\\)"
31793181
):
31803182
get_puzzle_and_solution_for_coin(BlockGenerator(SerializedProgram.to(None), []), TEST_COIN, 0, test_constants)
3183+
3184+
3185+
# TODO: import this from chia_rs once we bump the version we depend on
3186+
ENABLE_KECCAK = 0x200
3187+
ENABLE_KECCAK_OPS_OUTSIDE_GUARD = 0x100
3188+
3189+
3190+
def test_flags_for_height() -> None:
3191+
3192+
# the keccak operator is supposed to be enabled at soft-fork 6 height
3193+
flags = get_flags_for_height_and_constants(DEFAULT_CONSTANTS.SOFT_FORK6_HEIGHT, DEFAULT_CONSTANTS)
3194+
print(f"{flags:x}")
3195+
assert (flags & ENABLE_KECCAK) != 0
3196+
3197+
flags = get_flags_for_height_and_constants(DEFAULT_CONSTANTS.SOFT_FORK6_HEIGHT - 1, DEFAULT_CONSTANTS)
3198+
print(f"{flags:x}")
3199+
assert (flags & ENABLE_KECCAK) == 0
3200+
3201+
3202+
def test_keccak() -> None:
3203+
3204+
# the keccak operator is 62. The assemble() function doesn't support it
3205+
# (yet)
3206+
3207+
# keccak256 is available when the softfork has activated
3208+
keccak_prg = Program.to(
3209+
assemble(
3210+
"(softfork (q . 1134) (q . 1) (q a (i "
3211+
"(= "
3212+
'(62 (q . "foobar"))'
3213+
"(q . 0x38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e))"
3214+
"(q . 0) (q x)) (q . ())) (q . ()))"
3215+
)
3216+
)
3217+
3218+
cost, ret = keccak_prg.run_with_flags(1215, ENABLE_KECCAK, [])
3219+
assert cost == 1215
3220+
assert ret.atom == b""
3221+
3222+
# keccak is ignored when the softfork has not activated
3223+
cost, ret = keccak_prg.run_with_flags(1215, 0, [])
3224+
assert cost == 1215
3225+
assert ret.atom == b""
3226+
3227+
# make sure keccak is actually executed, by comparing with the wrong output
3228+
keccak_prg = Program.to(
3229+
assemble(
3230+
"(softfork (q . 1134) (q . 1) (q a (i "
3231+
'(= (62 (q . "foobar")) '
3232+
"(q . 0x58d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e))"
3233+
"(q . 0) (q x)) (q . ())) (q . ()))"
3234+
)
3235+
)
3236+
with pytest.raises(ValueError, match="clvm raise"):
3237+
keccak_prg.run_with_flags(1215, ENABLE_KECCAK, [])
3238+
3239+
# keccak is ignored when the softfork has not activated
3240+
cost, ret = keccak_prg.run_with_flags(1215, 0, [])
3241+
assert cost == 1215
3242+
assert ret.atom == b""
3243+
3244+
# === HARD FORK ===
3245+
# new operators *outside* the softfork guard
3246+
# keccak256 is available outside the guard with the appropriate flag
3247+
keccak_prg = Program.to(
3248+
assemble(
3249+
"(a (i (= "
3250+
'(62 (q . "foobar")) '
3251+
"(q . 0x38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e)) "
3252+
"(q . 0) (q x)) (q . ()))"
3253+
)
3254+
)
3255+
3256+
cost, ret = keccak_prg.run_with_flags(994, ENABLE_KECCAK | ENABLE_KECCAK_OPS_OUTSIDE_GUARD, [])
3257+
assert cost == 994
3258+
assert ret.atom == b""

chia/_tests/core/mempool/test_mempool_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def make_test_conds(
227227
cost,
228228
0,
229229
0,
230+
False,
230231
)
231232

232233

chia/_tests/fee_estimation/test_fee_estimation_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def make_mempoolitem() -> MempoolItem:
4242

4343
fee = uint64(10000000)
4444
spends: List[SpendConditions] = []
45-
conds = SpendBundleConditions(spends, 0, 0, 0, None, None, [], cost, 0, 0)
45+
conds = SpendBundleConditions(spends, 0, 0, 0, None, None, [], cost, 0, 0, False)
4646
mempool_item = MempoolItem(
4747
spend_bundle,
4848
fee,

chia/_tests/util/test_condition_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def mk_agg_sig_conditions(
5353
agg_sig_puzzle_amount=agg_sig_data if opcode == ConditionOpcode.AGG_SIG_PUZZLE_AMOUNT else [],
5454
flags=0,
5555
)
56-
return SpendBundleConditions([spend], 0, 0, 0, None, None, agg_sig_unsafe_data, 0, 0, 0)
56+
return SpendBundleConditions([spend], 0, 0, 0, None, None, agg_sig_unsafe_data, 0, 0, 0, False)
5757

5858

5959
@pytest.mark.parametrize(
@@ -100,7 +100,7 @@ def test_pkm_pairs_vs_for_conditions_dict(opcode: ConditionOpcode) -> None:
100100

101101
class TestPkmPairs:
102102
def test_empty_list(self) -> None:
103-
conds = SpendBundleConditions([], 0, 0, 0, None, None, [], 0, 0, 0)
103+
conds = SpendBundleConditions([], 0, 0, 0, None, None, [], 0, 0, 0, False)
104104
pks, msgs = pkm_pairs(conds, b"foobar")
105105
assert pks == []
106106
assert msgs == []

chia/_tests/util/test_replace_str_to_bytes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
MAX_GENERATOR_SIZE=uint32(1000000),
5757
MAX_GENERATOR_REF_LIST_SIZE=uint32(512),
5858
POOL_SUB_SLOT_ITERS=uint64(37600000000),
59-
SOFT_FORK5_HEIGHT=uint32(5940000),
59+
SOFT_FORK6_HEIGHT=uint32(6800000),
6060
HARD_FORK_HEIGHT=uint32(5496000),
6161
PLOT_FILTER_128_HEIGHT=uint32(10542000),
6262
PLOT_FILTER_64_HEIGHT=uint32(15592000),

chia/_tests/util/test_testnet_overrides.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_testnet11() -> None:
99
overrides: Dict[str, Any] = {}
1010
update_testnet_overrides("testnet11", overrides)
1111
assert overrides == {
12-
"SOFT_FORK5_HEIGHT": 1340000,
12+
"SOFT_FORK6_HEIGHT": 2000000,
1313
}
1414

1515

chia/cmds/sim_funcs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ def create_chia_directory(
130130
# get fork heights then write back to config
131131
if "HARD_FORK_HEIGHT" not in sim_config: # this meh code is done so that we also write to the config file.
132132
sim_config["HARD_FORK_HEIGHT"] = 0
133-
if "SOFT_FORK5_HEIGHT" not in sim_config:
134-
sim_config["SOFT_FORK5_HEIGHT"] = 0
133+
if "SOFT_FORK6_HEIGHT" not in sim_config:
134+
sim_config["SOFT_FORK6_HEIGHT"] = 0
135135
simulator_consts["HARD_FORK_HEIGHT"] = sim_config["HARD_FORK_HEIGHT"]
136-
simulator_consts["SOFT_FORK5_HEIGHT"] = sim_config["SOFT_FORK5_HEIGHT"]
136+
simulator_consts["SOFT_FORK6_HEIGHT"] = sim_config["SOFT_FORK6_HEIGHT"]
137137

138138
# save config and return the config
139139
save_config(chia_root, "config.yaml", config)

chia/consensus/default_constants.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
MAX_GENERATOR_SIZE=uint32(1000000),
7373
MAX_GENERATOR_REF_LIST_SIZE=uint32(512), # Number of references allowed in the block generator ref list
7474
POOL_SUB_SLOT_ITERS=uint64(37600000000), # iters limit * NUM_SPS
75-
SOFT_FORK5_HEIGHT=uint32(5940000),
75+
SOFT_FORK6_HEIGHT=uint32(6800000),
7676
# June 2024
7777
HARD_FORK_HEIGHT=uint32(5496000),
7878
# June 2027
@@ -86,5 +86,5 @@
8686

8787
def update_testnet_overrides(network_id: str, overrides: Dict[str, Any]) -> None:
8888
if network_id == "testnet11":
89-
if "SOFT_FORK5_HEIGHT" not in overrides:
90-
overrides["SOFT_FORK5_HEIGHT"] = 1340000
89+
if "SOFT_FORK6_HEIGHT" not in overrides:
90+
overrides["SOFT_FORK6_HEIGHT"] = 2000000

0 commit comments

Comments
 (0)