Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump clvm to 0.9.0 #717

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ clvm-utils = { path = "./crates/clvm-utils", version = "0.13.0" }
clvm-derive = { path = "./crates/clvm-derive", version = "0.13.0" }
chia-fuzz = { path = "./crates/chia-consensus/fuzz", version = "0.13.0" }
blst = { version = "0.3.12", features = ["portable"] }
clvmr = "0.8.0"
clvmr = "0.9.0"
syn = "2.0.75"
quote = "1.0.32"
proc-macro2 = "1.0.84"
Expand Down
13 changes: 6 additions & 7 deletions crates/chia-consensus/src/spendbundle_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use chia_bls::GTElement;
use chia_bls::{aggregate_verify_gt, hash_to_g2};
use chia_protocol::SpendBundle;
use clvmr::sha2::Sha256;
use clvmr::{ENABLE_BLS_OPS_OUTSIDE_GUARD, ENABLE_FIXED_DIV, LIMIT_HEAP};
use clvmr::LIMIT_HEAP;
use std::time::{Duration, Instant};

// type definition makes clippy happy
Expand Down Expand Up @@ -96,7 +96,7 @@ fn hash_pk_and_msg(pk: &[u8], msg: &[u8]) -> [u8; 32] {
}

pub fn get_flags_for_height_and_constants(height: u32, constants: &ConsensusConstants) -> u32 {
let mut flags: u32 = ENABLE_FIXED_DIV;
let mut flags: u32 = 0;

if height >= constants.hard_fork_height {
// the hard-fork initiated with 2.0. To activate June 2024
Expand All @@ -113,7 +113,7 @@ pub fn get_flags_for_height_and_constants(height: u32, constants: &ConsensusCons
// arguments
// * Allow the block generator to be serialized with the improved clvm
// serialization format (with back-references)
flags = flags | ENABLE_BLS_OPS_OUTSIDE_GUARD | ALLOW_BACKREFS;
flags |= ALLOW_BACKREFS;
}
flags
}
Expand All @@ -132,10 +132,9 @@ mod tests {
use rstest::rstest;

#[rstest]
#[case(0, ENABLE_FIXED_DIV)]
#[case(TEST_CONSTANTS.hard_fork_height, ENABLE_BLS_OPS_OUTSIDE_GUARD | ENABLE_FIXED_DIV | ALLOW_BACKREFS)]
#[case(5_716_000, ENABLE_BLS_OPS_OUTSIDE_GUARD | ENABLE_FIXED_DIV | ALLOW_BACKREFS)]
#[case(TEST_CONSTANTS.soft_fork5_height, ENABLE_BLS_OPS_OUTSIDE_GUARD | ENABLE_FIXED_DIV | ALLOW_BACKREFS)]
#[case(0, 0)]
#[case(TEST_CONSTANTS.hard_fork_height, ALLOW_BACKREFS)]
#[case(5_716_000, ALLOW_BACKREFS)]
fn test_get_flags(#[case] height: u32, #[case] expected_value: u32) {
assert_eq!(
get_flags_for_height_and_constants(height, &TEST_CONSTANTS),
Expand Down
3 changes: 1 addition & 2 deletions crates/chia-protocol/fuzz/fuzz_targets/spend-bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use chia_protocol::{Bytes32, SpendBundle};
use chia_traits::Streamable;
use clvm_traits::FromClvm;
use clvmr::op_utils::{first, rest};
use clvmr::ENABLE_FIXED_DIV;
use clvmr::{Allocator, NodePtr};
use libfuzzer_sys::fuzz_target;
use std::collections::HashSet;
Expand All @@ -27,7 +26,7 @@ fuzz_target!(|data: &[u8]| {
for cs in &bundle.coin_spends {
let (cost, mut conds) = cs
.puzzle_reveal
.run(&mut a, ENABLE_FIXED_DIV, 11_000_000_000, &cs.solution)
.run(&mut a, 0, 11_000_000_000, &cs.solution)
.expect("run");
total_cost += cost;

Expand Down
5 changes: 1 addition & 4 deletions crates/chia-protocol/src/spend_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use clvmr::cost::Cost;
use clvmr::op_utils::{first, rest};
use clvmr::reduction::EvalErr;
use clvmr::Allocator;
use clvmr::ENABLE_FIXED_DIV;

#[cfg(feature = "py-bindings")]
use pyo3::prelude::*;
Expand Down Expand Up @@ -50,9 +49,7 @@ impl SpendBundle {

for cs in &self.coin_spends {
a.restore_checkpoint(&checkpoint);
let (cost, mut conds) =
cs.puzzle_reveal
.run(&mut a, ENABLE_FIXED_DIV, cost_left, &cs.solution)?;
let (cost, mut conds) = cs.puzzle_reveal.run(&mut a, 0, cost_left, &cs.solution)?;
if cost > cost_left {
return Err(EvalErr(a.nil(), "cost exceeded".to_string()));
}
Expand Down
34 changes: 1 addition & 33 deletions tests/test_block_record_fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from chia_rs import BlockRecord, ClassgroupElement
from chia_rs.sized_bytes import bytes32, bytes100
from chia_rs.sized_ints import uint32, uint64, uint8, uint128
from chia.consensus.block_record import BlockRecord as PyBlockRecord
from random import Random
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from run_gen import DEFAULT_CONSTANTS


def get_classgroup_element(rng: Random) -> ClassgroupElement:
Expand Down Expand Up @@ -130,34 +129,3 @@ def wrap_call(expr: str, br: Any) -> str:
return f"V:{ret}"
except Exception as e:
return f"E:{e}"


def test_block_record() -> None:
rng = Random()
seed = int(time.time())
print(f"seed: {seed}")
rng.seed(seed)

for i in range(500000):
br = get_block_record(rng)
serialized = bytes(br)
py_identity = PyBlockRecord.from_bytes(serialized)

assert bytes(py_identity) == serialized
assert f"{type(br)}" != f"{type(py_identity)}"

for test_call in [
"ip_iters",
"sp_total_iters",
"sp_iters",
"ip_sub_slot_total_iters",
"sp_sub_slot_total_iters",
]:
rust_ret = wrap_call(f"br.{test_call}(DEFAULT_CONSTANTS)", br)
py_ret = wrap_call(f"br.{test_call}(DEFAULT_CONSTANTS)", py_identity)

assert rust_ret == py_ret

if (i & 0x3FF) == 0:
sys.stdout.write(f" {i} \r")
sys.stdout.flush()
15 changes: 0 additions & 15 deletions tests/test_blscache.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from chia.util.hash import std_hash
from chia.util.lru_cache import LRUCache
from chia.types.blockchain_format.program import Program as ChiaProgram
from chia.util import cached_bls as cached_bls_old
import pytest


Expand Down Expand Up @@ -167,37 +166,25 @@ def test_cached_bls():

# Verify with empty cache and populate it
assert cached_bls.aggregate_verify(pks_half, msgs_half, agg_sig_half)
assert cached_bls_old.aggregate_verify(
pks_half_bytes, msgs_half, agg_sig_half, True
)

# Verify with partial cache hit
assert cached_bls.aggregate_verify(pks, msgs, agg_sig)
assert cached_bls_old.aggregate_verify(pks_bytes, msgs, agg_sig, True)

# Verify with full cache hit
assert cached_bls.aggregate_verify(pks, msgs, agg_sig)
assert cached_bls_old.aggregate_verify(pks_bytes, msgs, agg_sig)

# Use a small cache which can not accommodate all pairings
bls_cache = BLSCache(n_keys // 2)
local_cache = LRUCache(n_keys // 2)
# Verify signatures and cache pairings one at a time
for pk, msg, sig in zip(pks_half, msgs_half, sigs_half):
assert bls_cache.aggregate_verify([pk], [msg], sig)
assert cached_bls_old.aggregate_verify(
[bytes(pk)], [msg], sig, True, local_cache
)

# Verify the same messages with aggregated signature (full cache hit)
assert bls_cache.aggregate_verify(pks_half, msgs_half, agg_sig_half)
assert cached_bls_old.aggregate_verify(
pks_half_bytes, msgs_half, agg_sig_half, False, local_cache
)

# Verify more messages (partial cache hit)
assert bls_cache.aggregate_verify(pks, msgs, agg_sig)
assert cached_bls_old.aggregate_verify(pks_bytes, msgs, agg_sig, False, local_cache)


def test_cached_bls_flattening():
Expand Down Expand Up @@ -250,14 +237,12 @@ def test_cached_bls_repeat_pk():
assert AugSchemeMPL.aggregate_verify([pk for pk in pks], msgs, agg_sig)

assert cached_bls.aggregate_verify(pks, msgs, agg_sig)
assert cached_bls_old.aggregate_verify(pks_bytes, msgs, agg_sig, True)


def test_empty_sig():
sig = AugSchemeMPL.aggregate([])
cached_bls = BLSCache()
assert cached_bls.aggregate_verify([], [], sig)
assert cached_bls_old.aggregate_verify([], [], sig)


def test_bad_cache_size():
Expand Down
3 changes: 1 addition & 2 deletions tests/test_spend_bundle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from chia_rs import SpendBundle
from chia.types.spend_bundle import SpendBundle as PySpendBundle
import pytest
from typing import Type

Expand Down Expand Up @@ -189,7 +188,7 @@
amount: 1232500000000 }]"


@pytest.mark.parametrize("ty", [SpendBundle, PySpendBundle])
@pytest.mark.parametrize("ty", [SpendBundle])
@pytest.mark.parametrize(
"input_file, expected_add, expected_rem",
[
Expand Down
4 changes: 0 additions & 4 deletions wheel/generate_type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,6 @@ def get_flags_for_height_and_constants(
STRICT_ARGS_COUNT: int = ...
LIMIT_HEAP: int = ...
MEMPOOL_MODE: int = ...
ENABLE_BLS_OPS: int = ...
ENABLE_SECP_OPS: int = ...
ENABLE_BLS_OPS_OUTSIDE_GUARD: int = ...
ENABLE_FIXED_DIV: int = ...
ALLOW_BACKREFS: int = ...

ELIGIBLE_FOR_DEDUP: int = ...
Expand Down
4 changes: 0 additions & 4 deletions wheel/python/chia_rs/chia_rs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ NO_UNKNOWN_CONDS: int = ...
STRICT_ARGS_COUNT: int = ...
LIMIT_HEAP: int = ...
MEMPOOL_MODE: int = ...
ENABLE_BLS_OPS: int = ...
ENABLE_SECP_OPS: int = ...
ENABLE_BLS_OPS_OUTSIDE_GUARD: int = ...
ENABLE_FIXED_DIV: int = ...
ALLOW_BACKREFS: int = ...

ELIGIBLE_FOR_DEDUP: int = ...
Expand Down
4 changes: 1 addition & 3 deletions wheel/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use chia_protocol::{
TransactionsInfo, UnfinishedBlock, UnfinishedHeaderBlock, VDFInfo, VDFProof, WeightProof,
};
use clvm_utils::tree_hash_from_bytes;
use clvmr::{ENABLE_BLS_OPS_OUTSIDE_GUARD, ENABLE_FIXED_DIV, LIMIT_HEAP, NO_UNKNOWN_OPS};
use clvmr::{LIMIT_HEAP, NO_UNKNOWN_OPS};
use pyo3::buffer::PyBuffer;
use pyo3::exceptions::{PyRuntimeError, PyTypeError, PyValueError};
use pyo3::prelude::*;
Expand Down Expand Up @@ -500,7 +500,6 @@ pub fn chia_rs(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
// clvm functions
m.add("NO_UNKNOWN_CONDS", NO_UNKNOWN_CONDS)?;
m.add("STRICT_ARGS_COUNT", STRICT_ARGS_COUNT)?;
m.add("ENABLE_FIXED_DIV", ENABLE_FIXED_DIV)?;
m.add("MEMPOOL_MODE", MEMPOOL_MODE)?;
m.add("ALLOW_BACKREFS", ALLOW_BACKREFS)?;
m.add("ANALYZE_SPENDS", ANALYZE_SPENDS)?;
Expand Down Expand Up @@ -623,7 +622,6 @@ pub fn chia_rs(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(run_chia_program, m)?)?;
m.add("NO_UNKNOWN_OPS", NO_UNKNOWN_OPS)?;
m.add("LIMIT_HEAP", LIMIT_HEAP)?;
m.add("ENABLE_BLS_OPS_OUTSIDE_GUARD", ENABLE_BLS_OPS_OUTSIDE_GUARD)?;

m.add_function(wrap_pyfunction!(serialized_length, m)?)?;
m.add_function(wrap_pyfunction!(compute_merkle_set_root, m)?)?;
Expand Down
Loading