tn-domain-contracts
Skill2 starsChanged 8 months agoMITView on GitHub
Domain expert reference for the telcoin-network smart-contract integration layer — ConsensusRegistry, StakeManager, Issuance bindings; system calls (concludeEpoch, applyIncentives, applySlashes); validator activation/exit; reward tier accounting. Loaded by tn-rust-engineer and tn-domain-reviewer when work touches crates/tn-reth/src/system_calls.rs, system-call ordering, or registry reads from Rust. NOT user-invocable. Loaded programmatically by tn-* agents via the Skill tool.
In this repository36 other files it gives its agents.
- agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- create-agentSkill
- doc-writerSkill
- feynman-auditorSkill
- gh-issueSkill
- human-writingSkill
- mermaidSkill
- nemesis-ogSkill
- nemesis-scanSkill
- outline-codeSkill
- report-to-pr-commentsSkill
- skill-creatorSkill
- solidity-security-scanSkill
- state-inconsistency-auditorSkill
- telx-reviewSkill
- tn-add-benchmarkSkill
- tn-bug-scanSkill
- tn-debug-e2eSkill
- tn-domain-consensusSkill
- tn-domain-epochSkill
- tn-domain-executionSkill
- tn-domain-networkingSkill
- tn-domain-storageSkill
- tn-domain-workerSkill
- tn-hardenSkill
- tn-nemesis-scanSkill
- tn-review-contractsSkill
- tn-reviewSkill
- tn-rust-engineerSkill
- tn-rust-skillsSkill
- tn-security-evalSkill
- tn-threat-modelSkill
- tn-write-crate-docSkill
- tn-write-e2eSkill
- tn-write-proptestSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
If you are about to modify code that:
- Distinctive: line 50
What's the call ordering relative to other system calls?: If this is at the closing block, list the full sequence: slashes (if any), …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
tn-domain-contracts
The on-chain ConsensusRegistry and StakeManager are the source of truth for committee membership, validator status, stake amounts, and reward tiers. The Rust node interacts with them via system calls fired from inside block execution. Mistakes in this layer are protocol-altering: a wrong committee gets installed, or rewards go to the wrong addresses, or slashes don't apply.
If you are about to modify code that:
- lives in
crates/tn-reth/src/system_calls.rs,crates/tn-reth/src/evm/block.rs - fires
concludeEpoch,applyIncentives, orapplySlashesfrom Rust - reads
ValidatorInfo,EpochInfo, orStakeConfigfrom contract storage - decodes contract return values for use in Rust state
…load this skill before writing a single line.
Why contracts are different
System calls are EVM transactions executed by the node, not by users. They run as part of a block's normal execution but originate from a privileged caller. Two consequences:
- Ordering is fixed by protocol, not by Rust ergonomics.
applyIncentivesruns beforeconcludeEpochso rewards credit the closing committee using closing stake versions. Reordering is a state-root divergence. - System-call inputs come from authoritative state, not local config. The new committee passed to
concludeEpochis computed from on-chain stake — not from a local list. Slashes come from consensus evidence, not from local heuristics.
Invariants
- System calls fire exactly once per intended boundary.
concludeEpochfires at the closing block of every epoch; firing it twice or zero times in a single epoch corrupts the registry state. applyIncentivesruns beforeconcludeEpochat the closing block. Incentives credit the closing committee (using their closing stake versions); concludeEpoch then transitions to the new committee.applySlashesruns at its consensus-dictated position. Typically before incentives if slashes occurred during the closing window; the consensus output specifies the position.- System-call inputs come from authoritative on-chain state. New committee derives from current stake (after slashes apply); rewards from gas accumulator counters; slashes from consensus evidence.
- Contract reads honor block-height pinning. Reading committee/stake/config for epoch N requires reading at the closing-block height of epoch N (cross-references
tn-domain-epochandtn-domain-execution).
Pre-write Checklist
- Which system call is this, and at which block does it fire? Name it. Closing block? Specific intra-epoch position?
- What's the input source? Authoritative on-chain state, gas accumulator snapshot, or consensus evidence — not local config or heuristic.
- What's the call ordering relative to other system calls? If this is at the closing block, list the full sequence: slashes (if any), incentives, conclude. Confirm the order matches the protocol.
- What state does this call read or write? Confirm reads use the right block height; confirm writes affect the next epoch's parameters (not the current one mid-epoch).
- Is the return value parsed correctly? ABI mismatches between Solidity and Rust silently corrupt — pin types and verify with a round-trip test.
Canonical Sources
| Value | Source | Avoid |
New committee for concludeEpoch | Computed from current stake state after slashes apply | Local list; pre-slash stake |
Rewards for applyIncentives | gas_accumulator.rewards_counter() snapshot at close | Live counter (still mutating) |
Slash list for applySlashes | Consensus output's slash field | Local heuristic (e.g., "this validator missed votes") |
| Validator activation/exit epochs | ValidatorInfo in ConsensusRegistry | Local timing assumptions |
| Stake version for reward tier | StakeManager versioning | Cached value across epochs |
| EpochInfo for past epoch N | Read at closing-block height of N | Live storage (may be from N+1 already) |
Common Bug Patterns
Pattern 1: System-call reorder at closing block
concludeEpoch runs before applyIncentives → incentives credit new committee using new stake versions. Wrong recipients, wrong amounts. State-root divergence.
Fix: enforce the order in code, document it next to the call sites.
Pattern 2: New committee includes inactive validators
The new committee passed to concludeEpoch should be derived from active validators after slashes have applied. Including inactive or just-slashed validators causes them to attempt participation next epoch and triggers further slashes for inactivity.
Pattern 3: ABI decode mismatch
// WRONG — Solidity returns (uint256, address[]); Rust decodes (uint256,) and discards
let (count,): (U256,) = decode(return_data)?;Pin the ABI type alongside the call site; round-trip test in CI.
Pattern 4: Reading registry from canonical tip for past epoch
To decide who the committee was during epoch N (e.g., to validate a late certificate), don't read live registry — it may show epoch N+1 already. Read at closing-block height of N or use the stored EpochRecord.
Pattern 5: Concluding epoch twice
Double-fire on retry path. Make concludeEpoch invocation idempotent against already-applied state, or guard with a "already closed" check.
Further Reading
references/invariants.mdreferences/bug-patterns.mdreferences/canonical-sources.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

