|
1 |
| -// Copyright 2024 RISC Zero, Inc. |
2 |
| -// |
3 |
| -// Licensed under the Apache License, Version 2.0 (the "License"); |
4 |
| -// you may not use this file except in compliance with the License. |
5 |
| -// You may obtain a copy of the License at |
6 |
| -// |
7 |
| -// http://www.apache.org/licenses/LICENSE-2.0 |
8 |
| -// |
9 |
| -// Unless required by applicable law or agreed to in writing, software |
10 |
| -// distributed under the License is distributed on an "AS IS" BASIS, |
11 |
| -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 |
| -// See the License for the specific language governing permissions and |
13 |
| -// limitations under the License. |
14 |
| - |
15 |
| -//! The RISC Zero zkVM's guest-side RISC-V API. |
16 |
| -//! |
17 |
| -//! Code that is validated by the [RISC Zero zkVM](crate) is run inside the guest. In almost all |
18 |
| -//! practical cases, the guest will want to read private input data from the host and write public |
19 |
| -//! data to the journal. This can be done with [env::read] and [env::commit], respectively; |
20 |
| -//! additional I/O functionality is also available in [mod@env]. |
21 |
| -//! |
22 |
| -//! ## Installation |
23 |
| -//! |
24 |
| -//! To build and run RISC Zero zkVM code, you will need to install the RISC Zero |
25 |
| -//! toolchain, which can be done using the rzup utility: |
26 |
| -//! |
27 |
| -//! ```sh |
28 |
| -//! curl -L https://risczero.com/install | bash |
29 |
| -//! rzup install |
30 |
| -//! ``` |
31 |
| -//! |
32 |
| -//! ## Example |
33 |
| -//! |
34 |
| -//! The following guest code[^starter-ex] proves a number is |
35 |
| -//! composite by multiplying two unsigned integers, and panicking if either is |
36 |
| -//! `1` or if the multiplication overflows: |
37 |
| -//! |
38 |
| -//! ```ignore |
39 |
| -//! #![no_main] |
40 |
| -//! #![no_std] |
41 |
| -//! |
42 |
| -//! use risc0_zkvm::guest::env; |
43 |
| -//! |
44 |
| -//! risc0_zkvm::guest::entry!(main); |
45 |
| -//! |
46 |
| -//! fn main() { |
47 |
| -//! // Load the first number from the host |
48 |
| -//! let a: u64 = env::read(); |
49 |
| -//! // Load the second number from the host |
50 |
| -//! let b: u64 = env::read(); |
51 |
| -//! // Verify that neither of them are 1 (i.e. nontrivial factors) |
52 |
| -//! if a == 1 || b == 1 { |
53 |
| -//! panic!("Trivial factors") |
54 |
| -//! } |
55 |
| -//! // Compute the product while being careful with integer overflow |
56 |
| -//! let product = a.checked_mul(b).expect("Integer overflow"); |
57 |
| -//! env::commit(&product); |
58 |
| -//! } |
59 |
| -//! ``` |
60 |
| -//! |
61 |
| -//! Notice how [env::read] is used to load the two factors, and [env::commit] is used to make their |
62 |
| -//! composite product publicly available. All input an output of your guest is private except for |
63 |
| -//! what is written to the journal with [env::commit]. |
64 |
| -//! |
65 |
| -//! By default, the guest only has the Rust `core` libraries and not `std`. A partial |
66 |
| -//! implementation of the Rust standard libraries can be enabled with the `std` feature on this [crate]. |
67 |
| -//! When this feature is not enabled, the lines including `#![no_std]` and `#![no_main]` are |
68 |
| -//! required, as well as the use of the [crate::guest::entry] macro. When `std` is enabled, these |
69 |
| -//! three lines can be omitted and many features of `std` can be used. |
70 |
| -//! |
71 |
| -//! If you encounter problems building zkVM guest code, you can see if we have a |
72 |
| -//! known workaround for your issue by looking in our |
73 |
| -//! [rust guest workarounds](https://github.com/risc0/risc0/issues?q=is%3Aissue+is%3Aopen+label%3A%22rust+guest+workarounds%22) |
74 |
| -//! tag on GitHub. |
75 |
| -//! |
76 |
| -//! [^starter-ex]: The example is based on the [Factors example](https://github.com/risc0/risc0/tree/main/examples/factors). |
| 1 | +//! # axVM |
77 | 2 |
|
78 | 3 | #![cfg_attr(not(feature = "std"), no_std)]
|
79 | 4 | #![deny(rustdoc::broken_intra_doc_links)]
|
80 | 5 | #![deny(missing_docs)]
|
81 | 6 | #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
| 7 | +#![feature(asm_const)] |
82 | 8 |
|
83 | 9 | extern crate alloc;
|
84 | 10 |
|
85 |
| -pub mod env; |
86 | 11 | pub mod intrinsics;
|
| 12 | +pub mod io; |
| 13 | +pub mod process; |
87 | 14 | pub mod serde;
|
88 | 15 |
|
89 | 16 | #[cfg(target_os = "zkvm")]
|
@@ -165,7 +92,8 @@ unsafe extern "C" fn __start() -> ! {
|
165 | 92 | main()
|
166 | 93 | }
|
167 | 94 |
|
168 |
| - env::exit::<0>(); |
| 95 | + process::exit(); |
| 96 | + unreachable!() |
169 | 97 | }
|
170 | 98 |
|
171 | 99 | #[cfg(target_os = "zkvm")]
|
|
0 commit comments