fix(dice-duel): prevent predictable outcomes with commit-reveal - #14
fix(dice-duel): prevent predictable outcomes with commit-reveal#14safal207 wants to merge 2 commits into
Conversation
|
| if game.phase != Phase::Revealing { | ||
| return Err(Error::GameAlreadyEnded); | ||
| } |
There was a problem hiding this comment.
💡 Quality: resolve_timeout returns GameAlreadyEnded for a Ready game
In resolve_timeout, a game in the Ready phase (both players validly revealed but reveal_winner not yet called) falls through the phase != Phase::Revealing guard and returns Error::GameAlreadyEnded. That is misleading: the game has not ended — it simply must be settled via reveal_winner rather than timed out. Callers/clients may interpret GameAlreadyEnded as a terminal state and stop, when the correct action is to call reveal_winner. Consider a distinct error (e.g. reuse BothPlayersNotRolled's counterpart or add a ReadyForSettlement code) so the timeout path signals "use reveal_winner" instead of "ended".
Was this helpful? React with 👍 / 👎
Code Review 👍 Approved with suggestions 0 resolved / 1 findingsImplements commit-reveal to prevent predictable dice-duel outcomes with session-bound 256-bit commitments, independent reveals, inclusive deadlines, and neutral cancellation. The core logic is sound and well-tested across unit, integration, and optimized-WASM resource coverage. Consider clarifying the 💡 Quality: resolve_timeout returns GameAlreadyEnded for a Ready game📄 contracts/dice-duel/src/lib.rs:474-476 In resolve_timeout, a game in the 🤖 Prompt for agentsOptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Important Your trial ends in 4 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more. Was this helpful? React with 👍 / 👎 | Gitar |
|
Mergeado. Verifiqué la rama entera en local antes: Coincide con lo que declarás en la descripción. Lo que cierraEste PR resuelve la #1, que era el problema más grave del repositorio: el Y hace algo que yo había marcado como riesgo aparte: el Una corrección que me toca a míCuando abrí este PR pensé que el problema era que reimplementaste el commit y Comparé las dos y la tuya es mejor que la mía en tres puntos concretos: 1. Preimage canónico. Vos armás un buf.append(&contract.to_string().to_bytes());
buf.append(&Bytes::from_array(env, &game.to_val().get_payload().to_be_bytes()));
buf.append(&Bytes::from_array(env, &session_id.to_be_bytes()));
buf.append(&player.to_string().to_bytes());Eso funciona porque las direcciones en string son de ancho fijo, pero es una 2. Separación de dominio. Tenés 3. Qué ata el compromiso. Vos atás los dos jugadores y las dos apuestas. Mi Aparte, mi truco de identificar el juego con Así que el problema no es que no hayas usado el crate compartido: es que el Un detalle que tu PR destapó, y es míoCompilando tu rama apareció esto: Es el marcador de la plantilla que agregué ayer. Está bien que sea un marcador, Gracias por el laburo, y por los vectores golden de XDR, que es la clase de test |
|
Aclaración: está en borrador, así que no puedo mergearla todavía. De mi lado ya está aprobada y verificada, con el detalle en el comentario de arriba. Cuando la marques como lista la mergeo. Si le falta algo, sin apuro. |
El marcador `__GAME_STRUCT__` dispara `non_camel_case_types`, asi que desde que agregue la plantilla cualquiera que compile el workspace ve un warning que no puede arreglar, y un gate de `-D warnings` falla por culpa de un contrato que ni siquiera es un juego. Aparecio compilando la rama de #14, que si usa ese gate. El marcador tiene que quedarse como esta: `bun run create` lo reemplaza por el nombre real y ahi la convencion se cumple sola. Lo que sobra es el warning. Co-authored-by: leocagli <organization@cosmospay.lat>
|
Gracias, Leo, por verificar la rama y por la revisión detallada. Voy a mantenerla en borrador por ahora. Tu ejecución valida el cambio de contrato en el head "88c6a069dbe2088d7c83fb319ffebf12a3a9c1ce", pero no cierra los cuatro gates de despliegue y cliente:
No afirmo que el Hub desplegado carezca de "cancel_game"; la afirmación exacta es que esa compatibilidad todavía no está demostrada. Además, "main" avanzó a "bc60a285727ad35a3c0c99062811d0bf2e6b31ff", por lo que el resultado combinado exacto aún no fue probado. Si preferís fusionarlo como un cambio contract-only y dejar esos cuatro puntos como gates de despliegue en follow-ups separados, confirmámelo. Primero ajustaré la descripción, actualizaré la rama contra "main" y volveré a ejecutar la suite sobre el nuevo SHA. Mientras tanto, mantengo el borrador. |
|
Thanks again for verifying the build and all 93 tests. To avoid blocking the GrantFox review while keeping deployment safety explicit, can we treat #1 as the contract-layer deliverable, merge the verified implementation, and track deployment reuse, storage migration, Hub ABI integration, and frontend migration as separate follow-ups? If that boundary works for you, I’ll update the branch, resolve the remaining review note, and mark PR #14 ready for review. |
|
Hi @leocagli, following up on the scope question from 2 September. Can you confirm that #1 can be accepted as a contract-layer deliverable, with Hub compatibility, deployment reuse checks, storage migration/new deployment, and frontend migration tracked as explicit prerequisites for deployment in separate follow-ups? Your successful build and 93-test run covered If accepting the contract layer separately does not work for this project, please identify which integration requirement must be completed within this PR. That will let me proceed against a clear acceptance boundary. Thanks! |
|
Hi @leocagli, could you give a scope decision by 16 September 2026 on the question in my 2 and 7 September comments? Can #1 be accepted as the contract-layer deliverable, with Hub compatibility, deployment reuse, storage migration/new deployment, and frontend integration remaining explicit deployment prerequisites in separate follow-ups? Or must any of those be completed in PR #14 before acceptance? If so, please identify the required items and dependencies. Your earlier build and 93-test verification are appreciated. Once the acceptance scope is confirmed, I can update the branch, address the remaining review note, and validate the resulting commit before marking the PR ready. The existing verification does not cover that future updated commit or deployment readiness. If you cannot decide by that date, please let me know who owns the decision and when it can be made. Until the scope is clarified, I am keeping the PR in draft and additional implementation paused. Thanks! |



Closes #1
Summary
session_idand reveal orderVerification
cargo fmt -p dice-duel -p mock-game-hub -- --checkcargo clippy -p dice-duel -p mock-game-hub --all-targets --no-deps -- -D warningscargo test --workspace --locked -j 2— 93 passed, 0 failed, 1 expected ignored resource testcargo build --locked --release --target wasm32v1-none -p dice-duel -p mock-game-hubcargo test -p dice-duel --test wasm_resource --locked -- --ignored --nocapture— passedPeak observed optimized-WASM lifecycle budget: 1,397,614 CPU instructions / 2,693,428 bytes memory.
Readiness gates
This remains a draft until all deployment and client gates are resolved:
cancel_game(session_id)neutral-settlement ABI and real refund semantics.No production deployment or Studio contract-ID change is included here.