Skip to content
Akinbola0xKENZMAN
Work/Privacy & cryptography · Games
Stellar

Hidden moves with a ZK commitment

Proving three turns of moves are legal without revealing them.

Role
Sole author
When
Jan 2026 – now
Team
Solo
Stack
Noir, Pedersen hash

Overview

Clash's duel circuit checks every attack and defense is a valid enum value and returns a Pedersen commitment over the moves, the player's address and the session. The same moves in a different session give a different commitment, so commitments can't be replayed.

The code

duel_commit_circuit/src/main.nrView on GitHub ↗
fn main(
    attacks: [Field; 3],       // Private: player's attack choices
    defenses: [Field; 3],      // Private: player's defense choices
    player_address: pub Field, // Public: player's blockchain address
    session_id: pub Field,     // Public: game session identifier
) -> pub Field {
    for i in 0..3 { assert(attacks[i] as u8 <= 2, "Invalid attack value"); }
    for i in 0..3 { assert(defenses[i] as u8 <= 2, "Invalid defense value"); }
    pedersen_hash([
        attacks[0], attacks[1], attacks[2],
        defenses[0], defenses[1], defenses[2],
        player_address,
        session_id
    ])
}

#[test]
fn test_valid_different_sessions_produce_different_commitments() {
    let attacks = [0, 1, 2];
    let defenses = [1, 2, 0];
    let commitment_1 = main(attacks, defenses, 0x111111, 100);
    let commitment_2 = main(attacks, defenses, 0x111111, 200);
    assert(commitment_1 != commitment_2);
}

How it works

  1. Range checks on six private move values
  2. A commitment bound to player and session
  3. Tests for valid strategies, session separation and out-of-range moves (should_fail)

Part of

Stack

NoirPedersen hash