Skip to content

Commit

Permalink
Update to risc0/risc0 0.10 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
intoverflow authored Jun 25, 2022
1 parent 3807551 commit 91a9640
Show file tree
Hide file tree
Showing 12 changed files with 3,455 additions and 246 deletions.
748 changes: 724 additions & 24 deletions Cargo.lock

Large diffs are not rendered by default.

1,359 changes: 1,329 additions & 30 deletions contract/Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ bincode = "1.3"
battleship-core = { path = "../core" }
battleship-methods = { path = "../methods" }
near-sdk = "3.1"
risc0-zkvm-core = "0.9"
risc0-zkvm-serde = "0.9"
risc0-zkvm-verify = "0.9"
risc0-zkvm-core = "0.10"
risc0-zkvm-serde = "0.10"
risc0-zkvm-verify = "0.10"
serde = "1.0"

[profile.release]
Expand Down
8 changes: 4 additions & 4 deletions contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Default for BattleshipContract {
pub fn verify_receipt(str: &String, method_id: &MethodID) -> Vec<u32> {
let as_bytes = base64::decode(str).unwrap();
let receipt = bincode::deserialize::<Receipt>(&as_bytes).unwrap();
receipt.verify(&method_id);
receipt.verify(&method_id).unwrap();
receipt.get_journal_u32()
}

Expand All @@ -90,7 +90,7 @@ impl BattleshipContract {
pub fn new_game(&mut self, name: String, receipt_str: String) -> GameState {
// Game must not exist
assert!(self.games.get(&name).is_none());
let method_id = MethodID::try_from(INIT_ID.as_slice()).unwrap();
let method_id = MethodID::try_from(INIT_ID).unwrap();
let journal = verify_receipt(&receipt_str, &method_id);
let digest = risc0_zkvm_serde::from_slice::<Digest>(&journal).unwrap();
let state = GameState {
Expand Down Expand Up @@ -124,7 +124,7 @@ impl BattleshipContract {
// Set turn to 1
state.next_turn = 1;
// Verify the player has a valid initial state
let method_id = MethodID::try_from(INIT_ID.as_slice()).unwrap();
let method_id = MethodID::try_from(INIT_ID).unwrap();
let journal = verify_receipt(&receipt_str, &method_id);
let digest = risc0_zkvm_serde::from_slice::<Digest>(&journal).unwrap();
// Update player 2 starting state + set shot
Expand Down Expand Up @@ -160,7 +160,7 @@ impl BattleshipContract {
// Verify the right user is playing
assert!(cur_player.id == env::signer_account_id());
// Verify the proof and extract as a RoundCommit
let method_id = MethodID::try_from(TURN_ID.as_slice()).unwrap();
let method_id = MethodID::try_from(TURN_ID).unwrap();
let journal = verify_receipt(&receipt_str, &method_id);
let commit = risc0_zkvm_serde::from_slice::<RoundCommit>(&journal).unwrap();
// Make sure the prior state matches the current state
Expand Down
6 changes: 3 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ version = "0.1.0"
edition = "2021"

[dependencies]
risc0-zkvm-core = { version = "0.9", default-features = false, features = ["pure"] }
risc0-zkvm-core = { version = "0.10", default-features = false, features = ["pure"] }
serde = { version = "1.0", default-features = false }

[dev-dependencies]
battleship-methods = { path = "../methods" }
ctor = "0.1"
env_logger = "0.8"
log = "0.4"
risc0-zkvm-host = "0.9"
risc0-zkvm-serde = "0.9"
risc0-zkvm-host = "0.10"
risc0-zkvm-serde = "0.10"
6 changes: 4 additions & 2 deletions core/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ impl Battleship {
}

pub fn init(&self) -> Result<InitMessage> {
let mut prover = Prover::new(INIT_PATH, INIT_ID)?;
let elf_contents = std::fs::read(INIT_PATH).unwrap();
let mut prover = Prover::new(&elf_contents, INIT_ID)?;
let vec = to_vec(&self.state).unwrap();
prover.add_input(vec.as_slice())?;
let receipt = prover.run()?;
Expand All @@ -91,7 +92,8 @@ impl Battleship {
log::info!("on_turn_msg: {:?}", msg);
let params = RoundParams::new(self.state.clone(), msg.shot.x, msg.shot.y);

let mut prover = Prover::new(TURN_PATH, TURN_ID)?;
let elf_contents = std::fs::read(TURN_PATH).unwrap();
let mut prover = Prover::new(&elf_contents, TURN_ID)?;
let vec = to_vec(&params).unwrap();
prover.add_input(vec.as_slice())?;
let receipt = prover.run()?;
Expand Down
2 changes: 1 addition & 1 deletion methods/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ lto = true
opt-level = "z"

[build-dependencies]
risc0-build = "0.9"
risc0-build = "0.10"
Loading

0 comments on commit 91a9640

Please sign in to comment.