Skip to content

Commit ffd637b

Browse files
committed
Bundle the curried arguments for clarity
1 parent 395fa41 commit ffd637b

File tree

5 files changed

+75
-18
lines changed

5 files changed

+75
-18
lines changed

resources/debug_game_handler.clsp

+57-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
;; Debug game handler
2+
;;
3+
;; The validation info hash result is the sha256 of the concatenation of two
4+
;; hashes.
5+
;;
6+
;; 1 - A program which aborts if the move is a cheat.
7+
;; 2 - The sha256tree of the program state.
8+
;;
9+
;; In the debug game, the whole state is described by the readable move data.
10+
11+
;; Curried = MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO
12+
213
(include *standard-cl-23*)
314

415
(import std.curry)
516
(import std.map)
617
(import std.shatree)
718

19+
(defun-inline curried_mod_hash (CURRIED) (f CURRIED))
20+
(defun-inline curried_puzzle (CURRIED) (f (r CURRIED)))
21+
(defun-inline curried_amount (CURRIED) (f (r (r CURRIED))))
22+
(defun-inline curried_my_turn (CURRIED) (f (r (r (r CURRIED)))))
23+
(defun-inline curried_slash_info (CURRIED) (f (r (r (r (r CURRIED))))))
24+
(defun-inline curried_other_turn (CURRIED)
25+
(list
26+
(curried_mod_hash CURRIED)
27+
(curried_puzzle CURRIED)
28+
(curried_amount CURRIED)
29+
(not (curried_my_turn CURRIED))
30+
(curried_slash_info CURRIED)
31+
)
32+
)
33+
834
(defun get-validation-move
935
(MOVER_PUZZLE_HASH
1036
WAITER_PUZZLE_HASH
@@ -27,54 +53,73 @@
2753

2854
(defun validation_program (validation-data)
2955
(assign
30-
cheated (substr (get-validation-move validation-data) 0 1)
56+
cheated (logand (get-validation-move validation-data) 1)
3157
(if cheated
3258
(x "validation program cheating" validation-data)
3359
()
3460
)
3561
)
3662
)
3763

38-
(defun do_my_turn (MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO readable_new_move amount state entropy)
64+
(defun do_my_turn (CURRIED readable_new_move amount state entropy)
3965
(assign
4066

67+
;; Readable move is a clvm structure that describes the move
68+
;; uncompressed.
4169
(set_share . set_cheated) readable_new_move
4270

43-
new_validation_program_hash (shatree state "this is not right") ;; XXX just anything
71+
;; Validation info
72+
validation_info readable_new_move
73+
74+
state_hash (shatree state)
75+
other_turn (curried_other_turn CURRIED)
76+
77+
program-hash
78+
(curry_unhashed_args
79+
(curried_mod_hash other_turn)
80+
other_turn
81+
)
82+
83+
new_state
84+
(logior (logand 1 set_cheated) (ash set_share 1))
85+
86+
new_validation_program_hash
87+
(sha256 program-hash (shatree new_state))
4488

4589
(list
46-
(logior (logand 1 set_cheated) (ash set_share 1))
90+
new_state
4791
validation_program
4892
new_validation_program_hash
4993
(c set_share set_cheated)
5094
100
5195
set_share
52-
(curry PUZZLE MOD_HASH PUZZLE AMOUNT (not MY_TURN) SLASH_INFO)
96+
(curry (curried_puzzle CURRIED) other_turn)
5397
()
5498
)
5599
)
56100
)
57101

58-
(defun do_their_turn (MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO amount last_state new_move new_validation_info_hash new_max_move_size new_mover_share)
102+
(defun do_their_turn (CURRIED amount last_state new_move new_validation_info_hash new_max_move_size new_mover_share)
59103
(assign
60104
set_cheated (logand new_move 1)
105+
other_turn (curried_other_turn CURRIED)
61106

62107
(if set_cheated
63-
(c 2 SLASH_INFO)
108+
(c 2 (curried_slash_info CURRIED))
64109
(list
65110
0
66111
(c set_cheated (get-move-share new_move)) ;; readable move
67-
(curry PUZZLE MOD_HASH PUZZLE AMOUNT (not MY_TURN) SLASH_INFO)
112+
(curry (curried_puzzle CURRIED) other_turn)
68113
"message data"
69114
)
70115
)
71116
)
72117
)
73118

74119
(export
75-
(MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO . args)
76-
(if MY_TURN
77-
(do_my_turn MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO &rest args)
78-
(do_their_turn MOD_HASH PUZZLE AMOUNT MY_TURN SLASH_INFO &rest args)
120+
(CURRIED . args)
121+
(if (curried_my_turn CURRIED)
122+
(do_my_turn CURRIED &rest args)
123+
(do_their_turn CURRIED &rest args)
79124
)
80125
)

resources/debug_game_handler.hex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ff02ffff01ff02ffff03ff2fffff01ff02ff10ffff04ff02ffff04ff05ffff04ff0bffff04ff17ffff04ff2fffff04ff5fff7f80808080808080ffff01ff02ff14ffff04ff02ffff04ff05ffff04ff0bffff04ff17ffff04ff2fffff04ff5fff7f8080808080808080ff0180ffff04ffff01ffffffff02ff18ffff04ff02ffff04ff03ffff04ff8200bfffff04ffff02ff2effff04ff02ffff04ff8202ffffff04ffff019174686973206973206e6f74207269676874ff8080808080ff808080808080ff04ffff19ffff18ffff0101ff1b80ffff16ff13ffff01018080ffff04ffff04ffff0102ffff04ffff04ffff0101ff3e80ffff04ffff04ffff0104ffff04ffff04ffff0101ff0280ffff04ffff0101ff80808080ff80808080ffff04ff17ffff04ffff04ff13ff1b80ffff04ffff0164ffff04ff13ffff04ffff02ff16ffff04ff02ffff04ff15ffff04ff09ffff04ff15ffff04ff2dffff04ffff20ff5d80ffff04ff8200bdff808080808080808080ffff04ff80ff808080808080808080ffff02ff2cffff04ff02ffff04ff03ffff04ffff18ff8202ffffff010180ff8080808080ffff02ffff03ff0bffff01ff04ffff0102ff8200bd80ffff01ff04ff80ffff04ffff04ff0bffff02ff3cffff04ff02ffff04ff8205fdff8080808080ffff04ffff02ff16ffff04ff02ffff04ff15ffff04ff09ffff04ff15ffff04ff2dffff04ffff20ff5d80ffff04ff8200bdff808080808080808080ffff04ffff018c6d6573736167652064617461ff808080808080ff0180ff16ff05ffff0181ff80ffff82017fff02ffff03ff05ffff01ff04ffff0104ffff04ffff04ffff0101ff0980ffff04ffff02ff1affff04ff02ffff04ff0dff80808080ff80808080ffff01ff010180ff0180ffff04ffff0102ffff04ffff04ffff0101ff0580ffff04ffff02ff1affff04ff02ffff04ff07ff80808080ff80808080ffff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff2effff04ff02ffff04ff09ff80808080ffff02ff2effff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff02ffff03ffff0cffff02ff12ffff04ff02ffff04ff05ff80808080ff80ffff010180ffff01ff08ffff019b76616c69646174696f6e2070726f6772616d206368656174696e67ff0580ffff01ff018080ff0180ff018080
1+
ff02ffff01ff02ffff03ff5dffff01ff02ff10ffff04ff02ffff04ff05ff07808080ffff01ff02ff14ffff04ff02ffff04ff05ff0780808080ff0180ffff04ffff01ffffffff02ff28ffff04ff02ffff04ff03ffff04ff0bffff04ff0bffff04ffff02ff2effff04ff02ffff04ff2fff80808080ffff04ffff04ff09ffff04ff15ffff04ff2dffff04ffff20ff5d80ffff04ff8200bdff808080808080ff8080808080808080ffff02ff38ffff04ff02ffff04ff03ffff04ffff02ff26ffff04ff02ffff04ff82009fffff04ffff02ff2effff04ff02ffff04ff5fff80808080ff8080808080ffff04ffff19ffff18ffff0101ff1b80ffff16ff13ffff01018080ff808080808080ff04ff17ffff04ffff04ffff0102ffff04ffff04ffff0101ff3e80ffff04ffff04ffff0104ffff04ffff04ffff0101ff0280ffff04ffff0101ff80808080ff80808080ffff04ffff0bff0bffff02ff2effff04ff02ffff04ff17ff8080808080ffff04ffff04ff25ff3580ffff04ffff0164ffff04ff25ffff04ffff02ff3affff04ff02ffff04ff51ffff04ff8200bdff8080808080ffff04ff80ff808080808080808080ffff02ffff03ffff18ff2fffff010180ffff01ff04ffff0102ff8200bd80ffff01ff04ff80ffff04ffff04ffff18ff2fffff010180ffff02ff2cffff04ff02ffff04ff2fff8080808080ffff04ffff02ff3affff04ff02ffff04ff15ffff04ffff04ff09ffff04ff15ffff04ff2dffff04ffff20ff5d80ffff04ff8200bdff808080808080ff8080808080ffff04ffff018c6d6573736167652064617461ff808080808080ff0180ffff16ff05ffff0181ff8082017fffffff02ffff03ff05ffff01ff04ffff0104ffff04ffff04ffff0101ff0980ffff04ffff02ff12ffff04ff02ffff04ff0dff80808080ff80808080ffff01ff010180ff0180ffff02ffff03ff05ffff01ff0bffff06ffff06ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c58080ffff02ff36ffff04ff02ffff04ff09ffff04ffff02ff2affff04ff02ffff04ff0dff80808080ff808080808080ffff01ff06ffff05ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c5808080ff0180ff04ffff0102ffff04ffff04ffff0101ff0580ffff04ffff02ff12ffff04ff02ffff04ff07ff80808080ff80808080ffffff0bffff05ffff06ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c58080ffff02ff36ffff04ff02ffff04ff05ffff04ffff02ff2affff04ff02ffff04ff07ff80808080ff808080808080ff0bffff0102ffff0bffff0102ffff06ffff05ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c58080ff0580ffff0bffff0102ff0bffff05ffff05ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c580808080ffff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff2effff04ff02ffff04ff09ff80808080ffff02ff2effff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff02ffff03ffff18ffff02ff3cffff04ff02ffff04ff05ff80808080ffff010180ffff01ff08ffff019b76616c69646174696f6e2070726f6772616d206368656174696e67ff0580ffff01ff018080ff0180ff018080

src/channel_handler/game_handler.rs

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ fn run_code(
148148
.map(|r| r.1)
149149
}
150150

151+
#[derive(Debug, Clone)]
151152
pub enum TheirTurnResult {
152153
MakeMove(GameHandler, NodePtr, Vec<u8>),
153154
Slash(NodePtr, Aggsig),

src/referee/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ use crate::common::types::{
2222

2323
pub const REM_CONDITION_FIELDS: usize = 4;
2424

25+
#[derive(Debug, Clone)]
2526
pub struct RefereeMakerMoveResult {
2627
pub puzzle_hash_for_unroll: PuzzleHash,
2728
pub move_made: Vec<u8>,
29+
/// sha256 of the concatenation of two hashes:
30+
/// 1 - The next game handler program
31+
/// 2 - The game state.
2832
pub validation_info_hash: Hash,
2933
pub max_move_size: usize,
3034
pub mover_share: Amount,
3135
}
3236

37+
#[derive(Debug, Clone)]
3338
pub struct TheirTurnMoveResult {
3439
pub puzzle_hash_for_unroll: PuzzleHash,
3540
pub readable_move: NodePtr,

src/tests/referee.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ fn make_debug_game_handler(allocator: &mut AllocEncoder, amount: &Amount) -> Gam
2222
let curried_game_handler = CurriedProgram {
2323
program: debug_game_handler.clone(),
2424
args: clvm_curried_args!(
25-
game_handler_mod_hash,
26-
debug_game_handler,
27-
amount.clone(),
28-
true,
29-
((), (aggsig, ())) // slash info
25+
(game_handler_mod_hash,
26+
(debug_game_handler,
27+
(amount.clone(),
28+
(true,
29+
(((), (aggsig, ())), ()) // slash info
30+
)
31+
)
32+
)
33+
)
3034
),
3135
};
3236
GameHandler::my_driver_from_nodeptr(
@@ -70,6 +74,7 @@ fn test_referee_smoke() {
7074
1,
7175
)
7276
.expect("should construct");
77+
referee.enable_debug_run(true);
7378
let readable_move = assemble(allocator.allocator(), "(0 . 0)").expect("should assemble");
7479
let my_move_result = referee
7580
.my_turn_make_move(
@@ -87,6 +92,7 @@ fn test_referee_smoke() {
8792
100,
8893
&Amount::default(),
8994
);
95+
eprintln!("their move result {their_move_result:?}");
9096
if let Err(Error::StrErr(s)) = their_move_result {
9197
assert!(s.contains("slash"));
9298
assert!(s.contains("off chain"));

0 commit comments

Comments
 (0)