Skip to content

updated costs_5#7389

Merged
brice-stacks merged 10 commits into
stacks-network:release/4.0.0from
rob-stacks:feat/costs_5_from_valgrind_bench_tool
Jul 10, 2026
Merged

updated costs_5#7389
brice-stacks merged 10 commits into
stacks-network:release/4.0.0from
rob-stacks:feat/costs_5_from_valgrind_bench_tool

Conversation

@rob-stacks

@rob-stacks rob-stacks commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

This patch assigns the new runtime costs based on the clarity-cost-bench tool (valgrind based) available at https://github.com/rob-stacks/stacks-core/tree/feat/costs_bench_valgrind.

This is the (current) results/analysis of the tool

costs.txt

Every entry has a detailed comment explaining the logic behind the math/values

Additional Notes

  • Few of the functions are still not covered
  • The tool is able to measure MARF accesses too, as a secondart step we could revisit the read/write costs too (even if they rarely caused issues)
  • The clarity contract for costs should be updated too but for making to PR more readable i am deferring it to a different PR

Applicable issues

Additional info (benefits, drawbacks, caveats)

Checklist

  • Test coverage for new or modified code paths
  • For new Clarity features or consensus changes, add property tests (see docs/property-testing.md)
  • Changelog fragment(s) or "no changelog" label added (see changelog.d/README.md)
  • Required documentation changes (e.g., rpc/openapi.yaml for RPC endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo

@rob-stacks
rob-stacks marked this pull request as draft July 6, 2026 13:44
@rob-stacks
rob-stacks marked this pull request as ready for review July 7, 2026 15:35
@coveralls

coveralls commented Jul 7, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 29114246895

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Warning

No base build found for commit 8a3bd08 on release/4.0.0.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 86.537%

Details

  • Patch coverage: 59 uncovered changes across 1 file (98 of 157 lines covered, 62.42%).

Uncovered Changes

File Changed Covered %
clarity/src/vm/costs/costs_5.rs 150 91 60.67%
Total (3 files) 157 98 62.42%

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 231363
Covered Lines: 200214
Line Coverage: 86.54%
Coverage Strength: 19343271.96 hits per line

💛 - Coveralls

@rob-stacks
rob-stacks requested a review from aaronb-stacks July 7, 2026 15:36
Comment thread clarity/src/vm/costs/costs_5.rs Outdated
@rob-stacks
rob-stacks requested a review from aaronb-stacks July 8, 2026 10:16
aaronb-stacks
aaronb-stacks previously approved these changes Jul 8, 2026
@cylewitruk-stacks

Copy link
Copy Markdown
Contributor

It feels a bit like we should have https://github.com/rob-stacks/stacks-core/tree/feat/costs_bench_valgrind PR'd/reviewed/merged before merging in costs based on it? Or, what does everyone else think?

@aaronb-stacks

Copy link
Copy Markdown
Contributor

It feels a bit like we should have https://github.com/rob-stacks/stacks-core/tree/feat/costs_bench_valgrind PR'd/reviewed/merged before merging in costs based on it? Or, what does everyone else think?

I'm not too worried about merging that branch before the costs -- historically, the benchmarks lived in a separate repo entirely, and the cost changes were reviewed more or less exactly this way. Not that this is the best process in the world, but I'm not convinced that we should hold up review of the PR to change that.

Comment thread clarity/src/vm/costs/costs_5.rs Outdated
Comment thread clarity/src/vm/costs/costs_5.rs Outdated
Comment thread changelog.d/costs-5-valgrind-calibration.changed Outdated
Comment thread clarity/src/vm/costs/costs_5.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Clarity 6 / Epoch 4.0 runtime cost schedule (costs_5.rs) by replacing many Costs4 forwards with new bench-derived formulas (plus associated snapshot/changelog updates), based on Callgrind instruction-count measurements from clarity-cost-bench.

Changes:

  • Recalibrates many Costs5 runtime cost functions with new constants/linear formulas derived from benchmarking.
  • Updates an existing chainstate test snapshot to reflect the new runtime cost outputs.
  • Adds a changelog fragment documenting the new calibration and a crypto-cost correction.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
clarity/src/vm/costs/costs_5.rs Replaces many forwarded costs with new bench-derived runtime formulas/constants for Epoch 4.0.
stackslib/src/chainstate/tests/snapshots/blockstack_lib__chainstate__tests__static_analysis_tests__tuple_merge_overflow_unused_runtime_ccall.snap Updates expected runtime cost values to match the recalibrated schedule.
changelog.d/costs-5-valgrind-calibration.changed Documents the calibration methodology/baseline and notable cost changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread clarity/src/vm/costs/costs_5.rs Outdated
Comment thread clarity/src/vm/costs/costs_5.rs Outdated
Comment thread changelog.d/costs-5-valgrind-calibration.changed Outdated
@rob-stacks

Copy link
Copy Markdown
Contributor Author

Updated the tool to correctly profile index-of and comparison functions. Set the baseline to 80k per unit (a bit more conservative). Re-uploaded costs.txt with the new values

@aaronb-stacks
aaronb-stacks changed the base branch from pox-wf-integration to develop July 10, 2026 14:41
@aaronb-stacks
aaronb-stacks dismissed their stale review July 10, 2026 14:41

The base branch was changed.

@aaronb-stacks

Copy link
Copy Markdown
Contributor

Changed base branch to develop, now that pox-wf-integration has been merged there, we're preparing the 4.0 release from there.

aaronb-stacks
aaronb-stacks previously approved these changes Jul 10, 2026
@cylewitruk-stacks

Copy link
Copy Markdown
Contributor

Throwing another Copilot sanity-check at it quick

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread clarity/src/vm/costs/costs_5.rs
Comment thread clarity/src/vm/costs/costs_5.rs
@brice-stacks
brice-stacks changed the base branch from develop to release/4.0.0 July 10, 2026 17:21
@brice-stacks
brice-stacks dismissed aaronb-stacks’s stale review July 10, 2026 17:21

The base branch was changed.

aaronb-stacks
aaronb-stacks previously approved these changes Jul 10, 2026

@brice-stacks brice-stacks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good, but can we also remove costs-5.clar here (along with its deployment), so that don't end up with a cost contract that doesn't match the actual costs?

With cost-voting removed, we no longer need to publish the costs in a
Clarity contract.
@brice-stacks
brice-stacks merged commit 2fb646a into stacks-network:release/4.0.0 Jul 10, 2026
436 of 439 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants