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
Prev Previous commit
Next Next commit
Referee maker interface
  • Loading branch information
prozacchiwawa committed Apr 27, 2024
commit f7e945fd41dec0a31e02a8c5486c8079ea0ac37c
117 changes: 91 additions & 26 deletions src/channel_handler/types.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ use rand::prelude::*;
use rand::distributions::Standard;
use clvmr::allocator::Allocator;

use crate::common::types::{Amount, CoinString, PrivateKey, PublicKey, Aggsig, GameID, RefereeID, Puzzle, PuzzleHash, Error, GameHandler, Timeout, ClvmObject, Hash};
use crate::common::types::{Amount, CoinString, PrivateKey, PublicKey, Aggsig, GameID, RefereeID, Program, Puzzle, PuzzleHash, Error, GameHandler, Timeout, ClvmObject, Hash};

#[derive(Default)]
pub struct ChannelHandlerPrivateKeys {
@@ -58,30 +58,6 @@ pub struct ReadableMove(ClvmObject);

pub struct ReadableUX(ClvmObject);

/// A channel handler runs the game by facilitating the phases of game startup
/// and passing on move information as well as termination to other layers.
#[derive(Default)]
pub struct ChannelHandler {
private_keys: ChannelHandlerPrivateKeys,

their_channel_coin_public_key: PublicKey,
their_unroll_coin_public_key: PublicKey,
their_referee_puzzle_hash: PuzzleHash,
state_channel_coin_string: Option<CoinString>,
my_out_of_game_balance: Amount,
their_out_of_game_balance: Amount,
have_potato: bool,
current_state_number: usize,
next_nonce_number: usize,

last_channel_aggsig: Aggsig,
last_unroll_aggsig: Aggsig,
game_id_of_most_recent_move: Option<GameID>,
game_id_of_most_recent_created_game: Option<GameID>,
game_id_of_most_recent_accepted_game: Option<GameID>,
referee_of_most_recent_accepted_game: Option<RefereeID>,
}

pub struct MoveResult {
signatures: PotatoSignatures,
move_peer: Vec<u8>,
@@ -106,7 +82,7 @@ pub struct SpentResult {
pub struct OnChainGameCoin<'a> {
game_id_up: GameID,
coin_string_up: CoinString,
referee_up: &'a RefereeMaker
referee_up: &'a mut RefereeMaker
}

pub struct SpendRewardResult {
@@ -123,6 +99,30 @@ pub struct CoinSpentResult<'a> {
game_id_of_accept_up: GameID
}

/// A channel handler runs the game by facilitating the phases of game startup
/// and passing on move information as well as termination to other layers.
#[derive(Default)]
pub struct ChannelHandler {
private_keys: ChannelHandlerPrivateKeys,

their_channel_coin_public_key: PublicKey,
their_unroll_coin_public_key: PublicKey,
their_referee_puzzle_hash: PuzzleHash,
state_channel_coin_string: Option<CoinString>,
my_out_of_game_balance: Amount,
their_out_of_game_balance: Amount,
have_potato: bool,
current_state_number: usize,
next_nonce_number: usize,

last_channel_aggsig: Aggsig,
last_unroll_aggsig: Aggsig,
game_id_of_most_recent_move: Option<GameID>,
game_id_of_most_recent_created_game: Option<GameID>,
game_id_of_most_recent_accepted_game: Option<GameID>,
referee_of_most_recent_accepted_game: Option<RefereeID>,
}

impl ChannelHandler {
pub fn new(private_keys: ChannelHandlerPrivateKeys) -> Self {
ChannelHandler {
@@ -211,5 +211,70 @@ impl ChannelHandler {
}
}

pub struct RefereeMakerMoveResult {
puzzle_hash_for_unroll: PuzzleHash,
move_made: Vec<u8>,
validation_info_hash: Hash,
max_move_size: usize,
mover_share: Amount
}

pub struct TheirTurnMoveResult {
puzzle_hash_for_unroll: PuzzleHash,
readable_move: ClvmObject,
message: ClvmObject
}

pub enum TheirTurnCoinSpentResult {
Timedout {
my_reward_coin_string: CoinString
},
Moved {
new_coin_string: CoinString,
readable: ClvmObject
},
Slash {
new_coin_string: CoinString,
puzzle_reveal: Puzzle,
solution: ClvmObject,
aggsig: Aggsig,
my_reward_coin_string: CoinString
}
}

pub struct RefereeMaker {
}

impl RefereeMaker {
pub fn new(allocator: &mut Allocator, amount: Amount, game_handler: Program, is_my_turn: bool, timeout: Timeout, validation_puzzle: Puzzle, validation_puzzle_hash: PuzzleHash, initial_state: ClvmObject, initial_move: &[u8], initial_move_max_size: usize, initial_mover_share: Amount, my_private_key: PrivateKey, their_puzzle_hash: PuzzleHash, nonce: usize) -> Self {
todo!();
}

pub fn get_initial_puzzle_hash(&self) -> PuzzleHash {
todo!();
}

pub fn my_turn_make_move(&mut self, allocator: &mut Allocator, readable_move: &ClvmObject) -> RefereeMakerMoveResult {
todo!();
}

pub fn get_transaction_for_move(&mut self, allocator: &mut Allocator, coin_string: &CoinString) -> (TransactionBundle, CoinString) {
todo!();
}

pub fn get_my_share(&self, allocator: &mut Allocator) -> Amount {
todo!();
}

pub fn get_timeout_transaction(&self, allocator: &mut Allocator) -> (TransactionBundle, CoinString) {
todo!();
}

pub fn their_turn_move_off_chain(&mut self, allocator: &mut Allocator, their_move: &[u8], validation_info_hash: &Hash, max_move_size: usize, mover_share: &Amount) -> TheirTurnMoveResult {
todo!();
}

pub fn their_turn_coin_spent(&mut self, allocator: &mut Allocator, coin_string: &CoinString, conditions: &ClvmObject) -> Result<TheirTurnCoinSpentResult, Error> {
todo!();
}
}
5 changes: 4 additions & 1 deletion src/common/types.rs
Original file line number Diff line number Diff line change
@@ -85,7 +85,10 @@ pub enum Error {
pub struct ClvmObject(NodePtr);

#[derive(Clone)]
pub struct Puzzle(ClvmObject);
pub struct Program(ClvmObject);

#[derive(Clone)]
pub struct Puzzle(Program);

#[derive(Clone)]
pub enum GameHandler {