-
Notifications
You must be signed in to change notification settings - Fork 95
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 #663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ pub struct Game { | |
| pub moves: Vec<ChessMove>, | ||
| pub created_at: u64, | ||
| pub winner: Option<Address>, | ||
| pub proof_of_game: BytesN<32>, | ||
| pub last_move_at: u64, // Ledger sequence of last move | ||
| } | ||
|
|
||
|
|
@@ -209,6 +210,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]), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing unit tests for the new Issue Want me to draft the test cases? 🤖 Prompt for AI Agents |
||
| last_move_at: env.ledger().sequence() as u64, | ||
| }; | ||
|
|
||
|
|
@@ -324,9 +326,21 @@ impl GameContract { | |
|
|
||
| let chess_move = ChessMove { | ||
| player: player.clone(), | ||
| move_data, | ||
| move_data: move_data.clone(), | ||
| timestamp: env.ledger().sequence() as u64, | ||
| }; | ||
|
|
||
| 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); | ||
|
Comment on lines
+332
to
+344
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proof payload is not canonical — omits player/game_id and lacks length framing for The current chaining hashes
Consider encoding the move with explicit framing, e.g.: ♻️ Proposed fix let mut proof_payload = Bytes::new(&env);
proof_payload.append(&game.proof_of_game.clone().into());
+ // Domain separation / binding
+ proof_payload.append(&Bytes::from_slice(&env, &game.id.to_le_bytes()));
+ proof_payload.append(&Bytes::from_slice(&env, &(player_num as u32).to_le_bytes()));
+ // Length-prefix the variable-length move_data to prevent concatenation ambiguity
+ proof_payload.append(&Bytes::from_slice(&env, &(move_data.len() as u32).to_le_bytes()));
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();🤖 Prompt for AI Agents |
||
| game.current_turn = if game.current_turn == 1 { 2 } else { 1 }; | ||
| game.last_move_at = env.ledger().sequence() as u64; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: NOVUS-X/XLMate
Length of output: 10043
Update test.rs Game struct literal to include the required proof_of_game field.
The
Gamestruct literal in test.rs (lines 23–33) is missing theproof_of_game: BytesN<32>field that was added to the struct definition. This will cause a compilation error. Addproof_of_game: BytesN::from_array(&env, &[0; 32]),to the literal to match the struct definition and the initialization used increate_game(lib.rs:155).🤖 Prompt for AI Agents