Skip to content
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

20240426 rust #2

Closed
wants to merge 96 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
a6c0a8f
Updated notes on APIs
bramcohen Apr 9, 2024
7784275
API polish
bramcohen Apr 9, 2024
3fb1b41
API polish
bramcohen Apr 19, 2024
1f1d501
API cleanup
bramcohen Apr 23, 2024
42a604e
Updated APIs to be in imperative language and fixed some bugs
bramcohen Apr 26, 2024
907ffec
small cleanups
bramcohen Apr 26, 2024
266d085
Basics of crate
prozacchiwawa Apr 26, 2024
f6a5836
New rust code
prozacchiwawa Apr 26, 2024
15b84d9
Merge up
prozacchiwawa Apr 26, 2024
92dedc6
Rust interface compiling
prozacchiwawa Apr 27, 2024
f7e945f
Referee maker interface
prozacchiwawa Apr 27, 2024
2323b5a
Add standard coin and some infra
prozacchiwawa Apr 29, 2024
c3edfd6
Add standard coin handling
prozacchiwawa Apr 29, 2024
f59d26f
Working standard puzzle function puzzle_for_pk
prozacchiwawa Apr 30, 2024
f739aff
Working standard puzzle function puzzle_for_pk
prozacchiwawa Apr 30, 2024
768bb89
Cleaning
prozacchiwawa Apr 30, 2024
21d7b54
Add some standard coin and signature functionality
prozacchiwawa Apr 30, 2024
9c402ab
Puzzle hash infra
prozacchiwawa Apr 30, 2024
57d667c
Add a basic construction smoke test for channel handler
prozacchiwawa Apr 30, 2024
6b55187
Add tests
prozacchiwawa Apr 30, 2024
9a63cbe
All compiling
prozacchiwawa May 1, 2024
cc69e39
Added files
prozacchiwawa May 1, 2024
47b81b1
Add a test of bram style partial signatures
prozacchiwawa May 2, 2024
b7765a3
Remove ClvmObject, add implementations from richard's code. We still …
prozacchiwawa May 2, 2024
4a21dbe
More tests, I have good confidence in the signing stuff and more test…
prozacchiwawa May 2, 2024
8befe39
Add signature verification at the end
prozacchiwawa May 2, 2024
1a18432
not needed
prozacchiwawa May 2, 2024
d41b536
Some cleaning
prozacchiwawa May 2, 2024
089fcb8
Continue filling things out, make the test env nicer
prozacchiwawa May 2, 2024
ceb52b4
Better factoring
prozacchiwawa May 2, 2024
68ee977
Small type rearrangement
prozacchiwawa May 2, 2024
d45b01b
Minor correction to coin parsing
prozacchiwawa May 2, 2024
d526589
Passing so far with clean shutdown
prozacchiwawa May 2, 2024
7c765e0
Some renaming
prozacchiwawa May 2, 2024
f4a012e
Add a structure that holds byte and hash references and describes has…
prozacchiwawa May 3, 2024
6720a3d
Some paring down
prozacchiwawa May 3, 2024
c9b7454
A bit more cutting
prozacchiwawa May 3, 2024
8c4c139
Tests passing so far
prozacchiwawa May 3, 2024
135bced
Add failing test after reconciling
prozacchiwawa May 3, 2024
6c6ead0
Added cache and disposition
prozacchiwawa May 4, 2024
24a3f7a
Add candidate spend_reward_coins
prozacchiwawa May 6, 2024
62ab743
Add send_empty_potato
prozacchiwawa May 6, 2024
8868774
sending potatos
prozacchiwawa May 6, 2024
27c1fa5
Factor out caching new unroll state
prozacchiwawa May 6, 2024
cc006a4
Potato accept
prozacchiwawa May 7, 2024
9c7c416
Channel handler no todos
prozacchiwawa May 7, 2024
0d0e98c
Give potato on potato send
prozacchiwawa May 7, 2024
31fc2ed
Add a way of running the simulator so we can do test with coins
prozacchiwawa May 7, 2024
4692e3d
Feature gate python based tests
prozacchiwawa May 7, 2024
e6461f5
drop trait
prozacchiwawa May 7, 2024
f63cd4b
Commit up
prozacchiwawa May 7, 2024
de4839e
Have a pair of states
prozacchiwawa May 8, 2024
05926e1
WIP: not building yet
prozacchiwawa May 8, 2024
882829c
All building
prozacchiwawa May 8, 2024
8ebd475
New files
prozacchiwawa May 8, 2024
e2469f0
WIP Semantically complete, need to make it all compile
prozacchiwawa May 8, 2024
9ba42d4
Building
prozacchiwawa May 9, 2024
6fdfab3
Games called
prozacchiwawa May 9, 2024
8485281
Add first test: call their turn handler
prozacchiwawa May 9, 2024
6b3c439
Data parsing from make move
prozacchiwawa May 9, 2024
06b8f0b
Document my turn handler
prozacchiwawa May 9, 2024
36b33ff
Add game handler tests
prozacchiwawa May 9, 2024
36b7931
Add test data: the debug game
prozacchiwawa May 9, 2024
b7063fc
WIP failing test
prozacchiwawa May 9, 2024
3841d89
Quiet some clippy traffic (need investigation)
prozacchiwawa May 9, 2024
f6f6798
One passing test
prozacchiwawa May 9, 2024
e2a6bcf
More code running
prozacchiwawa May 9, 2024
cd51531
Add basic ci
prozacchiwawa May 9, 2024
d96e67a
fmt
prozacchiwawa May 9, 2024
6951054
Run tests with chia-blockchain installed so we can access the simulator
prozacchiwawa May 9, 2024
973e1f9
Some clippy traffic, update the debug game a bit
prozacchiwawa May 13, 2024
e51b9c7
Debug game: now just represent share and cheated as bits
prozacchiwawa May 13, 2024
395fa41
Complete those changes, gonna document validation info hash properly …
prozacchiwawa May 13, 2024
ffd637b
Bundle the curried arguments for clarity
prozacchiwawa May 13, 2024
7d30595
Move some things for clarity
prozacchiwawa May 15, 2024
606b915
Should be strictly better. Allow us to use the debug game program pr…
prozacchiwawa May 15, 2024
bbb80b2
Add my rewritten referee code which has a bit more structure
prozacchiwawa May 15, 2024
f8ab642
Comment
prozacchiwawa May 15, 2024
9c5ebb7
Check move reciprocity
prozacchiwawa May 15, 2024
609ce75
Add max into std
prozacchiwawa May 16, 2024
5ee36dc
Big refactoring: introduce ChiaIdentity and GameMoveDetails
prozacchiwawa May 17, 2024
8bd8677
Document how to run the validator.
prozacchiwawa May 17, 2024
9031552
WIP, interim updates, starting to construct TransactionBundle for sim…
prozacchiwawa May 20, 2024
b1979e8
We can make a CoinSpend
prozacchiwawa May 20, 2024
f943ed9
Added plumbing for coin spends
prozacchiwawa May 20, 2024
253338e
Add a bunch of verification tests with data lifted from python
prozacchiwawa May 21, 2024
26e45a3
A mess but we're properly connected to the simulator
prozacchiwawa May 21, 2024
117cc7d
Move synthetic keys into identity
prozacchiwawa May 21, 2024
28f7eb7
Ensure complete shutdown in all circumstances
prozacchiwawa May 21, 2024
b5b181b
All partial signatures
prozacchiwawa May 21, 2024
44f18b3
Move referee construction into RefereeTest
prozacchiwawa May 21, 2024
458b669
Start using referee test elsewhere
prozacchiwawa May 21, 2024
c90acf9
Give evidence a distinct type based on how it's used in the onchain r…
prozacchiwawa May 22, 2024
d6956bb
Plumbing for on chain referee solutions
prozacchiwawa May 22, 2024
79216ed
WIP getting timeout spend. We're correctly calling the function to g…
prozacchiwawa May 22, 2024
f61a74e
We're creating a spend that gets to signature checking
prozacchiwawa May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 55 additions & 30 deletions resources/debug_game_handler.clsp
Original file line number Diff line number Diff line change
@@ -15,53 +15,78 @@
(import std.curry)
(import std.map)
(import std.shatree)
(import std.condition_codes)

