From 26c3893eea6f627e21e554be3f84d30761b0a467 Mon Sep 17 00:00:00 2001 From: Alistair Date: Wed, 18 Oct 2023 18:13:40 +0100 Subject: [PATCH] Cli: Encode `bridge_address` as KT1 address as opposed to a tz4 address --- Cargo.lock | 112 +++++++++++++++++++++++++++++++-- jstz_cli/Cargo.toml | 1 + jstz_cli/src/sandbox/daemon.rs | 66 ++++++++++--------- 3 files changed, 146 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b5721443a..c01703f6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,6 +130,15 @@ dependencies = [ "serde", ] +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + [[package]] name = "bit-vec" version = "0.6.3" @@ -802,6 +811,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.2.10" @@ -810,7 +830,7 @@ checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -1163,6 +1183,7 @@ dependencies = [ "tezos-smart-rollup", "tezos-smart-rollup-installer-config", "tezos-smart-rollup-mock", + "tezos_crypto_rs", ] [[package]] @@ -1174,7 +1195,7 @@ dependencies = [ "boa_gc", "derive_more", "erased-serde", - "getrandom", + "getrandom 0.2.10", "serde", "tezos-smart-rollup-host", ] @@ -1238,6 +1259,12 @@ version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "libsecp256k1" version = "0.7.1" @@ -1252,6 +1279,7 @@ dependencies = [ "libsecp256k1-gen-genmult", "rand 0.8.5", "serde", + "sha2 0.9.9", ] [[package]] @@ -1391,6 +1419,7 @@ dependencies = [ "autocfg", "num-integer", "num-traits", + "rand 0.7.3", "serde", ] @@ -1423,6 +1452,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -1614,6 +1644,32 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "proptest" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e35c06b98bf36aba164cc17cb25f7e232f5c4aeea73baa14b8a9f0d92dbfa65" +dependencies = [ + "bit-set", + "bitflags 1.3.2", + "byteorder", + "lazy_static", + "num-traits", + "rand 0.8.5", + "rand_chacha 0.3.1", + "rand_xorshift", + "regex-syntax 0.6.29", + "rusty-fork", + "tempfile", + "unarray", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.33" @@ -1645,6 +1701,8 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ + "getrandom 0.1.16", + "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", "rand_hc", @@ -1686,6 +1744,9 @@ name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] [[package]] name = "rand_core" @@ -1693,7 +1754,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.10", ] [[package]] @@ -1705,6 +1766,15 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core 0.6.4", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -1729,7 +1799,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom", + "getrandom 0.2.10", "redox_syscall 0.2.16", "thiserror", ] @@ -1807,6 +1877,18 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + [[package]] name = "rustyline" version = "10.1.1" @@ -2226,6 +2308,7 @@ dependencies = [ "num-bigint 0.3.3", "num-traits", "p256", + "proptest", "rand 0.7.3", "serde", "strum", @@ -2379,6 +2462,12 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + [[package]] name = "unicode-bidi" version = "0.3.13" @@ -2459,6 +2548,21 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/jstz_cli/Cargo.toml b/jstz_cli/Cargo.toml index a5e48581c..03d40c0ef 100644 --- a/jstz_cli/Cargo.toml +++ b/jstz_cli/Cargo.toml @@ -32,6 +32,7 @@ tezos-smart-rollup = "0.2.1" tezos-smart-rollup-mock = "0.2.1" tezos-smart-rollup-installer-config = "0.2.1" serde_yaml = "0.8" +tezos_crypto_rs = "0.5.1" [[bin]] name = "jstz" diff --git a/jstz_cli/src/sandbox/daemon.rs b/jstz_cli/src/sandbox/daemon.rs index 49d11c61b..ddabe5b7d 100644 --- a/jstz_cli/src/sandbox/daemon.rs +++ b/jstz_cli/src/sandbox/daemon.rs @@ -10,10 +10,10 @@ use std::{ use anyhow::Result; use fs_extra::dir::CopyOptions; use jstz_core::kv::value::serialize; -use jstz_crypto::public_key_hash::PublicKeyHash; use nix::libc::{SIGINT, SIGTERM}; use signal_hook::iterator::Signals; use tempfile::TempDir; +use tezos_crypto_rs::hash::ContractKt1Hash; use tezos_smart_rollup_installer_config::yaml::{Instr, SetArgs, YamlConfig}; use crate::{ @@ -179,13 +179,11 @@ fn start_rollup_node(cfg: &Config) -> Result { fn smart_rollup_installer(cfg: &Config, bridge_address: &str) -> Result<()> { //Convert address - let address_encoding = - serialize(&PublicKeyHash::from_base58(&bridge_address).unwrap()); - let hex_address = hex::encode(address_encoding.clone()); + let bridge_address = ContractKt1Hash::from_base58_check(bridge_address)?; let instructions = YamlConfig { instructions: vec![Instr::Set(SetArgs { - value: hex_address.clone(), + value: hex::encode(serialize(&bridge_address)), to: "/ticketer".to_owned(), })], }; @@ -199,29 +197,39 @@ fn smart_rollup_installer(cfg: &Config, bridge_address: &str) -> Result<()> { let setup_file_path = temp_file.path().to_owned(); // Create an installer kernel - let _output = Command::new("smart-rollup-installer") - .args(&[ - "get-reveal-installer", - "--setup-file", - &setup_file_path.to_str().expect("Invalid path"), - "--output", - cfg.jstz_path - .join("target/kernel/jstz_kernel_installer.hex") - .to_str() - .expect("Invalid path"), - "--preimages-dir", - &cfg.jstz_path - .join("target/kernel") - .join("preimages/") - .to_str() - .expect("Invalid path"), - "--upgrade-to", - &cfg.jstz_path - .join("target/wasm32-unknown-unknown/release/jstz_kernel.wasm") - .to_str() - .expect("Invalid path"), - ]) - .output(); + let mut installer_command = Command::new("smart-rollup-installer"); + + installer_command.args(&[ + "get-reveal-installer", + "--setup-file", + &setup_file_path.to_str().expect("Invalid path"), + "--output", + cfg.jstz_path + .join("target/kernel/jstz_kernel_installer.hex") + .to_str() + .expect("Invalid path"), + "--preimages-dir", + &cfg.jstz_path + .join("target/kernel") + .join("preimages/") + .to_str() + .expect("Invalid path"), + "--upgrade-to", + &cfg.jstz_path + .join("target/wasm32-unknown-unknown/release/jstz_kernel.wasm") + .to_str() + .expect("Invalid path"), + ]); + + let installer_output = installer_command.output()?; + + if !installer_output.status.success() { + return Err(anyhow::anyhow!( + "Command {:?} failed:\n {}", + installer_command, + String::from_utf8_lossy(&installer_output.stderr) + )); + } Ok(()) } @@ -409,7 +417,7 @@ pub fn main(cfg: &mut Config) -> Result<()> { cfg.save()?; // 4. Wait for the sandbox to shutdown (either by the user or by an error) - OctezThread::join(vec![rollup_node, baker, node])?; + OctezThread::join(vec![baker, rollup_node, node])?; cfg.sandbox = None; cfg.save()?;