Skip to content

Commit 7f06876

Browse files
committed
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into chore/merge-develop-to-aac-client-breaking
2 parents 54f800b + 9dfb1d1 commit 7f06876

File tree

7 files changed

+272
-39
lines changed

7 files changed

+272
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1010
### Changed
1111

1212
- Renamed Clarity 4's new `block-time` to `stacks-block-time`
13+
- Improve cost-tracking for type-checking function arguments in epoch 3.3 (see [#6425](https://github.com/stacks-network/stacks-core/issues/6425))
1314

1415
## [3.2.0.0.2]
1516

clarity/src/vm/callables.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,18 @@ impl DefinedFunction {
146146
self.arguments.len(),
147147
)?;
148148

149-
for arg_type in self.arg_types.iter() {
150-
runtime_cost(
151-
ClarityCostFunction::InnerTypeCheckCost,
152-
env,
153-
arg_type.size()?,
154-
)?;
149+
if env.epoch().uses_arg_size_for_cost() {
150+
for arg in args.iter() {
151+
runtime_cost(ClarityCostFunction::InnerTypeCheckCost, env, arg.size()?)?;
152+
}
153+
} else {
154+
for arg_type in self.arg_types.iter() {
155+
runtime_cost(
156+
ClarityCostFunction::InnerTypeCheckCost,
157+
env,
158+
arg_type.size()?,
159+
)?;
160+
}
155161
}
156162

157163
let mut context = LocalContext::new();

stacks-common/src/types/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,27 @@ impl StacksEpochId {
789789
StacksEpochId::Epoch33 => true,
790790
}
791791
}
792+
793+
/// Before Epoch 3.3, the cost for arguments to functions was based on the
794+
/// parameter type, not the actual size of the argument passed in. This
795+
/// resulted in over-charging for arguments smaller than the maximum size
796+
/// permitted for the parameter.
797+
pub fn uses_arg_size_for_cost(&self) -> bool {
798+
match self {
799+
StacksEpochId::Epoch10
800+
| StacksEpochId::Epoch20
801+
| StacksEpochId::Epoch2_05
802+
| StacksEpochId::Epoch21
803+
| StacksEpochId::Epoch22
804+
| StacksEpochId::Epoch23
805+
| StacksEpochId::Epoch24
806+
| StacksEpochId::Epoch25
807+
| StacksEpochId::Epoch30
808+
| StacksEpochId::Epoch31
809+
| StacksEpochId::Epoch32 => false,
810+
StacksEpochId::Epoch33 => true,
811+
}
812+
}
792813
}
793814

794815
impl std::fmt::Display for StacksEpochId {

stackslib/src/chainstate/tests/consensus.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
//
1313
// You should have received a copy of the GNU General Public License
1414
// along with this program. If not, see <http://www.gnu.org/licenses/>.
15-
use std::cell::LazyCell;
1615
use std::collections::{BTreeSet, HashMap};
16+
use std::sync::LazyLock;
1717

1818
use clarity::boot_util::boot_code_addr;
1919
use clarity::codec::StacksMessageCodec;
@@ -62,7 +62,7 @@ pub const SK_2: &str = "4ce9a8f7539ea93753a36405b16e8b57e15a552430410709c2b6d65d
6262
pub const SK_3: &str = "cb95ddd0fe18ec57f4f3533b95ae564b3f1ae063dbf75b46334bd86245aef78501";
6363

6464
/// The private key for the faucet account.
65-
pub const FAUCET_PRIV_KEY: LazyCell<StacksPrivateKey> = LazyCell::new(|| {
65+
pub static FAUCET_PRIV_KEY: LazyLock<StacksPrivateKey> = LazyLock::new(|| {
6666
StacksPrivateKey::from_hex("510f96a8efd0b11e211733c1ac5e3fa6f3d3fcdd62869e376c47decb3e14fea101")
6767
.expect("Failed to parse private key")
6868
});
@@ -709,6 +709,8 @@ pub struct ExpectedTransactionOutput {
709709
pub struct ExpectedBlockOutput {
710710
/// The expected block marf
711711
pub marf_hash: TrieHash,
712+
/// The epoch in which the test block was expected to be evaluated
713+
pub evaluated_epoch: StacksEpochId,
712714
/// The expected outputs for each transaction, in input order.
713715
pub transactions: Vec<ExpectedTransactionOutput>,
714716
/// The total execution cost of the block.
@@ -735,25 +737,25 @@ impl ExpectedResult {
735737
Ok(epoch_receipt) => {
736738
let transactions: Vec<ExpectedTransactionOutput> = epoch_receipt
737739
.tx_receipts
738-
.iter()
740+
.into_iter()
739741
.map(|r| {
740-
let tx = match &r.transaction {
741-
TransactionOrigin::Stacks(tx) => Some(tx.payload.clone()),
742+
let tx = match r.transaction {
743+
TransactionOrigin::Stacks(tx) => Some(tx.payload),
742744
TransactionOrigin::Burn(..) => None,
743745
};
744746
ExpectedTransactionOutput {
745747
tx,
746-
return_type: r.result.clone(),
747-
cost: r.execution_cost.clone(),
748-
vm_error: r.vm_error.clone(),
748+
return_type: r.result,
749+
cost: r.execution_cost,
750+
vm_error: r.vm_error,
749751
}
750752
})
751753
.collect();
752-
let total_block_cost = epoch_receipt.anchored_block_cost.clone();
753754
ExpectedResult::Success(ExpectedBlockOutput {
754755
marf_hash,
756+
evaluated_epoch: epoch_receipt.evaluated_epoch,
755757
transactions,
756-
total_block_cost,
758+
total_block_cost: epoch_receipt.anchored_block_cost,
757759
})
758760
}
759761
Err(e) => ExpectedResult::Failure(e.to_string()),
@@ -873,7 +875,7 @@ impl ConsensusTest<'_> {
873875
"--------- Processed block: {sig_hash} ---------";
874876
"block" => ?nakamoto_block
875877
);
876-
let remapped_result = res.map(|receipt| receipt.unwrap()).into();
878+
let remapped_result = res.map(|receipt| receipt.unwrap());
877879
// Restore chainstate for the next block
878880
self.chain.sortdb = Some(sortdb);
879881
self.chain.stacks_node = Some(stacks_node);
@@ -1009,14 +1011,14 @@ impl ConsensusTest<'_> {
10091011
fn compute_block_marf_root_hash(
10101012
&mut self,
10111013
block_time: u64,
1012-
block_txs: &Vec<StacksTransaction>,
1014+
block_txs: &[StacksTransaction],
10131015
) -> Result<TrieHash, String> {
10141016
let node = self.chain.stacks_node.as_mut().unwrap();
10151017
let sortdb = self.chain.sortdb.as_ref().unwrap();
10161018
let burndb_conn = sortdb.index_handle_at_tip();
10171019
let chainstate = &mut node.chainstate;
10181020

1019-
let chain_tip = NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb)
1021+
let chain_tip = NakamotoChainState::get_canonical_block_header(chainstate.db(), sortdb)
10201022
.unwrap()
10211023
.unwrap();
10221024

@@ -1039,7 +1041,7 @@ impl ConsensusTest<'_> {
10391041
chain_tip.burn_header_height,
10401042
);
10411043
clarity_tx.rollback_block();
1042-
return result;
1044+
result
10431045
}
10441046

10451047
/// This is where the real MARF computation happens.
@@ -1049,7 +1051,7 @@ impl ConsensusTest<'_> {
10491051
fn inner_compute_block_marf_root_hash(
10501052
clarity_tx: &mut ClarityTx,
10511053
block_time: u64,
1052-
block_txs: &Vec<StacksTransaction>,
1054+
block_txs: &[StacksTransaction],
10531055
burn_header_height: u32,
10541056
) -> Result<TrieHash, String> {
10551057
clarity_tx

stackslib/src/chainstate/tests/snapshots/blockstack_lib__chainstate__tests__consensus__append_stx_transfers_success.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ expression: result
55
[
66
Success(ExpectedBlockOutput(
77
marf_hash: "95999ab12ae2162f2dd25c4a7f7807017b3b5d20f28a53248e37c9864f923718",
8+
evaluated_epoch: Epoch32,
89
transactions: [
910
ExpectedTransactionOutput(
1011
tx: "TokenTransfer(from: ST000000000000000000002AMW42H, amount: 1000, memo: 00000000000000000000000000000000000000000000000000000000000000000000)",
@@ -62,6 +63,7 @@ expression: result
6263
)),
6364
Success(ExpectedBlockOutput(
6465
marf_hash: "7e9b86e5b0ff545908784c1c674d1354228ce2884395ced13f7c9e4eaa7ecfd0",
66+
evaluated_epoch: Epoch33,
6567
transactions: [
6668
ExpectedTransactionOutput(
6769
tx: "TokenTransfer(from: ST000000000000000000002AMW42H, amount: 1000, memo: 00000000000000000000000000000000000000000000000000000000000000000000)",

0 commit comments

Comments
 (0)