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

remove the DISALLOW_INFINITY_G1 flag #715

Merged
merged 1 commit into from
Sep 19, 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
62 changes: 14 additions & 48 deletions crates/chia-consensus/src/gen/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::opcodes::{
use super::sanitize_int::{sanitize_uint, SanitizedUint};
use super::validation_error::{first, next, rest, ErrorCode, ValidationErr};
use crate::consensus_constants::ConsensusConstants;
use crate::gen::flags::{DISALLOW_INFINITY_G1, NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT};
use crate::gen::flags::{NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT};
use crate::gen::messages::{Message, SpendId};
use crate::gen::spend_visitor::SpendVisitor;
use crate::gen::validation_error::check_nil;
Expand Down Expand Up @@ -867,17 +867,13 @@ fn decrement(cnt: &mut u32, n: NodePtr) -> Result<(), ValidationErr> {
}
}

fn to_key(a: &Allocator, pk: NodePtr, flags: u32) -> Result<Option<PublicKey>, ValidationErr> {
fn to_key(a: &Allocator, pk: NodePtr) -> Result<PublicKey, ValidationErr> {
let key = PublicKey::from_bytes(a.atom(pk).as_ref().try_into().expect("internal error"))
.map_err(|_| ValidationErr(pk, ErrorCode::InvalidPublicKey))?;
if key.is_inf() {
if (flags & DISALLOW_INFINITY_G1) != 0 {
Err(ValidationErr(pk, ErrorCode::InvalidPublicKey))
} else {
Ok(None)
}
Err(ValidationErr(pk, ErrorCode::InvalidPublicKey))
} else {
Ok(Some(key))
Ok(key)
}
}

Expand Down Expand Up @@ -1124,47 +1120,31 @@ pub fn parse_conditions<V: SpendVisitor>(
state.assert_concurrent_puzzle.insert(id);
}
Condition::AggSigMe(pk, msg) => {
if let Some(pk) = to_key(a, pk, flags)? {
spend.agg_sig_me.push((pk, msg));
}
spend.agg_sig_me.push((to_key(a, pk)?, msg));
}
Condition::AggSigParent(pk, msg) => {
if let Some(pk) = to_key(a, pk, flags)? {
spend.agg_sig_parent.push((pk, msg));
}
spend.agg_sig_parent.push((to_key(a, pk)?, msg));
}
Condition::AggSigPuzzle(pk, msg) => {
if let Some(pk) = to_key(a, pk, flags)? {
spend.agg_sig_puzzle.push((pk, msg));
}
spend.agg_sig_puzzle.push((to_key(a, pk)?, msg));
}
Condition::AggSigAmount(pk, msg) => {
if let Some(pk) = to_key(a, pk, flags)? {
spend.agg_sig_amount.push((pk, msg));
}
spend.agg_sig_amount.push((to_key(a, pk)?, msg));
}
Condition::AggSigPuzzleAmount(pk, msg) => {
if let Some(pk) = to_key(a, pk, flags)? {
spend.agg_sig_puzzle_amount.push((pk, msg));
}
spend.agg_sig_puzzle_amount.push((to_key(a, pk)?, msg));
}
Condition::AggSigParentAmount(pk, msg) => {
if let Some(pk) = to_key(a, pk, flags)? {
spend.agg_sig_parent_amount.push((pk, msg));
}
spend.agg_sig_parent_amount.push((to_key(a, pk)?, msg));
}
Condition::AggSigParentPuzzle(pk, msg) => {
if let Some(pk) = to_key(a, pk, flags)? {
spend.agg_sig_parent_puzzle.push((pk, msg));
}
spend.agg_sig_parent_puzzle.push((to_key(a, pk)?, msg));
}
Condition::AggSigUnsafe(pk, msg) => {
// AGG_SIG_UNSAFE messages are not allowed to end with the
// suffix added to other AGG_SIG_* conditions
check_agg_sig_unsafe_message(a, msg, constants)?;
if let Some(pk) = to_key(a, pk, flags)? {
ret.agg_sig_unsafe.push((pk, msg));
}
ret.agg_sig_unsafe.push((to_key(a, pk)?, msg));
}
Condition::Softfork(cost) => {
if *max_cost < cost {
Expand Down Expand Up @@ -3123,7 +3103,7 @@ fn test_agg_sig_invalid_pubkey(
#[case(AGG_SIG_UNSAFE)]
fn test_agg_sig_infinity_pubkey(
#[case] condition: ConditionOpcode,
#[values(DISALLOW_INFINITY_G1, 0)] mempool: u32,
#[values(MEMPOOL_MODE, 0)] mempool: u32,
) {
let ret = cond_test_flag(
&format!(
Expand All @@ -3133,21 +3113,7 @@ fn test_agg_sig_infinity_pubkey(
mempool
);

if mempool != 0 {
assert_eq!(ret.unwrap_err().1, ErrorCode::InvalidPublicKey);
} else {
let ret = ret.expect("expected conditions to be valid").1;
assert!(ret.agg_sig_unsafe.is_empty());
for c in ret.spends {
assert!(c.agg_sig_me.is_empty());
assert!(c.agg_sig_parent.is_empty());
assert!(c.agg_sig_puzzle.is_empty());
assert!(c.agg_sig_amount.is_empty());
assert!(c.agg_sig_puzzle_amount.is_empty());
assert!(c.agg_sig_parent_amount.is_empty());
assert!(c.agg_sig_parent_puzzle.is_empty());
}
}
assert_eq!(ret.unwrap_err().1, ErrorCode::InvalidPublicKey);
}

#[cfg(test)]
Expand Down
13 changes: 2 additions & 11 deletions crates/chia-consensus/src/gen/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,5 @@ pub const ALLOW_BACKREFS: u32 = 0x0200_0000;
// what features are detected of the spends
pub const ANALYZE_SPENDS: u32 = 0x0400_0000;

// When this flag is set, we reject AGG_SIG_* conditions whose public key is the
// infinity G1 point. Such public keys are mathematically valid, but do not
// provide any security guarantees. Chia has historically allowed them. Enabling
// this flag is a soft-fork.
pub const DISALLOW_INFINITY_G1: u32 = 0x1000_0000;

pub const MEMPOOL_MODE: u32 = CLVM_MEMPOOL_MODE
| NO_UNKNOWN_CONDS
| STRICT_ARGS_COUNT
| ANALYZE_SPENDS
| DISALLOW_INFINITY_G1;
pub const MEMPOOL_MODE: u32 =
CLVM_MEMPOOL_MODE | NO_UNKNOWN_CONDS | STRICT_ARGS_COUNT | ANALYZE_SPENDS;
8 changes: 2 additions & 6 deletions crates/chia-consensus/src/spendbundle_validation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::allocator::make_allocator;
use crate::consensus_constants::ConsensusConstants;
use crate::gen::flags::{ALLOW_BACKREFS, DISALLOW_INFINITY_G1};
use crate::gen::flags::ALLOW_BACKREFS;
use crate::gen::make_aggsig_final_message::make_aggsig_final_message;
use crate::gen::opcodes::{
AGG_SIG_AMOUNT, AGG_SIG_ME, AGG_SIG_PARENT, AGG_SIG_PARENT_AMOUNT, AGG_SIG_PARENT_PUZZLE,
Expand Down Expand Up @@ -98,10 +98,6 @@ 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;

if height >= constants.soft_fork5_height {
flags |= DISALLOW_INFINITY_G1;
}

if height >= constants.hard_fork_height {
// the hard-fork initiated with 2.0. To activate June 2024
// * costs are ascribed to some unknown condition codes, to allow for
Expand Down Expand Up @@ -139,7 +135,7 @@ mod tests {
#[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 | DISALLOW_INFINITY_G1)]
#[case(TEST_CONSTANTS.soft_fork5_height, ENABLE_BLS_OPS_OUTSIDE_GUARD | ENABLE_FIXED_DIV | 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
6 changes: 0 additions & 6 deletions generator-tests/infinity-g1.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
ff01ffffffa00101010101010101010101010101010101010101010101010101010101010101ffff01ffff2bffb0c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff86666f6f6261728080ff7bff80808080
SPENDS:
- coin id: 10d6c244183579e7704ea71e862098f15d28d63fb63c6a54779d1fe901ca48b1 ph: 99d9c5fd60cc6d5bca3390783d3489cd744139f7f143191ea911de3a22b50907
cost: 2552512
removal_amount: 123
addition_amount: 0
STRICT:
FAILED: 10
1 change: 0 additions & 1 deletion wheel/generate_type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ def get_flags_for_height_and_constants(
NO_UNKNOWN_CONDS: int = ...
STRICT_ARGS_COUNT: int = ...
LIMIT_HEAP: int = ...
DISALLOW_INFINITY_G1: int = ...
MEMPOOL_MODE: int = ...
ENABLE_BLS_OPS: int = ...
ENABLE_SECP_OPS: int = ...
Expand Down
1 change: 0 additions & 1 deletion wheel/python/chia_rs/chia_rs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def get_flags_for_height_and_constants(
NO_UNKNOWN_CONDS: int = ...
STRICT_ARGS_COUNT: int = ...
LIMIT_HEAP: int = ...
DISALLOW_INFINITY_G1: int = ...
MEMPOOL_MODE: int = ...
ENABLE_BLS_OPS: int = ...
ENABLE_SECP_OPS: 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 @@ -3,8 +3,7 @@ use chia_consensus::allocator::make_allocator;
use chia_consensus::consensus_constants::ConsensusConstants;
use chia_consensus::gen::conditions::MempoolVisitor;
use chia_consensus::gen::flags::{
ALLOW_BACKREFS, ANALYZE_SPENDS, DISALLOW_INFINITY_G1, MEMPOOL_MODE, NO_UNKNOWN_CONDS,
STRICT_ARGS_COUNT,
ALLOW_BACKREFS, ANALYZE_SPENDS, MEMPOOL_MODE, NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT,
};
use chia_consensus::gen::owned_conditions::{OwnedSpendBundleConditions, OwnedSpendConditions};
use chia_consensus::gen::run_block_generator::setup_generator_args;
Expand Down Expand Up @@ -505,7 +504,6 @@ pub fn chia_rs(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add("MEMPOOL_MODE", MEMPOOL_MODE)?;
m.add("ALLOW_BACKREFS", ALLOW_BACKREFS)?;
m.add("ANALYZE_SPENDS", ANALYZE_SPENDS)?;
m.add("DISALLOW_INFINITY_G1", DISALLOW_INFINITY_G1)?;

// Chia classes
m.add_class::<Coin>()?;
Expand Down
Loading