Skip to content

Commit 7a35db4

Browse files
committed
WIP: just see if this breaks replay blocks
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent ab6459b commit 7a35db4

File tree

14 files changed

+697
-159
lines changed

14 files changed

+697
-159
lines changed

clarity-serialization/src/errors/analysis.rs

Lines changed: 645 additions & 0 deletions
Large diffs are not rendered by default.

clarity/src/vm/ast/mod.rs

Lines changed: 17 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ fn parse_in_epoch(
6868
) -> ParseResult<Vec<PreSymbolicExpression>> {
6969
if epoch_id >= StacksEpochId::Epoch21 {
7070
parse_v2(source_code)
71-
} else if ast_rules == ASTRules::Typical {
72-
parse_v1_no_stack_limit(source_code)
7371
} else {
7472
parse_v1(source_code)
7573
}
@@ -100,23 +98,13 @@ pub fn build_ast_with_rules<T: CostTracker>(
10098
epoch: StacksEpochId,
10199
ruleset: ASTRules,
102100
) -> ParseResult<ContractAST> {
103-
match ruleset {
104-
// After epoch 2.1, prechecking the size is required
105-
ASTRules::Typical if epoch < StacksEpochId::Epoch21 => build_ast_typical(
106-
contract_identifier,
107-
source_code,
108-
cost_track,
109-
clarity_version,
110-
epoch,
111-
),
112-
_ => build_ast_precheck_size(
113-
contract_identifier,
114-
source_code,
115-
cost_track,
116-
clarity_version,
117-
epoch,
118-
),
119-
}
101+
build_ast_precheck_size(
102+
contract_identifier,
103+
source_code,
104+
cost_track,
105+
clarity_version,
106+
epoch,
107+
)
120108
}
121109

122110
/// Build an AST with the typical rules
@@ -133,7 +121,7 @@ fn build_ast_typical<T: CostTracker>(
133121
cost_track,
134122
clarity_version,
135123
epoch,
136-
ASTRules::Typical,
124+
ASTRules::PrecheckSize,
137125
true,
138126
)?;
139127
Ok(contract)
@@ -190,10 +178,7 @@ fn inner_build_ast<T: CostTracker>(
190178
parser::v2::parse_collect_diagnostics(source_code)
191179
}
192180
} else {
193-
let parse_result = match ast_rules {
194-
ASTRules::Typical => parse_v1_no_stack_limit(source_code),
195-
ASTRules::PrecheckSize => parse_v1(source_code),
196-
};
181+
let parse_result = parse_v1(source_code);
197182
match parse_result {
198183
Ok(pre_expressions) => (pre_expressions, vec![], true),
199184
Err(error) if error_early => return Err(error),
@@ -223,16 +208,14 @@ fn inner_build_ast<T: CostTracker>(
223208
_ => (),
224209
}
225210

226-
if ast_rules != ASTRules::Typical {
227-
// run extra stack-depth pass for tuples
228-
match VaryStackDepthChecker::run_pass(&mut contract_ast, clarity_version) {
229-
Err(e) if error_early => return Err(e),
230-
Err(e) => {
231-
diagnostics.push(e.diagnostic);
232-
success = false;
233-
}
234-
_ => (),
211+
// run extra stack-depth pass for tuples
212+
match VaryStackDepthChecker::run_pass(&mut contract_ast, clarity_version) {
213+
Err(e) if error_early => return Err(e),
214+
Err(e) => {
215+
diagnostics.push(e.diagnostic);
216+
success = false;
235217
}
218+
_ => (),
236219
}
237220

238221
match ExpressionIdentifier::run_pre_expression_pass(&mut contract_ast, clarity_version) {
@@ -404,7 +387,7 @@ mod test {
404387
&mut cost_track,
405388
clarity_version,
406389
StacksEpochId::Epoch2_05,
407-
ASTRules::Typical,
390+
ASTRules::PrecheckSize,
408391
)
409392
.expect_err("Contract should error in parsing");
410393

@@ -441,18 +424,6 @@ mod test {
441424
assert_eq!(expected_list_cost_state, cost_track);
442425

443426
// you cannot do the same for tuples!
444-
// in ASTRules::Typical, this passes
445-
let mut cost_track = UnitTestTracker::new();
446-
let _ = build_ast_with_rules(
447-
&QualifiedContractIdentifier::transient(),
448-
&exceeds_stack_depth_tuple,
449-
&mut cost_track,
450-
clarity_version,
451-
StacksEpochId::Epoch2_05,
452-
ASTRules::Typical,
453-
)
454-
.expect("Contract should parse with ASTRules::Typical");
455-
456427
// this actually won't even error without
457428
// the VaryStackDepthChecker changes.
458429
let mut cost_track = UnitTestTracker::new();
@@ -498,29 +469,6 @@ mod test {
498469
")".repeat(stack_limit + 1)
499470
);
500471

501-
// with old rules, this is just ExpressionStackDepthTooDeep
502-
let mut cost_track = UnitTestTracker::new();
503-
let err = build_ast_with_rules(
504-
&QualifiedContractIdentifier::transient(),
505-
&exceeds_stack_depth_list,
506-
&mut cost_track,
507-
*clarity_version,
508-
StacksEpochId::Epoch21,
509-
ASTRules::Typical,
510-
)
511-
.expect_err("Contract should error in parsing");
512-
513-
let expected_err = ParseErrors::ExpressionStackDepthTooDeep;
514-
let expected_list_cost_state = UnitTestTracker {
515-
invoked_functions: vec![(ClarityCostFunction::AstParse, vec![500])],
516-
invocation_count: 1,
517-
cost_addition_count: 1,
518-
};
519-
520-
assert_eq!(&expected_err, &err.err);
521-
assert_eq!(expected_list_cost_state, cost_track);
522-
523-
// in 2.1, this is still ExpressionStackDepthTooDeep
524472
let mut cost_track = UnitTestTracker::new();
525473
let err = build_ast_with_rules(
526474
&QualifiedContractIdentifier::transient(),
@@ -542,29 +490,6 @@ mod test {
542490
assert_eq!(&expected_err, &err.err);
543491
assert_eq!(expected_list_cost_state, cost_track);
544492

545-
// in 2.1, ASTRules::Typical is ignored -- this still fails to parse
546-
let mut cost_track = UnitTestTracker::new();
547-
let _ = build_ast_with_rules(
548-
&QualifiedContractIdentifier::transient(),
549-
&exceeds_stack_depth_tuple,
550-
&mut cost_track,
551-
*clarity_version,
552-
StacksEpochId::Epoch21,
553-
ASTRules::Typical,
554-
)
555-
.expect_err("Contract should error in parsing");
556-
557-
let expected_err = ParseErrors::ExpressionStackDepthTooDeep;
558-
let expected_list_cost_state = UnitTestTracker {
559-
invoked_functions: vec![(ClarityCostFunction::AstParse, vec![571])],
560-
invocation_count: 1,
561-
cost_addition_count: 1,
562-
};
563-
564-
assert_eq!(&expected_err, &err.err);
565-
assert_eq!(expected_list_cost_state, cost_track);
566-
567-
// in 2.1, ASTRules::PrecheckSize is still ignored -- this still fails to parse
568493
let mut cost_track = UnitTestTracker::new();
569494
let err = build_ast_with_rules(
570495
&QualifiedContractIdentifier::transient(),

clarity/src/vm/contexts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> {
790790
contract: &QualifiedContractIdentifier,
791791
program: &str,
792792
) -> Result<(Value, AssetMap, Vec<StacksTransactionEvent>)> {
793-
self.eval_read_only_with_rules(contract, program, ast::ASTRules::Typical)
793+
self.eval_read_only_with_rules(contract, program, ast::ASTRules::PrecheckSize)
794794
}
795795

796796
pub fn begin(&mut self) {
@@ -1010,7 +1010,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> {
10101010
contract_identifier: &QualifiedContractIdentifier,
10111011
program: &str,
10121012
) -> Result<Value> {
1013-
self.eval_read_only_with_rules(contract_identifier, program, ast::ASTRules::Typical)
1013+
self.eval_read_only_with_rules(contract_identifier, program, ast::ASTRules::PrecheckSize)
10141014
}
10151015

10161016
pub fn eval_raw_with_rules(&mut self, program: &str, rules: ast::ASTRules) -> Result<Value> {
@@ -1039,7 +1039,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> {
10391039

10401040
#[cfg(any(test, feature = "testing"))]
10411041
pub fn eval_raw(&mut self, program: &str) -> Result<Value> {
1042-
self.eval_raw_with_rules(program, ast::ASTRules::Typical)
1042+
self.eval_raw_with_rules(program, ast::ASTRules::PrecheckSize)
10431043
}
10441044

10451045
/// Used only for contract-call! cost short-circuiting. Once the short-circuited cost

clarity/src/vm/database/clarity_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ impl BurnStateDB for NullBurnStateDB {
443443
}
444444

445445
fn get_ast_rules(&self, _height: u32) -> ASTRules {
446-
ASTRules::Typical
446+
ASTRules::PrecheckSize
447447
}
448448
}
449449

clarity/src/vm/test_util/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct UnitTestHeaderDB {}
2626
pub const TEST_HEADER_DB: UnitTestHeaderDB = UnitTestHeaderDB {};
2727
pub const TEST_BURN_STATE_DB: UnitTestBurnStateDB = UnitTestBurnStateDB {
2828
epoch_id: StacksEpochId::Epoch20,
29-
ast_rules: ASTRules::Typical,
29+
ast_rules: ASTRules::PrecheckSize,
3030
};
3131
pub const TEST_BURN_STATE_DB_205: UnitTestBurnStateDB = UnitTestBurnStateDB {
3232
epoch_id: StacksEpochId::Epoch2_05,
@@ -44,7 +44,7 @@ pub fn generate_test_burn_state_db(epoch_id: StacksEpochId) -> UnitTestBurnState
4444
}
4545
StacksEpochId::Epoch20 => UnitTestBurnStateDB {
4646
epoch_id,
47-
ast_rules: ASTRules::Typical,
47+
ast_rules: ASTRules::PrecheckSize,
4848
},
4949
StacksEpochId::Epoch2_05
5050
| StacksEpochId::Epoch21

stacks-node/src/tests/neon_integrations.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8152,7 +8152,7 @@ fn test_problematic_blocks_are_not_mined() {
81528152
(tip, cur_ast_rules)
81538153
};
81548154

8155-
assert_eq!(cur_ast_rules, ASTRules::Typical);
8155+
assert_eq!(cur_ast_rules, ASTRules::PrecheckSize);
81568156

81578157
// add another bad tx to the mempool
81588158
debug!("Submit problematic tx_high transaction {tx_high_txid}");
@@ -8487,7 +8487,7 @@ fn test_problematic_blocks_are_not_relayed_or_stored() {
84878487
(tip, cur_ast_rules)
84888488
};
84898489

8490-
assert_eq!(cur_ast_rules, ASTRules::Typical);
8490+
assert_eq!(cur_ast_rules, ASTRules::PrecheckSize);
84918491

84928492
btc_regtest_controller.build_next_block(1);
84938493

@@ -8528,7 +8528,7 @@ fn test_problematic_blocks_are_not_relayed_or_stored() {
85288528
};
85298529

85308530
// we reverted to the old rules (but the follower won't)
8531-
assert_eq!(cur_ast_rules, ASTRules::Typical);
8531+
assert_eq!(cur_ast_rules, ASTRules::PrecheckSize);
85328532

85338533
// add another bad tx to the mempool.
85348534
// because the miner is now non-conformant, it should mine this tx.
@@ -8561,7 +8561,7 @@ fn test_problematic_blocks_are_not_relayed_or_stored() {
85618561
};
85628562

85638563
// we reverted to the old rules (but the follower won't)
8564-
assert_eq!(cur_ast_rules, ASTRules::Typical);
8564+
assert_eq!(cur_ast_rules, ASTRules::PrecheckSize);
85658565
}
85668566

85678567
let tip_info = get_chain_info(&conf);

stackslib/src/chainstate/burn/db/sortdb.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10602,15 +10602,15 @@ pub mod tests {
1060210602

1060310603
assert_eq!(
1060410604
SortitionDB::get_ast_rules(db.conn(), 0).unwrap(),
10605-
ASTRules::Typical
10605+
ASTRules::PrecheckSize
1060610606
);
1060710607
assert_eq!(
1060810608
SortitionDB::get_ast_rules(db.conn(), 1).unwrap(),
10609-
ASTRules::Typical
10609+
ASTRules::PrecheckSize
1061010610
);
1061110611
assert_eq!(
1061210612
SortitionDB::get_ast_rules(db.conn(), AST_RULES_PRECHECK_SIZE - 1).unwrap(),
10613-
ASTRules::Typical
10613+
ASTRules::PrecheckSize
1061410614
);
1061510615
assert_eq!(
1061610616
SortitionDB::get_ast_rules(db.conn(), AST_RULES_PRECHECK_SIZE).unwrap(),
@@ -10629,7 +10629,7 @@ pub mod tests {
1062910629

1063010630
assert_eq!(
1063110631
SortitionDB::get_ast_rules(db.conn(), 0).unwrap(),
10632-
ASTRules::Typical
10632+
ASTRules::PrecheckSize
1063310633
);
1063410634
assert_eq!(
1063510635
SortitionDB::get_ast_rules(db.conn(), 1).unwrap(),

stackslib/src/chainstate/stacks/db/transactions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ pub mod test {
16811681

16821682
pub const TestBurnStateDB_20: UnitTestBurnStateDB = UnitTestBurnStateDB {
16831683
epoch_id: StacksEpochId::Epoch20,
1684-
ast_rules: ASTRules::Typical,
1684+
ast_rules: ASTRules::PrecheckSize,
16851685
};
16861686
pub const TestBurnStateDB_2_05: UnitTestBurnStateDB = UnitTestBurnStateDB {
16871687
epoch_id: StacksEpochId::Epoch2_05,

stackslib/src/chainstate/stacks/miner.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -943,12 +943,10 @@ impl<'a> StacksMicroblockBuilder<'a> {
943943
StacksMicroblockHeader::first_unsigned(parent_anchor_block_hash, &tx_merkle_root)
944944
};
945945

946-
if ast_rules != ASTRules::Typical {
947-
next_microblock_header.version = cmp::max(
948-
STACKS_BLOCK_VERSION_AST_PRECHECK_SIZE,
949-
next_microblock_header.version,
950-
);
951-
}
946+
next_microblock_header.version = cmp::max(
947+
STACKS_BLOCK_VERSION_AST_PRECHECK_SIZE,
948+
next_microblock_header.version,
949+
);
952950

953951
next_microblock_header.sign(miner_key).unwrap();
954952
next_microblock_header.verify(&miner_pubkey_hash).unwrap();
@@ -1653,7 +1651,7 @@ impl StacksBlockBuilder {
16531651
clarity_tx,
16541652
tx,
16551653
quiet,
1656-
ASTRules::Typical,
1654+
ASTRules::PrecheckSize,
16571655
None,
16581656
) {
16591657
Ok((fee, receipt)) => {
@@ -1670,7 +1668,7 @@ impl StacksBlockBuilder {
16701668
clarity_tx,
16711669
tx,
16721670
quiet,
1673-
ASTRules::Typical,
1671+
ASTRules::PrecheckSize,
16741672
None,
16751673
) {
16761674
Ok((fee, receipt)) => {
@@ -2352,12 +2350,10 @@ impl StacksBlockBuilder {
23522350
let mut miner_epoch_info =
23532351
builder.pre_epoch_begin(&mut chainstate, burn_dbconn, settings.confirm_microblocks)?;
23542352
let ast_rules = miner_epoch_info.ast_rules;
2355-
if ast_rules != ASTRules::Typical {
2356-
builder.header.version = cmp::max(
2357-
STACKS_BLOCK_VERSION_AST_PRECHECK_SIZE,
2358-
builder.header.version,
2359-
);
2360-
}
2353+
builder.header.version = cmp::max(
2354+
STACKS_BLOCK_VERSION_AST_PRECHECK_SIZE,
2355+
builder.header.version,
2356+
);
23612357

23622358
let (mut epoch_tx, confirmed_mblock_cost) =
23632359
builder.epoch_begin(burn_dbconn, &mut miner_epoch_info)?;

stackslib/src/clarity_cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ pub fn vm_execute(program: &str, clarity_version: ClarityVersion) -> Result<Opti
461461
&mut (),
462462
clarity_version,
463463
DEFAULT_CLI_EPOCH,
464-
ASTRules::Typical,
464+
ASTRules::PrecheckSize,
465465
)?
466466
.expressions;
467467
eval_all(&parsed, &mut contract_context, g, None)

0 commit comments

Comments
 (0)