(defmac CURRIED ()
(q . (@ CURRIED
(MOD_HASH
PUZZLE
TIMEOUT
AMOUNT
MY_TURN
SLASH_INFO
MOVER_PUZZLE_HASH
)
)
)
)

(defun-inline curried_mod_hash ((CURRIED)) MOD_HASH)
(defun-inline curried_puzzle ((CURRIED)) PUZZLE)
(defun-inline curried_timeout ((CURRIED)) TIMEOUT)
(defun-inline curried_amount ((CURRIED)) AMOUNT)
(defun-inline curried_my_turn ((CURRIED)) MY_TURN)
(defun-inline curried_slash_info ((CURRIED)) SLASH_INFO)
(defun-inline curried_mover_puzzle_hash ((CURRIED)) MOVER_PUZZLE_HASH)

(defun-inline curried_mod_hash (CURRIED) (f CURRIED))
(defun-inline curried_puzzle (CURRIED) (f (r CURRIED)))
(defun-inline curried_amount (CURRIED) (f (r (r CURRIED))))
(defun-inline curried_my_turn (CURRIED) (f (r (r (r CURRIED)))))
(defun-inline curried_slash_info (CURRIED) (f (r (r (r (r CURRIED))))))
(defun-inline curried_other_turn (CURRIED)
(defun-inline curried_other_turn ((CURRIED))
(list
(curried_mod_hash CURRIED)
(curried_puzzle CURRIED)
(curried_amount CURRIED)
(not (curried_my_turn CURRIED))
(curried_slash_info CURRIED)
)
MOD_HASH
PUZZLE
TIMEOUT
AMOUNT
(not MY_TURN)
SLASH_INFO
MOVER_PUZZLE_HASH
)
)

(defun get-validation-move
(MOVER_PUZZLE_HASH
WAITER_PUZZLE_HASH
TIMEOUT
AMOUNT
MOD_HASH
NONCE
MOVE
MAX_MOVE_SIZE
VALIDATION_INFO_HASH
MOVER_SHARE
PREVIOUS_VALIDATION_INFO_HASH
(defmac move-validation-info ()
(q . (@ move-validation-info
(new_move
new_validation_info_hash
new_mover_share
new_max_move_size
mover_puzzle
solution)
)
)
MOVE
)

(defun get-validation-move ((move-validation-info)) new_move)
(defun get-validation-mover-puzzle ((move-validation-info)) mover_puzzle)
(defun get-validation-solution ((move-validation-info)) solution)
(defun get-validation-game-move ((move-validation-info))
(list new_move new_validation_info_hash new_mover_share new_max_move_size)
)

(defun get-move-share (new-move)
(ash new-move -1)
)

(defun validation_program (CURRIED validation-data)
(defun validation_program ((CURRIED) . validation-data)
(assign

cheated (logand (get-validation-move validation-data) 1)

(if cheated
(x "validation program cheating" validation-data)
()
)
)
)

(defun do_my_turn (CURRIED readable_new_move amount state entropy)
(defun do_my_turn ((CURRIED) readable_new_move amount state entropy)
(assign

;; Readable move is a clvm structure that describes the move
@@ -88,7 +113,7 @@

(list
new_state
validation_program
(curry validation_program CURRIED)
new_validation_program_hash
(c set_share set_cheated)
100
@@ -99,7 +124,7 @@
)
)

(defun do_their_turn (CURRIED amount last_state new_move new_validation_info_hash new_max_move_size new_mover_share)
(defun do_their_turn ((CURRIED) amount last_state new_move new_validation_info_hash new_max_move_size new_mover_share)
(assign
set_cheated (logand new_move 1)
other_turn (curried_other_turn CURRIED)
@@ -117,7 +142,7 @@
)

(export
(CURRIED . args)
((CURRIED) . args)
(if
;; Validation personality
(if (not (l (f args))) (= 1337 (f args)) ())
2 changes: 1 addition & 1 deletion resources/debug_game_handler.hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ff02ffff01ff02ffff03ffff02ffff03ffff07ff0b80ffff01ff0180ffff01ff09ffff01820539ff0b8080ff0180ffff01ff02ff3effff04ff02ffff04ff05ff0f808080ffff01ff02ffff03ff5dffff01ff02ff10ffff04ff02ffff04ff05ff07808080ffff01ff02ff14ffff04ff02ffff04ff05ff0780808080ff018080ff0180ffff04ffff01ffffffff02ff28ffff04ff02ffff04ff03ffff04ff0bffff04ff0bffff04ffff02ff2effff04ff02ffff04ff2fff80808080ffff04ffff04ff09ffff04ff15ffff04ff2dffff04ffff20ff5d80ffff04ff8200bdff808080808080ff8080808080808080ffff02ff38ffff04ff02ffff04ff03ffff04ffff02ff26ffff04ff02ffff04ff82009fffff04ffff02ff2effff04ff02ffff04ff5fff80808080ff8080808080ffff04ffff19ffff18ffff0101ff1b80ffff16ff13ffff01018080ff808080808080ff04ff17ffff04ffff04ffff0102ffff04ffff04ffff0101ff3e80ffff04ffff04ffff0104ffff04ffff04ffff0101ff0280ffff04ffff0101ff80808080ff80808080ffff04ffff0bff0bffff02ff2effff04ff02ffff04ff17ff8080808080ffff04ffff04ff25ff3580ffff04ffff0164ffff04ff25ffff04ffff02ff3affff04ff02ffff04ff51ffff04ff8200bdff8080808080ffff04ff80ff808080808080808080ffff02ffff03ffff18ff2fffff010180ffff01ff04ffff0102ff8200bd80ffff01ff04ff80ffff04ffff04ffff18ff2fffff010180ffff02ff2cffff04ff02ffff04ff2fff8080808080ffff04ffff02ff3affff04ff02ffff04ff15ffff04ffff04ff09ffff04ff15ffff04ff2dffff04ffff20ff5d80ffff04ff8200bdff808080808080ff8080808080ffff04ffff018c6d6573736167652064617461ff808080808080ff0180ffff16ff05ffff0181ff8082017fffffff02ffff03ff05ffff01ff04ffff0104ffff04ffff04ffff0101ff0980ffff04ffff02ff12ffff04ff02ffff04ff0dff80808080ff80808080ffff01ff010180ff0180ffff02ffff03ff05ffff01ff0bffff06ffff06ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c58080ffff02ff36ffff04ff02ffff04ff09ffff04ffff02ff2affff04ff02ffff04ff0dff80808080ff808080808080ffff01ff06ffff05ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c5808080ff0180ff04ffff0102ffff04ffff04ffff0101ff0580ffff04ffff02ff12ffff04ff02ffff04ff07ff80808080ff80808080ffffff0bffff05ffff06ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c58080ffff02ff36ffff04ff02ffff04ff05ffff04ffff02ff2affff04ff02ffff04ff07ff80808080ff808080808080ff0bffff0102ffff0bffff0102ffff06ffff05ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c58080ff0580ffff0bffff0102ff0bffff05ffff05ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c580808080ffff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff2effff04ff02ffff04ff09ff80808080ffff02ff2effff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff02ffff03ffff18ffff02ff3cffff04ff02ffff04ff0bff80808080ffff010180ffff01ff08ffff019b76616c69646174696f6e2070726f6772616d206368656174696e67ff0b80ffff01ff018080ff0180ff018080
ff02ffff01ff02ffff03ffff02ffff03ffff07ff0b80ffff01ff0180ffff01ff09ffff01820539ff0b8080ff0180ffff01ff02ff3effff04ff02ffff04ff05ff0f808080ffff01ff02ffff03ff8200bdffff01ff02ff10ffff04ff02ffff04ff05ff07808080ffff01ff02ff14ffff04ff02ffff04ff05ff0780808080ff018080ff0180ffff04ffff01ffffffff02ff28ffff04ff02ffff04ff03ffff04ff0bffff04ff0bffff04ffff02ff2effff04ff02ffff04ff2fff80808080ffff04ffff04ff09ffff04ff15ffff04ff2dffff04ff5dffff04ffff20ff8200bd80ffff04ff82017dffff04ff8202fdff8080808080808080ff8080808080808080ffff02ff38ffff04ff02ffff04ff03ffff04ffff02ff26ffff04ff02ffff04ff82009fffff04ffff02ff2effff04ff02ffff04ff5fff80808080ff8080808080ffff04ffff19ffff18ffff0101ff1b80ffff16ff13ffff01018080ff808080808080ff04ff17ffff04ffff02ff3affff04ff02ffff04ffff04ffff0102ffff04ffff04ffff0101ff3e80ffff04ffff04ffff0104ffff04ffff04ffff0101ff0280ffff04ffff0101ff80808080ff80808080ffff04ff11ff8080808080ffff04ffff0bff0bffff02ff2effff04ff02ffff04ff17ff8080808080ffff04ffff04ff25ff3580ffff04ffff0164ffff04ff25ffff04ffff02ff3affff04ff02ffff04ff51ffff04ff8200bdff8080808080ffff04ff80ff808080808080808080ffff02ffff03ffff18ff2fffff010180ffff01ff04ffff0102ff82017d80ffff01ff04ff80ffff04ffff04ffff18ff2fffff010180ffff02ff2cffff04ff02ffff04ff2fff8080808080ffff04ffff02ff3affff04ff02ffff04ff15ffff04ffff04ff09ffff04ff15ffff04ff2dffff04ff5dffff04ffff20ff8200bd80ffff04ff82017dffff04ff8202fdff8080808080808080ff8080808080ffff04ffff018c6d6573736167652064617461ff808080808080ff0180ffff16ff05ffff0181ff8009ffffff02ffff03ff05ffff01ff04ffff0104ffff04ffff04ffff0101ff0980ffff04ffff02ff12ffff04ff02ffff04ff0dff80808080ff80808080ffff01ff010180ff0180ffff02ffff03ff05ffff01ff0bffff06ffff06ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c58080ffff02ff36ffff04ff02ffff04ff09ffff04ffff02ff2affff04ff02ffff04ff0dff80808080ff808080808080ffff01ff06ffff05ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c5808080ff0180ff04ffff0102ffff04ffff04ffff0101ff0580ffff04ffff02ff12ffff04ff02ffff04ff07ff80808080ff80808080ffffff0bffff05ffff06ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c58080ffff02ff36ffff04ff02ffff04ff05ffff04ffff02ff2affff04ff02ffff04ff07ff80808080ff808080808080ff0bffff0102ffff0bffff0102ffff06ffff05ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c58080ff0580ffff0bffff0102ff0bffff05ffff05ffff01ffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c580808080ffff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff2effff04ff02ffff04ff09ff80808080ffff02ff2effff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff02ffff03ffff18ffff02ff3cffff04ff02ffff04ff07ff80808080ffff010180ffff01ff08ffff019b76616c69646174696f6e2070726f6772616d206368656174696e67ff0780ffff01ff018080ff0180ff018080
150 changes: 73 additions & 77 deletions src/referee.rs
Original file line number Diff line number Diff line change
@@ -182,25 +182,22 @@ fn curry_referee_puzzle_hash(
/// Mover puzzle is a wallet puzzle for an ordinary value coin and the solution
/// is next to it.
///
pub struct ValidatorMoveArgs<'a> {
pub new_move: &'a [u8],
pub new_validation_info_hash: Hash,
pub new_mover_share: Amount,
pub new_max_move_size: usize,
pub struct ValidatorMoveArgs {
pub game_move: GameMoveDetails,
pub mover_puzzle: Program,
pub solution: NodePtr
}

impl<'a> ValidatorMoveArgs<'a> {
impl ValidatorMoveArgs {
pub fn to_nodeptr(
&self,
allocator: &mut AllocEncoder
) -> Result<NodePtr, Error> {
let args: &[NodePtr] = &[
allocator.encode_atom(self.new_move).into_gen()?,
self.new_validation_info_hash.to_clvm(allocator).into_gen()?,
self.new_mover_share.to_clvm(allocator).into_gen()?,
self.new_max_move_size.to_clvm(allocator).into_gen()?,
allocator.encode_atom(&self.game_move.move_made).into_gen()?,
self.game_move.validation_info_hash.to_clvm(allocator).into_gen()?,
self.game_move.mover_share.to_clvm(allocator).into_gen()?,
self.game_move.max_move_size.to_clvm(allocator).into_gen()?,
self.mover_puzzle.to_clvm(allocator).into_gen()?,
self.solution
];
@@ -216,10 +213,12 @@ struct RefereeMakerGameState {
pub state: NodePtr,
pub validation_program: NodePtr,
pub game_handler: GameHandler,
pub previous_state: NodePtr,

// Details of the move that triggered this state change
pub game_move: GameMoveDetails,

pub previous_state: NodePtr,

// Ensure we copy this when we update RefereeMaker::current_state
pub previous_validation_program_hash: Hash,
}
@@ -479,19 +478,15 @@ impl RefereeMaker {
// Agg sig me on the solution of the referee_coin_puzzle.
// When it invokes the validation program, it passes through args as the full
// argument set.
pub fn curry_referee_puzzle(
fn curry_referee_puzzle(
&self,
allocator: &mut AllocEncoder,
coin_string: &CoinString,
curried_args: &RefereePuzzleArgs,
// args from referee.clsp
args: Option<NodePtr>,
agg_sig_additional_data: &Hash,
) -> Result<TransactionBundle, Error> {
let public_key = private_to_public_key(&self.my_identity.private_key);
let my_referee_puzzle = puzzle_for_pk(allocator, &public_key)?;
let puzzle = CurriedProgram {
program: my_referee_puzzle.clone(),
) -> Result<Puzzle, Error> {
Ok(Puzzle::from_nodeptr(CurriedProgram {
program: self.my_identity.puzzle.clone(),
args: clvm_curried_args!(
curried_args.mover_puzzle_hash.clone(),
curried_args.waiter_puzzle_hash.clone(),
@@ -507,22 +502,45 @@ impl RefereeMaker {
),
}
.to_clvm(allocator)
.into_gen()?;
let solution = args.unwrap_or_else(|| allocator.allocator().null());
let solution_hash = Node(solution).sha256tree(allocator);

let signature = sign_agg_sig_me(
&self.my_identity.private_key,
&solution_hash.bytes(),
&coin_string.to_coin_id(),
agg_sig_additional_data,
);
.into_gen()?))
}

Ok(TransactionBundle {
puzzle: Puzzle::from_nodeptr(puzzle),
solution,
signature,
})
pub fn curried_referee_puzzle_for_validator(
&self,
allocator: &mut AllocEncoder,
args: Option<NodePtr>,
) -> Result<Puzzle, Error> {
let current_state = self.current_state();
let my_turn =
matches!(current_state.game_handler, GameHandler::MyTurnHandler(_));
let mover_puzzle_hash = if my_turn {
self.my_identity.puzzle_hash.clone()
} else {
self.their_referee_puzzle_hash.clone()
};
let waiter_puzzle_hash = if my_turn {
self.their_referee_puzzle_hash.clone()
} else {
self.my_identity.puzzle_hash.clone()
};

self.curry_referee_puzzle(
allocator,
&RefereePuzzleArgs {
mover_puzzle_hash,
waiter_puzzle_hash,
timeout: self.timeout.clone(),
amount: self.amount.clone(),
referee_coin_puzzle_hash: self.referee_coin_puzzle_hash.clone(),
nonce: self.nonce,

game_move: current_state.game_move.clone(),
previous_validation_info_hash: current_state
.previous_validation_program_hash
.clone(),
},
args,
)
}

// Ensure this returns
@@ -571,37 +589,26 @@ impl RefereeMaker {
// XXX do this differently based on args.is_none()
// because that is a move transaction with no reward.
let transaction_bundle = {
let current_state = self.current_state();
let mover_puzzle_hash = if my_turn {
self.my_identity.puzzle_hash.clone()
} else {
self.their_referee_puzzle_hash.clone()
};
let waiter_puzzle_hash = if my_turn {
self.their_referee_puzzle_hash.clone()
} else {
self.my_identity.puzzle_hash.clone()
};

self.curry_referee_puzzle(
let puzzle = self.curried_referee_puzzle_for_validator(
allocator,
coin_string,
&RefereePuzzleArgs {
mover_puzzle_hash,
waiter_puzzle_hash,
timeout: self.timeout.clone(),
amount: self.amount.clone(),
referee_coin_puzzle_hash: self.referee_coin_puzzle_hash.clone(),
nonce: self.nonce,
args
)?;

game_move: current_state.game_move.clone(),
previous_validation_info_hash: current_state
.previous_validation_program_hash
.clone(),
},
args,
let solution = args.unwrap_or_else(|| allocator.allocator().null());
let solution_hash = Node(solution).sha256tree(allocator);

let signature = sign_agg_sig_me(
&self.my_identity.private_key,
&solution_hash.bytes(),
&coin_string.to_coin_id(),
agg_sig_me_additional_data,
)?
);

TransactionBundle {
puzzle,
solution,
signature,
}
};

let output_coin_string = CoinString::from_parts(
@@ -805,19 +812,11 @@ impl RefereeMaker {
Ok(())
}

pub fn curried_referee_coin_puzzle_hash(
&mut self,
allocator: &mut AllocEncoder,
validator_move_args: &ValidatorMoveArgs,
) -> Result<PuzzleHash, Error> {
todo!();
}

pub fn run_validator_for_their_move(
&mut self,
allocator: &mut AllocEncoder,
validator_move_args: &ValidatorMoveArgs
) -> Result<Option<SlashOutcome>, Error> {
) -> Result<(), Error> {
let validation_program = self.current_state().validation_program;
let validator_move_converted = validator_move_args.to_nodeptr(allocator)?;
let ran_validator =
@@ -828,8 +827,7 @@ impl RefereeMaker {
validator_move_converted,
0
).into_gen()?.1;
eprintln!("ran_validator {}", disassemble(allocator.allocator(), ran_validator, None));
todo!();
Ok(())
}

pub fn their_turn_move_off_chain(
@@ -1058,10 +1056,8 @@ impl RefereeMaker {
};
let new_puzzle = self.curry_referee_puzzle(
allocator,
coin_string,
&ref_puzzle_args,
None,
agg_sig_me_additional_data,
)?;
let new_puzzle_hash =
curry_referee_puzzle_hash(allocator, &self.referee_coin_puzzle_hash, &ref_puzzle_args)?;
@@ -1144,7 +1140,7 @@ impl RefereeMaker {
self.make_slash_for_their_turn(
allocator,
coin_string,
&new_puzzle.puzzle,
&new_puzzle,
&new_puzzle_hash,
full_slash_solution,
slash_solution,
@@ -1175,7 +1171,7 @@ impl RefereeMaker {
TheirTurnResult::Slash(solution, sig) => self.make_slash_for_their_turn(
allocator,
coin_string,
&new_puzzle.puzzle,
&new_puzzle,
&new_puzzle_hash,
full_slash_solution,
solution,
Loading