Miden edge execution: combat engine + arena account#7
Draft
WiktorStarczewski wants to merge 11 commits intomainfrom
Draft
Miden edge execution: combat engine + arena account#7WiktorStarczewski wants to merge 11 commits intomainfrom
WiktorStarczewski wants to merge 11 commits intomainfrom
Conversation
- Clamp death animation on last frame using LoopOnce so the model stays collapsed instead of looping - Show KO'd champions in death pose during settle/second anim phases and outside animation phase when no survivors remain - Track secondActed in AnimScript to avoid playing attack animation for champions KO'd before their turn
Port TypeScript combat engine to #![no_std] Rust in crates/combat-engine/. Zero dependencies, fixed-point arithmetic, no heap allocation. Modules: types, elements, champions, damage, codec, combat. 33 tests including full 3v3 battle integration test.
- Install cargo-miden v0.7.1, scaffold account + program templates - Import combat-engine crate into Miden program, compile to .masp - Execute 1v1 combat in Miden VM: output matches native Rust exactly - Add resolve_turn_mut to combat-engine (Miden-friendly in-place variant) - Discovered compiler bug: large struct returns silently miscompiled - Workaround: inline combat logic instead of returning TurnResult - Track findings in tasks/todo.md and tasks/lessons.md
- Arena account component (contracts/arena-account/) with 21-slot storage layout - 6 procedures: join, set_team, submit_commit, submit_reveal, resolve_current_turn, claim_timeout - Inlined combat resolution (all ability types, burn, buffs, team elimination) - Champion state packing module (crates/combat-engine/src/pack.rs) with 7 native tests - Compiler bug repro (contracts/combat-test-broken/) for Dennis - SHA-256 verification, P2ID payouts, and block height access deferred as TODOs - Builds to 381KB .masp, all 40 combat-engine tests pass
greenhat
reviewed
Feb 24, 2026
|
|
||
| let mut rounds = 0u32; | ||
|
|
||
| while !storm.is_ko && !quake.is_ko && rounds < 50 { |
There was a problem hiding this comment.
Is it an equivalent (inlined) code from the combat-test-broken entrypoint? It seems different.
Replace P2P note patterns with arena contract interactions for staking, team submission, and combat commit/reveal. Matchmaking and draft picks remain P2P. - Add arenaNote.ts: note script loader, builders, two-tx orchestrator - Add useArenaState: arena storage polling backed by Zustand store - Add ArenaSetupScreen: post-draft stake + team submission flow - Rewrite commitment.ts: SHA-256 to RPO256 (sync, matches contract) - Rewrite useStaking: P2IDE to process_stake_note via arena - Rewrite useCommitReveal: P2P attachments to submit_move_note - Rewrite useCombatTurn: arena-based phase machine with fallback - Update useNoteDecoder: remove stake/raw categories - Update gameStore: add ArenaState slice, arenaSetup screen - Remove dead code: CommitRevealStatus, bytes.ts, MSG_TYPE_* - Update tests for new RPO256 commitment API
- WebClient → WasmWebClient (has syncState method) - Remove unused ARENA_ACCOUNT_ID import from arenaNote.ts - Get note ID via note.id() before submission instead of from TransactionId - Word.asInt() → Word.toFelts()[0].asInt() - AccountId.toWord() → AccountId.prefix()/suffix().asInt()
- Remove burn system (DamageDot, burn_turns, calculateBurnDamage) - Flatten champion data to struct-of-arrays (SoA) for smaller WASM - Reduce champions 10→8, merge Buff/Debuff→StatMod ability type - Add feature gates (track-damage, events, resolve-mut) to combat-engine - Create matchmaking-account (212KB): join, set_team, receive_result, claim_timeout, send_payout, receive_asset - Create combat-account (425KB): init_combat, submit_commit, submit_reveal, resolve, claim_combat_timeout, send_result_note - Add init-combat-note and process-result-note for cross-account comms - Retarget stake/team notes → matchmaking, move note → combat - Update all WIT bindings for new account names - Add defense-in-depth validation (duplicate/overlap) in init_combat - Update frontend: remove burn UI, dual-account polling, codec ranges - Fix getChampionHp bug, pool size constant, codec test ranges - Exclude combat-test-broken from workspace - All 38 Rust tests pass, 50 TS tests pass, TSC clean
Add native MASM combat account (143KB, under 256KB limit) replacing the Rust-compiled version (425KB). Includes MASM note scripts for init_combat and submit_move, compiled against the combat library to ensure correct procedure digest resolution. Deploy script updated to use the MASM build for combat artifacts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
crates/combat-engine/) with 40 tests — deterministic damage, buffs, debuffs, burn, heals, KO, full 3v3 battlescontracts/arena-account/) with 21-slot storage layout and 6 procedures:join,set_team,submit_commit,submit_reveal,resolve_current_turn,claim_timeout[u64; 4]↔ChampionState) for Miden Word storagecontracts/combat-test/) validating deterministic combat execution — native Rust and Miden VM produce identical resultscontracts/combat-test-broken/) — large struct returns lose mutations in Miden compiler v0.7.1, reported upstreamDeferred
submit_reveal)Also includes
Test plan
cargo test -p combat-engine— 40 tests passcargo miden build --releaseincontracts/arena-account/— produces 381KB .maspmiden vm runofcombat-test— output matches native Rust exactlycargo miden testbug)