From 0c64cb3c67a9681e80f9e08d5f66c4874984451d Mon Sep 17 00:00:00 2001 From: Collins C Augustine Date: Thu, 23 Apr 2026 13:13:35 +0100 Subject: [PATCH] feat: implemented the 'Proof of Game' via SHA-256 Move History hashing feature while ensuring high resource efficiency (Gas/CPU) by utilizing a Rolling Hash --- contracts/game_contract/src/lib.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/contracts/game_contract/src/lib.rs b/contracts/game_contract/src/lib.rs index fb7aa38..20aff63 100644 --- a/contracts/game_contract/src/lib.rs +++ b/contracts/game_contract/src/lib.rs @@ -31,6 +31,7 @@ pub struct Game { pub moves: Vec, pub created_at: u64, pub winner: Option
, + pub proof_of_game: BytesN<32>, } #[contracttype] @@ -151,6 +152,7 @@ impl GameContract { moves: Vec::new(&env), created_at: env.ledger().sequence() as u64, winner: None, + proof_of_game: BytesN::from_array(&env, &[0; 32]), }; let mut games: Map = env @@ -262,10 +264,22 @@ impl GameContract { let chess_move = ChessMove { player: player.clone(), - move_data, + move_data: move_data.clone(), timestamp: env.ledger().sequence() as u64, }; - game.moves.push_back(chess_move.into()); + + let mut proof_payload = Bytes::new(&env); + proof_payload.append(&game.proof_of_game.clone().into()); + for m in move_data.iter() { + proof_payload.append(&Bytes::from_slice(&env, &m.to_le_bytes())); + } + proof_payload.append(&Bytes::from_slice( + &env, + &chess_move.timestamp.to_le_bytes(), + )); + game.proof_of_game = env.crypto().sha256(&proof_payload).into(); + + game.moves.push_back(chess_move); game.current_turn = if game.current_turn == 1 { 2 } else { 1 }; games.set(game_id, game);