From 31d7dc28c5391015ef157b26fb1fe379416e1e9f Mon Sep 17 00:00:00 2001 From: martoon Date: Wed, 6 Sep 2023 19:08:31 +0300 Subject: [PATCH 1/8] MIR: Add rollup base Add a trivial rollup kernel and infra around it. This includes: 1. Toy `lib.rs` from tutorials. 2. Adding `.cargo/config.toml` with wasm as default target. We always want to build like that because having wasm target affects build - e.g. functionality that includes use of environmental randomness is not possible here for reason (rollup should be deterministic as it is executed on different nodes). 3. At this point you still need to pre-install the wasm toolchain. `rust-toolchain.toml` lifts that necessity, the toolchain is not automatically installed with `cargo build`. 4. Declaring `[lib]` in `Cargo.toml`. I also specified `[[bin]]` section to avoid the resulting name collisions (two `mir` targets). --- contrib/mir/Cargo.lock | 918 +++++++++++++++++++++++++++++++- contrib/mir/Cargo.toml | 8 + contrib/mir/rust-toolchain.toml | 2 + contrib/mir/src/lib.rs | 8 + 4 files changed, 932 insertions(+), 4 deletions(-) create mode 100644 contrib/mir/rust-toolchain.toml create mode 100644 contrib/mir/src/lib.rs diff --git a/contrib/mir/Cargo.lock b/contrib/mir/Cargo.lock index 05000df1a8bd..2f96f32f9eef 100644 --- a/contrib/mir/Cargo.lock +++ b/contrib/mir/Cargo.lock @@ -11,6 +11,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + +[[package]] +name = "arrayref" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" + [[package]] name = "ascii-canvas" version = "3.0.0" @@ -26,6 +38,18 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base58" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "bit-set" version = "0.5.3" @@ -53,6 +77,55 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "blst" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a30d0edd9dd1c60ddb42b80341c7852f6f985279a5c1a83659dcb65899dec99" +dependencies = [ + "cc", + "glob", + "threadpool", + "which", + "zeroize", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "cc" version = "1.0.83" @@ -68,18 +141,117 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cpufeatures" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +dependencies = [ + "libc", +] + [[package]] name = "crunchy" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-bigint" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8658c15c5d921ddf980f7fe25b1e82f4b7a4083b2c4985fea4922edb8e43e07d" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "crypto-mac" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "cryptoxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382ce8820a5bb815055d3553a610e8cb542b2d767bbacea99038afda96cd760d" + +[[package]] +name = "curve25519-dalek" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "platforms", + "rustc_version", + "subtle", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.33", +] + +[[package]] +name = "der" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79b71cca7d95d7681a4b3b9cdf63c8dbc3730d0584c2c74e31416d64a90493f4" + [[package]] name = "diff" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -101,12 +273,68 @@ dependencies = [ "winapi", ] +[[package]] +name = "dlmalloc" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "203540e710bfadb90e5e29930baf5d10270cec1f43ab34f46f78b147b2de715a" +dependencies = [ + "libc", +] + +[[package]] +name = "ecdsa" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43ee23aa5b4f68c7a092b5c3beb25f50c406adc75e2363634f242f28ab255372" +dependencies = [ + "der", + "elliptic-curve", + "hmac", + "signature 1.3.2", +] + +[[package]] +name = "ed25519" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60f6d271ca33075c88028be6f04d502853d63a5ece419d269c15315d4fc1cf1d" +dependencies = [ + "signature 2.1.0", +] + +[[package]] +name = "ed25519-dalek" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" +dependencies = [ + "curve25519-dalek", + "ed25519", + "sha2 0.10.7", +] + [[package]] name = "either" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "elliptic-curve" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83e5c176479da93a0983f0a6fdc3c1b8e7d5be0d7fe3fe05a99f15b96582b9a8" +dependencies = [ + "crypto-bigint", + "ff", + "generic-array", + "group", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + [[package]] name = "ena" version = "0.14.2" @@ -143,12 +371,44 @@ dependencies = [ "libc", ] +[[package]] +name = "ff" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0f40b2dcd8bc322217a5f6559ae5f9e9d1de202a2ecee2e9eafcbece7562a4f" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "fiat-crypto" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0870c84016d4b481be5c9f323c24f65e31e901ae618f0e80f4308fb00de1d2d" + [[package]] name = "fixedbitset" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.10" @@ -160,18 +420,69 @@ dependencies = [ "wasi", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "group" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c363a5301b8f153d80747126a04b3c82073b9fe3130571a9d170cacdeaf7912" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "hashbrown" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "hermit-abi" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" +dependencies = [ + "crypto-mac", + "digest 0.9.0", +] + +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys", +] + [[package]] name = "indexmap" version = "2.0.0" @@ -202,6 +513,12 @@ dependencies = [ "either", ] +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + [[package]] name = "lalrpop" version = "0.20.0" @@ -218,7 +535,7 @@ dependencies = [ "petgraph", "pico-args", "regex", - "regex-syntax", + "regex-syntax 0.7.5", "string_cache", "term", "tiny-keccak", @@ -234,12 +551,63 @@ dependencies = [ "regex", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +[[package]] +name = "libsecp256k1" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" +dependencies = [ + "arrayref", + "base64", + "digest 0.9.0", + "libsecp256k1-core", + "libsecp256k1-gen-ecmult", + "libsecp256k1-gen-genmult", + "rand 0.8.5", + "serde", +] + +[[package]] +name = "libsecp256k1-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be9b9bb642d8522a44d533eab56c16c738301965504753b03ad1de3425d5451" +dependencies = [ + "crunchy", + "digest 0.9.0", + "subtle", +] + +[[package]] +name = "libsecp256k1-gen-ecmult" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3038c808c55c87e8a172643a7d87187fc6c4174468159cb3090659d55bcb4809" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "libsecp256k1-gen-genmult" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db8d6ba2cec9eacc40e6e8ccc98931840301f1006e95647ceb2dd5c3aa06f7c" +dependencies = [ + "libsecp256k1-core", +] + [[package]] name = "linux-raw-sys" version = "0.4.7" @@ -268,12 +636,19 @@ version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "mir" version = "0.1.0" dependencies = [ "lalrpop", "lalrpop-util", + "tezos-smart-rollup", ] [[package]] @@ -282,12 +657,80 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-bigint" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "once_cell" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "p256" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d053368e1bae4c8a672953397bd1bd7183dde1c72b0b7612a15719173148d186" +dependencies = [ + "ecdsa", + "elliptic-curve", + "sha2 0.9.9", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -311,6 +754,31 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "parse-display" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7271152b3c46c07c729698e7a5248e2744466b3446d222c97a0b1315925a97b1" +dependencies = [ + "once_cell", + "parse-display-derive", + "regex", +] + +[[package]] +name = "parse-display-derive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6a9f3e41b237b77c99c09686481c235964ff5878229412b226c451f3e809f4f" +dependencies = [ + "once_cell", + "proc-macro2", + "quote", + "regex", + "regex-syntax 0.6.29", + "syn 1.0.109", +] + [[package]] name = "petgraph" version = "0.6.4" @@ -336,6 +804,18 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" +[[package]] +name = "platforms" +version = "3.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "precomputed-hash" version = "0.1.1" @@ -360,6 +840,63 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "rand_chacha", + "rand_core 0.5.1", + "rand_hc", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -398,7 +935,7 @@ dependencies = [ "aho-corasick", "memchr", "regex-automata", - "regex-syntax", + "regex-syntax 0.7.5", ] [[package]] @@ -409,15 +946,30 @@ checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.7.5", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.38.13" @@ -443,6 +995,72 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "semver" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0" + +[[package]] +name = "serde" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.33", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "signature" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2807892cfa58e081aa1f1111391c7a0649d4fa127a4ffbe34bcbfb35a1171a4" +dependencies = [ + "digest 0.9.0", + "rand_core 0.6.4", +] + +[[package]] +name = "signature" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" + [[package]] name = "siphasher" version = "0.3.11" @@ -468,6 +1086,41 @@ dependencies = [ "precomputed-hash", ] +[[package]] +name = "strum" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7318c509b5ba57f18533982607f24070a55d353e90d4cae30c467cdb2ad5ac5c" + +[[package]] +name = "strum_macros" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee8bc6b87a5112aeeab1f4a9f7ab634fe6cbefc4850006df31267f4cfb9e3149" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.33" @@ -479,6 +1132,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "term" version = "0.7.0" @@ -490,6 +1149,162 @@ dependencies = [ "winapi", ] +[[package]] +name = "tezos-smart-rollup" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc0d1ca723e4be76ae7f292068cc835e3cb2b74c0ec6e02c34f0474f7b65d4f" +dependencies = [ + "tezos-smart-rollup-core", + "tezos-smart-rollup-debug", + "tezos-smart-rollup-encoding", + "tezos-smart-rollup-entrypoint", + "tezos-smart-rollup-host", + "tezos-smart-rollup-storage", + "tezos_crypto_rs", + "tezos_data_encoding", +] + +[[package]] +name = "tezos-smart-rollup-core" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6982a67c936c315d8327c9d4bb0a29f53faa7fe24f02d5fb9d8d93f98553cbb1" + +[[package]] +name = "tezos-smart-rollup-debug" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e84d8e72a764c57ed1fc8dccc7090cd76b1da187e19b588f3da3515bef0314b2" +dependencies = [ + "tezos-smart-rollup-core", + "tezos-smart-rollup-host", +] + +[[package]] +name = "tezos-smart-rollup-encoding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cae9ceec0ecf07b635420874723ddc4c578a29d2cd3bb50e7f14171f2f0906a2" +dependencies = [ + "hex", + "nom", + "num-bigint", + "num-traits", + "tezos-smart-rollup-core", + "tezos-smart-rollup-host", + "tezos_crypto_rs", + "tezos_data_encoding", + "tezos_data_encoding_derive", + "thiserror", + "time", +] + +[[package]] +name = "tezos-smart-rollup-entrypoint" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30022841b361845e0f7b9eabfdd065cf628b21f22214de3229675017fe25439a" +dependencies = [ + "dlmalloc", + "tezos-smart-rollup-core", + "tezos-smart-rollup-debug", + "tezos-smart-rollup-host", + "tezos-smart-rollup-panic-hook", +] + +[[package]] +name = "tezos-smart-rollup-host" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b7f04c22d0b0015563b53a0e67581a162cd358a55ba6d7c7da447ad0a6c2da5" +dependencies = [ + "tezos-smart-rollup-core", + "tezos_crypto_rs", + "tezos_data_encoding", + "thiserror", +] + +[[package]] +name = "tezos-smart-rollup-panic-hook" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ed704d934d0295cc4f38b867c03641b4adcc218df007a9c237dad989e5eb4aa" +dependencies = [ + "tezos-smart-rollup-core", +] + +[[package]] +name = "tezos-smart-rollup-storage" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeb101aa1167477304ed6cdecd3b357af627fdc8ba757caa0d64e4f182b9a1d7" +dependencies = [ + "tezos-smart-rollup-core", + "tezos-smart-rollup-debug", + "tezos-smart-rollup-encoding", + "tezos-smart-rollup-host", + "thiserror", +] + +[[package]] +name = "tezos_crypto_rs" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576b69129eabf1edca392ff5e763610d448275fd2724d05464bb3542829c6d64" +dependencies = [ + "anyhow", + "base58", + "blst", + "byteorder", + "cryptoxide", + "ed25519-dalek", + "hex", + "libsecp256k1", + "num-bigint", + "num-traits", + "p256", + "rand 0.7.3", + "serde", + "strum", + "strum_macros", + "thiserror", + "zeroize", +] + +[[package]] +name = "tezos_data_encoding" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67e84a4b90368a8d4fd76687919227d3940aa4e9b826e23f08b9cd3a2ad22e47" +dependencies = [ + "bit-vec", + "bitvec", + "hex", + "lazy_static", + "nom", + "num-bigint", + "num-traits", + "serde", + "tezos_crypto_rs", + "tezos_data_encoding_derive", + "thiserror", +] + +[[package]] +name = "tezos_data_encoding_derive" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14d37c93461ba298e923ec27af2dd4139ef0cc246defa938eecde133af770ea5" +dependencies = [ + "lazy_static", + "once_cell", + "parse-display", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "thiserror" version = "1.0.48" @@ -507,7 +1322,43 @@ checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.33", +] + +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "time" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53250a3b3fed8ff8fd988587d8925d26a83ac3845d9e03b220b37f34c2b8d6c2" +dependencies = [ + "itoa", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + +[[package]] +name = "time-macros" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a460aeb8de6dcb0f381e1ee05f1cd56fcf5a5f6eb8187ff3d8f0b11078d38b7c" +dependencies = [ + "time-core", ] [[package]] @@ -519,24 +1370,54 @@ dependencies = [ "crunchy", ] +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + [[package]] name = "unicode-xid" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "winapi" version = "0.3.9" @@ -624,3 +1505,32 @@ name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zeroize" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.33", +] diff --git a/contrib/mir/Cargo.toml b/contrib/mir/Cargo.toml index e3f7b35ec034..df797ce3204c 100644 --- a/contrib/mir/Cargo.toml +++ b/contrib/mir/Cargo.toml @@ -3,8 +3,16 @@ name = "mir" version = "0.1.0" edition = "2021" +[lib] +crate-type = ["cdylib", "lib"] + +[[bin]] +name = "sandbox" +path = "src/main.rs" + [build-dependencies] lalrpop = "0.20.0" [dependencies] lalrpop-util = { version = "0.20.0", features = ["lexer"] } +tezos-smart-rollup = "0.2.1" diff --git a/contrib/mir/rust-toolchain.toml b/contrib/mir/rust-toolchain.toml new file mode 100644 index 000000000000..990104f055b0 --- /dev/null +++ b/contrib/mir/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +targets = ["wasm32-unknown-unknown"] diff --git a/contrib/mir/src/lib.rs b/contrib/mir/src/lib.rs new file mode 100644 index 000000000000..8d22eaf649ad --- /dev/null +++ b/contrib/mir/src/lib.rs @@ -0,0 +1,8 @@ +use tezos_smart_rollup::kernel_entry; +use tezos_smart_rollup::prelude::{debug_msg, Runtime}; + +kernel_entry!(kernel_entry); + +pub fn kernel_entry(host: &mut Host) { + debug_msg!(host, "Hello Kernel"); +} -- GitLab From 47ff92ecb76c342a2e6b1d8e679312cecdd1fe80 Mon Sep 17 00:00:00 2001 From: martoon Date: Wed, 6 Sep 2023 20:58:40 +0300 Subject: [PATCH 2/8] MIR: Add initial docs on building --- contrib/mir/README.md | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/contrib/mir/README.md b/contrib/mir/README.md index 4f58ad77b8ed..a21715130d70 100644 --- a/contrib/mir/README.md +++ b/contrib/mir/README.md @@ -1,16 +1,30 @@ -### M.I.R - Michelson In Rust +# M.I.R - Michelson In Rust This repo hosts the Rust implementation of the typechecker and interpreter for -Michelson smart contract language. +Michelson smart contract language and implements a Michelson runtime as a +Smart Rollup. -#### Building +This project implements a Michelson runtime as a Smart Rollup. -You need `cargo` to build this project. You can use the following -command to build the project. +## Building -`cargo build` +Running -#### Testing +``` +cargo build --target wasm32-unknown-unknown +``` + +will build the project in wasm, installing all the necessary toolchain. + +You will need `clang >= 11` installed in the system. This and other constraints +can be found mentioned in the +[Rust SDK for Smart Rollups](https://docs.rs/tezos-smart-rollup/latest/tezos_smart_rollup/). + +That build command will also automatically install the standard library for +`wasm32-unknown-unknown` target since compiling to that target is necessary for +actually using the produced kernel in Tezos network. + +## Automatic testing You can run the included tests by the following command. -- GitLab From e11ebdbf903f00a955bb3174565e838162fc1d3c Mon Sep 17 00:00:00 2001 From: martoon Date: Wed, 6 Sep 2023 22:47:14 +0300 Subject: [PATCH 3/8] MIR: Add main processing loop --- contrib/mir/src/lib.rs | 8 ++----- contrib/mir/src/rollup.rs | 1 + contrib/mir/src/rollup/kernel.rs | 39 ++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 contrib/mir/src/rollup.rs create mode 100644 contrib/mir/src/rollup/kernel.rs diff --git a/contrib/mir/src/lib.rs b/contrib/mir/src/lib.rs index 8d22eaf649ad..9ab972a351fe 100644 --- a/contrib/mir/src/lib.rs +++ b/contrib/mir/src/lib.rs @@ -1,8 +1,4 @@ +mod rollup; use tezos_smart_rollup::kernel_entry; -use tezos_smart_rollup::prelude::{debug_msg, Runtime}; -kernel_entry!(kernel_entry); - -pub fn kernel_entry(host: &mut Host) { - debug_msg!(host, "Hello Kernel"); -} +kernel_entry!(rollup::kernel::kernel_entry); diff --git a/contrib/mir/src/rollup.rs b/contrib/mir/src/rollup.rs new file mode 100644 index 000000000000..c3af9f72b35b --- /dev/null +++ b/contrib/mir/src/rollup.rs @@ -0,0 +1 @@ +pub mod kernel; diff --git a/contrib/mir/src/rollup/kernel.rs b/contrib/mir/src/rollup/kernel.rs new file mode 100644 index 000000000000..9b2bf5d45a71 --- /dev/null +++ b/contrib/mir/src/rollup/kernel.rs @@ -0,0 +1,39 @@ +use tezos_smart_rollup::{ + prelude::{debug_msg, Runtime}, + types::Message, +}; + +// This module follows the reference examples: https://gitlab.com/tezos/kernel-gallery + +/// The root method of the kernel. +/// +/// Executed every level. Can be asked from inside to be run again at the same +/// level to handle some of the messages in the inbox, mind the limits on +/// execution time of one such call. +pub fn kernel_entry(host: &mut impl Runtime) { + debug_msg!(host, "Kernel invoked"); + + let mut first_message_for_invocation = true; + // Handle all the messages we got at this level + loop { + match host.read_input() { + Ok(Some(msg)) => { + if first_message_for_invocation { + debug_msg!(host, "Handling messages at level {}", msg.level); + first_message_for_invocation = false; + } + + // TODO [#6411]: wrap into catch_unwind + process_message(host, &msg); + } + // The kernel gallery and some experienced devs advise to keep + // reading, errors in messages reading are really unlikely here. + Err(_) => continue, + Ok(None) => break, + } + } +} + +pub fn process_message(host: &mut impl Runtime, msg: &Message) { + let _ = (host, msg); +} -- GitLab From a95a28c39016d9687d4c2cd121d461e1930be641 Mon Sep 17 00:00:00 2001 From: martoon Date: Wed, 6 Sep 2023 23:35:52 +0300 Subject: [PATCH 4/8] MIR: Add messages parsing --- contrib/mir/src/rollup.rs | 1 + contrib/mir/src/rollup/kernel.rs | 43 +++++++++++++++++++++++++++++--- contrib/mir/src/rollup/types.rs | 8 ++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 contrib/mir/src/rollup/types.rs diff --git a/contrib/mir/src/rollup.rs b/contrib/mir/src/rollup.rs index c3af9f72b35b..50f370168171 100644 --- a/contrib/mir/src/rollup.rs +++ b/contrib/mir/src/rollup.rs @@ -1 +1,2 @@ pub mod kernel; +pub mod types; diff --git a/contrib/mir/src/rollup/kernel.rs b/contrib/mir/src/rollup/kernel.rs index 9b2bf5d45a71..2ecb79653b3e 100644 --- a/contrib/mir/src/rollup/kernel.rs +++ b/contrib/mir/src/rollup/kernel.rs @@ -1,10 +1,15 @@ use tezos_smart_rollup::{ + inbox::{InboxMessage, InternalInboxMessage}, prelude::{debug_msg, Runtime}, types::Message, }; +use super::types::*; + // This module follows the reference examples: https://gitlab.com/tezos/kernel-gallery +pub type Error = String; + /// The root method of the kernel. /// /// Executed every level. Can be asked from inside to be run again at the same @@ -24,7 +29,10 @@ pub fn kernel_entry(host: &mut impl Runtime) { } // TODO [#6411]: wrap into catch_unwind - process_message(host, &msg); + let res = process_message(host, &msg); + res.unwrap_or_else(|err| { + debug_msg!(host, "Processing message #{} failed: {}", msg.id, err) + }) } // The kernel gallery and some experienced devs advise to keep // reading, errors in messages reading are really unlikely here. @@ -34,6 +42,35 @@ pub fn kernel_entry(host: &mut impl Runtime) { } } -pub fn process_message(host: &mut impl Runtime, msg: &Message) { - let _ = (host, msg); +pub fn process_message(host: &mut impl Runtime, msg: &Message) -> Result<(), Error> { + let msg_id = msg.id; + let (rest, msg) = + InboxMessage::::parse(msg.as_ref()).map_err(|x| x.to_string())?; + // Likely we don't want to restrict the unparsed input for the sake of + // forward compatibility. And the reference kernels do the same thing. + debug_assert!(rest.is_empty()); + match msg { + InboxMessage::External(payload) => { + debug_msg!(host, "Message #{msg_id} - external: {payload:#x?}") + } + // [optimization] If payload is bytes, it should not be hard + // to avoid copying payload when parsing if we use our own structures. + // If it is not necessarily bytes, Nom lib still supports returning borrowed + // data and for concrete small type we won't need to write much of a + // decoding logic. + InboxMessage::Internal(in_msg) => match in_msg { + InternalInboxMessage::Transfer(transfer) => { + debug_msg!( + host, + "Message #{msg_id} - internal transfer to {} with payload: {:#x?}", + transfer.destination, + &transfer.payload.0 + ) + } + InternalInboxMessage::StartOfLevel => {} + InternalInboxMessage::InfoPerLevel(_) => {} + InternalInboxMessage::EndOfLevel => {} + }, + } + Ok(()) } diff --git a/contrib/mir/src/rollup/types.rs b/contrib/mir/src/rollup/types.rs new file mode 100644 index 000000000000..88527b5846ec --- /dev/null +++ b/contrib/mir/src/rollup/types.rs @@ -0,0 +1,8 @@ +use tezos_smart_rollup::michelson::MichelsonBytes; + +/// What we accept in internal messages as payload (i.e. what is our parameter +/// type). +/// +/// If you change this, then in the rollup origination command you should also +/// change the `type` CLI argument respectively. +pub type IncomingTransferParam = MichelsonBytes; -- GitLab From a6438dc9238872bfecaa532e0c5330edccc424d8 Mon Sep 17 00:00:00 2001 From: martoon Date: Wed, 13 Sep 2023 13:19:12 +0300 Subject: [PATCH 5/8] MIR: Deal with unused warnings Problem: for all targets except `wasm32` I get warnings about all kernel code being unused. This happens because `kernel_entry!` macro exposes our kernel only when compiled for `wasm32`. Solution: add a dummy use of `kernel_entry` for non-wasm32 targets. --- contrib/mir/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/contrib/mir/src/lib.rs b/contrib/mir/src/lib.rs index 9ab972a351fe..1007d6265473 100644 --- a/contrib/mir/src/lib.rs +++ b/contrib/mir/src/lib.rs @@ -1,4 +1,14 @@ mod rollup; -use tezos_smart_rollup::kernel_entry; +use rollup::kernel::kernel_entry; +use tezos_smart_rollup::{kernel_entry, prelude::Runtime}; kernel_entry!(rollup::kernel::kernel_entry); + +// kernel_entry! does something only on wasm32 target, on others we should deal +// with `kernel_entry` being unused. +#[cfg(not(feature = "wasm32-unknown-unknown"))] +#[allow(dead_code)] +fn consider_kernel_used(host: &mut impl Runtime) -> ! { + let _ = kernel_entry(host); + panic!("Should not be called"); +} -- GitLab From 6407e0b4e8e30ea9d137fea54b6cfed16d768e30 Mon Sep 17 00:00:00 2001 From: martoon Date: Tue, 12 Sep 2023 02:49:43 +0300 Subject: [PATCH 6/8] MIR: Add dummy fibonacci logic to rollup Prepare a rollup that executes fibonacci contract, but instead of contract call yet have a dummy Rust computation. Parameter is obtained from the processed message, and storage persists in the durable storage. --- contrib/mir/Cargo.lock | 15 +++++++++ contrib/mir/Cargo.toml | 1 + contrib/mir/src/rollup.rs | 1 + contrib/mir/src/rollup/demo.rs | 55 ++++++++++++++++++++++++++++++++ contrib/mir/src/rollup/kernel.rs | 5 ++- 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 contrib/mir/src/rollup/demo.rs diff --git a/contrib/mir/Cargo.lock b/contrib/mir/Cargo.lock index 2f96f32f9eef..2729f05ea3da 100644 --- a/contrib/mir/Cargo.lock +++ b/contrib/mir/Cargo.lock @@ -649,6 +649,7 @@ dependencies = [ "lalrpop", "lalrpop-util", "tezos-smart-rollup", + "tezos-smart-rollup-mock", ] [[package]] @@ -1225,6 +1226,20 @@ dependencies = [ "thiserror", ] +[[package]] +name = "tezos-smart-rollup-mock" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c0a78d331bf3b80970c7e2b81472283f197aab77912e079e759c2e672d451cc" +dependencies = [ + "hex", + "tezos-smart-rollup-core", + "tezos-smart-rollup-encoding", + "tezos-smart-rollup-host", + "tezos_crypto_rs", + "tezos_data_encoding", +] + [[package]] name = "tezos-smart-rollup-panic-hook" version = "0.2.1" diff --git a/contrib/mir/Cargo.toml b/contrib/mir/Cargo.toml index df797ce3204c..059c26d739c3 100644 --- a/contrib/mir/Cargo.toml +++ b/contrib/mir/Cargo.toml @@ -16,3 +16,4 @@ lalrpop = "0.20.0" [dependencies] lalrpop-util = { version = "0.20.0", features = ["lexer"] } tezos-smart-rollup = "0.2.1" +tezos-smart-rollup-mock = "0.2.1" diff --git a/contrib/mir/src/rollup.rs b/contrib/mir/src/rollup.rs index 50f370168171..754f17f66904 100644 --- a/contrib/mir/src/rollup.rs +++ b/contrib/mir/src/rollup.rs @@ -1,2 +1,3 @@ +pub mod demo; pub mod kernel; pub mod types; diff --git a/contrib/mir/src/rollup/demo.rs b/contrib/mir/src/rollup/demo.rs new file mode 100644 index 000000000000..67aece642783 --- /dev/null +++ b/contrib/mir/src/rollup/demo.rs @@ -0,0 +1,55 @@ +//! This is a logic for demo rollup that eventually should be thrown away. + +use std::mem::size_of; +use tezos_smart_rollup::{ + prelude::{debug_msg, Runtime}, + storage::path::RefPath, +}; + +pub type Error = String; + +const STORAGE_PATH: &RefPath = &RefPath::assert_from(b"/storage"); + +pub fn process_external_message(host: &mut impl Runtime, payload: &[u8]) -> Result<(), Error> { + let param = free_form_bytes_to_number(payload); + let is_storage_empty = host + .store_has(STORAGE_PATH) + .map_err(|err| err.to_string())? + .is_none(); + let storage = if is_storage_empty { + 0 + } else { + free_form_bytes_to_number( + host.store_read_all(STORAGE_PATH) + .map_err(|err| err.to_string())? + .as_ref(), + ) + }; + // ↑ That's pretty painful, MR with a higher-level API is on the way + + let new_storage = run_fibonacci(param, storage)?; + + host.store_write_all(STORAGE_PATH, &new_storage.to_le_bytes()) + .map_err(|err| err.to_string())?; + debug_msg!(host, "Computation successful, storage updated"); + Ok(()) +} + +fn run_fibonacci(param: usize, _storage: usize) -> Result { + // TODO: replace with contract interpretation + let answers: Vec = vec![ + 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, + ]; + answers + .get(param) + .copied() + .ok_or(String::from("Cannot answer for such large number :shrug:")) +} + +/// Accepts both undersized and oversized byte arrays to convert to number. +fn free_form_bytes_to_number(bs: &[u8]) -> usize { + let mut bs_sized = [0; size_of::()]; + let bs_len = std::cmp::min(bs_sized.len(), bs.len()); + bs_sized[..bs_len].copy_from_slice(&bs[..bs_len]); + usize::from_le_bytes(bs_sized) +} diff --git a/contrib/mir/src/rollup/kernel.rs b/contrib/mir/src/rollup/kernel.rs index 2ecb79653b3e..15a9447cb371 100644 --- a/contrib/mir/src/rollup/kernel.rs +++ b/contrib/mir/src/rollup/kernel.rs @@ -4,6 +4,8 @@ use tezos_smart_rollup::{ types::Message, }; +use crate::rollup::demo::process_external_message; + use super::types::*; // This module follows the reference examples: https://gitlab.com/tezos/kernel-gallery @@ -65,7 +67,8 @@ pub fn process_message(host: &mut impl Runtime, msg: &Message) -> Result<(), Err "Message #{msg_id} - internal transfer to {} with payload: {:#x?}", transfer.destination, &transfer.payload.0 - ) + ); + process_external_message(host, &transfer.payload.0)? } InternalInboxMessage::StartOfLevel => {} InternalInboxMessage::InfoPerLevel(_) => {} -- GitLab From 8ef87acd8e64bb8e1f921e0c3ecbd554c74ca99a Mon Sep 17 00:00:00 2001 From: martoon Date: Tue, 12 Sep 2023 02:51:16 +0300 Subject: [PATCH 7/8] MIR: Add tests on new logic --- contrib/mir/src/rollup/demo.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/contrib/mir/src/rollup/demo.rs b/contrib/mir/src/rollup/demo.rs index 67aece642783..e20766fb1f19 100644 --- a/contrib/mir/src/rollup/demo.rs +++ b/contrib/mir/src/rollup/demo.rs @@ -53,3 +53,24 @@ fn free_form_bytes_to_number(bs: &[u8]) -> usize { bs_sized[..bs_len].copy_from_slice(&bs[..bs_len]); usize::from_le_bytes(bs_sized) } + +#[cfg(test)] +mod test_message_processing { + use tezos_smart_rollup_mock::MockHost; + + use super::*; + + fn test_on_sample(param: &[u8], expected_res: &[u8]) { + let mut host = MockHost::default(); + process_external_message(&mut host, param).unwrap(); + assert_eq!(host.store_read_all(STORAGE_PATH).unwrap(), expected_res); + } + + #[test] + fn test_processing_on_samples() { + test_on_sample(b"\x00", b"\0\0\0\0\0\0\0\0"); + test_on_sample(b"\x01", b"\x01\0\0\0\0\0\0\0"); + test_on_sample(&[10], &[55, 0, 0, 0, 0, 0, 0, 0]); + test_on_sample(&[15], &[98, 2, 0, 0, 0, 0, 0, 0]); + } +} -- GitLab From ff457284e2d067baf39f8e1fac604f34c3fa8c8c Mon Sep 17 00:00:00 2001 From: martoon Date: Thu, 28 Sep 2023 02:09:22 +0400 Subject: [PATCH 8/8] MIR: Use the contract in the rollup --- contrib/mir/src/lib.rs | 8 ++++++++ contrib/mir/src/rollup/demo.rs | 33 ++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/contrib/mir/src/lib.rs b/contrib/mir/src/lib.rs index 1007d6265473..9c56d4cafa7d 100644 --- a/contrib/mir/src/lib.rs +++ b/contrib/mir/src/lib.rs @@ -1,4 +1,12 @@ +mod ast; +mod gas; +mod interpreter; +mod parser; mod rollup; +mod stack; +mod syntax; +mod typechecker; + use rollup::kernel::kernel_entry; use tezos_smart_rollup::{kernel_entry, prelude::Runtime}; diff --git a/contrib/mir/src/rollup/demo.rs b/contrib/mir/src/rollup/demo.rs index e20766fb1f19..92973a4a1bf9 100644 --- a/contrib/mir/src/rollup/demo.rs +++ b/contrib/mir/src/rollup/demo.rs @@ -1,6 +1,7 @@ //! This is a logic for demo rollup that eventually should be thrown away. -use std::mem::size_of; +use crate::{ast::Value, gas, interpreter, parser}; +use std::{collections::VecDeque, mem::size_of}; use tezos_smart_rollup::{ prelude::{debug_msg, Runtime}, storage::path::RefPath, @@ -36,14 +37,18 @@ pub fn process_external_message(host: &mut impl Runtime, payload: &[u8]) -> Resu } fn run_fibonacci(param: usize, _storage: usize) -> Result { - // TODO: replace with contract interpretation - let answers: Vec = vec![ - 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, - ]; - answers - .get(param) - .copied() - .ok_or(String::from("Cannot answer for such large number :shrug:")) + // NB: This is still not a real contract because we do not support pairs + let code = parser::parse(&FIBONACCI_SRC).map_err(|err| err.to_string())?; + let param_val = Value::NumberValue(param as i32); + let mut istack = VecDeque::from([param_val]); + let mut gas = gas::Gas::default(); + assert!(interpreter::interpret(&code, &mut gas, &mut istack).is_ok()); + match istack.make_contiguous() { + [Value::NumberValue(res)] => { + Ok(usize::try_from(*res).map_err(|_| String::from("Too large answer"))?) + } + _ => Err(String::from("Unexpected stack form at the end: {stack}")), + } } /// Accepts both undersized and oversized byte arrays to convert to number. @@ -74,3 +79,13 @@ mod test_message_processing { test_on_sample(&[15], &[98, 2, 0, 0, 0, 0, 0, 0]); } } + +const FIBONACCI_SRC: &str = "{ + INT ; PUSH int 0 ; DUP 2 ; GT ; + IF { DIP { PUSH int -1 ; ADD } ; + PUSH int 1 ; + DUP 3 ; + GT ; + LOOP { SWAP ; DUP 2 ; ADD ; DIP 2 { PUSH int -1 ; ADD } ; DUP 3 ; GT } ; + DIP { DROP 2 } } + { DIP { DROP } } }"; -- GitLab