consensus-math-correctness

A review of arithmetic that determines blockchain consensus, such as difficulty, rewards, moving averages, and target timing. Consensus is the shared rule that lets network nodes agree on the chain's state.

In plain words
What is it for?
Use it when checking Go or Rust code for truncation, incorrect bounds, reversed moving-average adjustments, or threshold edge cases.
Why use it?
Small arithmetic errors can consistently produce the wrong protocol result, such as a miscalculated difficulty or threshold.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/plamentsv/plamen/consensus-math-correctness
Any agent
npx skills add PlamenTSV/plamen --skill consensus-math-correctness
Clone the repo
git clone --depth 1 https://github.com/PlamenTSV/plamen

Made for: Claude Code, Codex.

Per session 30 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,108 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00030 $0.01108
Opus 5 $0.00015 $0.00554
Sonnet 5 $0.00006 $0.00222
Haiku 4.5 $0.00003 $0.00111

Measured 3d ago against content hash a64476cbb442, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

consensus-math-correctness scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

agents/skills/injectable/l1/consensus-math-correctness/SKILL.md · 125 lines

How it starts

The opening of the file, as written. The whole thing — 125 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Injectable Skill: Consensus Math Correctness

L1 trigger: CONSENSUS flag AND (adjust_difficulty OR difficulty_adjust OR ema OR moving_average OR reward_curve OR target_time detected) Inject Into: depth-consensus-invariant or depth-edge-case Language: Go and Rust Finding prefix: [CM-N]

Consensus math bugs are small, deterministic, and load-bearing. They rarely need fancy exploit chains: one wrong operator, one dead bound, or one flipped EMA direction can permanently skew the chain.

1. Division-before-multiplication

For every expression of the form (A / B) * C, test whether A < B is possible. If so, the intermediate division truncates to zero before the multiplication and the protocol silently loses precision.

Questions:

  1. Can A < B happen at runtime?
  2. Is the intended formula mathematically (A * C) / B?
  3. If multiplication moves first, is there an overflow guard on the wider intermediate?

Tag: [CONSENSUS-MATH:DIV-FIRST]

2. Declared-but-unapplied bounds

Consensus configs often declare bounds that never influence runtime math.

Questions:

  1. Which config fields look like bounds or caps? Example names: max_difficulty_adjustment_factor, min_reward, max_step_count.
  2. Is each field used only during config parsing, or also in the live computation?
  3. If a field is declared but never applied at runtime, what unbounded state transition does that permit?

Tag: [CONSENSUS-MATH:UNUSED-BOUND]

3. EMA / moving-average direction

For each moving-average implementation, identify the prior sample, current sample, and smoothing factor.

Questions:

  1. Does the code use the same sample ordering as the design doc or comments?
  2. Is the "previous" state actually previous, or has the implementation swapped current and prior inputs?
  3. If the direction is flipped, does the chain overreact instead of smoothing?

Tag: [CONSENSUS-MATH:EMA-DIRECTION]

4. Threshold operators

Consensus edge cases often live at threshold-1, threshold, and threshold+1.

Read the full file on GitHub · 125 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 125 lines · 30 tokens per session scan A a64476cbb442

Subscribe to this mod's changes

consensus-math-correctness is a skill published in the GitHub repository PlamenTSV/plamen (281 stars, last pushed 1mo ago), licensed MIT. It adds 30 tokens to every session and 1,108 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.