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

WEB3-67: feat: switch Steel to alloy #183

Merged
merged 32 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b30672c
switch Steel to alloy
Wollac Jul 24, 2024
fcd859a
remove ethers dependencies
Wollac Jul 24, 2024
90f76f3
cleanup Cargo.toml
Wollac Jul 24, 2024
0996262
fix serde
Wollac Jul 25, 2024
8e595c3
improve RlpHeader performance
Wollac Jul 26, 2024
3c2093e
minor refactoring
Wollac Jul 29, 2024
e438458
add ERC20 tests back
Wollac Jul 29, 2024
4c66d06
add more RPC checks
Wollac Jul 30, 2024
1b0109b
minor test cleanups
Wollac Jul 30, 2024
ce727d0
remove unused dependencies
Wollac Jul 30, 2024
4de4a97
fix examples
Wollac Jul 30, 2024
609fc39
Paris oldest supported version
Wollac Jul 30, 2024
fa7e48a
fix steel tests
Wollac Jul 31, 2024
913bc31
make commitment explicit
Wollac Jul 31, 2024
dea7825
do not use eth_getProof in alloyDb
Wollac Jul 31, 2024
3728acf
add changelog
Wollac Aug 1, 2024
6e84c9a
upgrade alloy to v0.2.1
Wollac Aug 5, 2024
3c84555
cleanup AlloyDb
Wollac Aug 5, 2024
f668c8a
update README
Wollac Aug 5, 2024
9fa83a4
update alloy-rlp
Wollac Aug 6, 2024
3b6b162
add comment
Wollac Aug 6, 2024
75f5718
enable logging for blockhash
Wollac Aug 6, 2024
b2d6071
chain spec cleanup
Wollac Aug 6, 2024
f4e7e7f
add solc compile instructions
Wollac Aug 6, 2024
eded136
fix fmt
Wollac Aug 6, 2024
311692d
Merge branch 'main' into feat/alloy
Wollac Aug 6, 2024
a42c5e3
Improve groth16 encode API (#179)
capossele Aug 7, 2024
6f665c2
Merge branch 'main' into feat/alloy
capossele Aug 7, 2024
519bf45
improve doc
Wollac Aug 7, 2024
76af633
fix clippy warnings
Wollac Aug 7, 2024
d2d2fa3
make url dependency optional
Wollac Aug 7, 2024
26ec759
improve CHANGELOG.md
Wollac Aug 7, 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
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [Linux, macOS]
feature: [default]
device: [cpu]
include:
- os: Linux
feature: default
device: cpu
- os: Linux
feature: cuda
device: nvidia_rtx_a5000
- os: macOS
feature: metal
feature: default
device: apple_m2_pro
env:
FEATURE: ${{ matrix.feature }}
Expand Down
16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,27 @@ risc0-build = { git = "https://github.com/risc0/risc0", branch = "main", default
risc0-zkp = { git = "https://github.com/risc0/risc0", branch = "main", default-features = false }
risc0-zkvm = { git = "https://github.com/risc0/risc0", branch = "main", default-features = false }

alloy-primitives = { version = "0.7", features = ["serde", "rlp", "std"] }
alloy-rlp = { version = "0.3.7", default-features = false }
alloy-rlp-derive = { version = "0.3.7", default-features = false }
# Alloy guest dependencies
alloy-consensus = { version = "0.2.1" }
alloy-primitives = { version = "0.7", features = ["rlp", "std"] }
alloy-rlp = { version = "0.3.8", default-features = false }
alloy-rlp-derive = { version = "0.3.8", default-features = false }
alloy-sol-types = { version = "0.7" }

# Alloy host dependencies
alloy = { version = "0.2.1", features = ["full"] }
alloy-trie = { version = "0.4.0" }

anyhow = { version = "1.0" }
bincode = { version = "1.3" }
clap = { version = "4.5", features = ["derive", "env"] }
ethers-core = "2.0"
ethers-providers = "2.0"
Comment on lines -32 to -33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

log = "0.4"
nybbles = { version = "0.2.1", features = ["serde"] }
once_cell = "1.19"
revm = { version = "10.0", default-features = false, features = ["std"] }
serde = "1.0"
serde_json = "1.0"
test-log = "0.2.15"
thiserror = "1.0"
tokio = { version = "1.35" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
url = { version = "2.5" }
6 changes: 3 additions & 3 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ repository = { workspace = true }
anyhow = "1.0"

[dependencies]
alloy-sol-types = { workspace = true }
alloy = { workspace = true, features = ["sol-types", "contract"] }
anyhow = { workspace = true }
ethers = { version = "2.0", features = ["rustls", "ws"] }
risc0-zkvm = { workspace = true }

[dev-dependencies]
hex = "0.4"
regex = "1.10"
tokio = { version = "1", features = ["macros", "rt"] }
tokio = { workspace = true, features = ["macros", "rt"] }

[lib]
doctest = false
Expand Down
41 changes: 0 additions & 41 deletions contracts/build.rs

This file was deleted.

20 changes: 13 additions & 7 deletions contracts/src/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,37 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use alloy_sol_types::SolValue;
use alloy::sol_types::SolValue;
use anyhow::Result;
use risc0_zkvm::{sha::Digestible, Groth16ReceiptVerifierParameters};

/// ABI encoding of the seal.
pub fn abi_encode(seal: Vec<u8>) -> Result<Vec<u8>> {
pub fn abi_encode(seal: impl AsRef<[u8]>) -> Result<Vec<u8>> {
Ok(encode(seal)?.abi_encode())
}

/// encoding of the seal with selector.
pub fn encode(seal: Vec<u8>) -> Result<Vec<u8>> {
/// Encoding of a Groth16 seal by prefixing it with the verifier selector.
///
/// The verifier selector is determined from the first 4 bytes of the hash of the verifier
/// parameters including the Groth16 verification key and the control IDs that commit to the RISC
/// Zero circuits.
///
/// NOTE: Selector value of the current zkVM version is used. If you need to use a selector from a
/// different version of the zkVM, use the [encode_seal] method instead.
pub fn encode(seal: impl AsRef<[u8]>) -> Result<Vec<u8>> {
let verifier_parameters_digest = Groth16ReceiptVerifierParameters::default().digest();
let selector = &verifier_parameters_digest.as_bytes()[..4];
// Create a new vector with the capacity to hold both selector and seal
let mut selector_seal = Vec::with_capacity(selector.len() + seal.len());
let mut selector_seal = Vec::with_capacity(selector.len() + seal.as_ref().len());
selector_seal.extend_from_slice(selector);
selector_seal.extend_from_slice(&seal);
selector_seal.extend_from_slice(seal.as_ref());

Ok(selector_seal)
}

#[cfg(test)]
mod tests {
use anyhow::anyhow;
use ethers::utils::hex;
use regex::Regex;

use super::*;
Expand Down
44 changes: 35 additions & 9 deletions contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,41 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use ethers::prelude::*;

abigen!(
IRiscZeroVerifier,
"$OUT_DIR/IRiscZeroVerifier.sol/IRiscZeroVerifier.json"
);
abigen!(
RiscZeroGroth16Verifier,
"$OUT_DIR/RiscZeroGroth16Verifier.sol/RiscZeroGroth16Verifier.json"
alloy::sol!(
#![sol(rpc, all_derives)]
"src/IRiscZeroVerifier.sol"
);

pub mod groth16;

use anyhow::{bail, Result};
use risc0_zkvm::{sha::Digestible, InnerReceipt};

/// Encode the seal of the given receipt for use with EVM smart contract verifiers.
///
/// Appends the verifier selector, determined from the first 4 bytes of the verifier parameters
/// including the Groth16 verification key and the control IDs that commit to the RISC Zero
/// circuits.
pub fn encode_seal(receipt: &risc0_zkvm::Receipt) -> Result<Vec<u8>> {
let seal = match receipt.inner.clone() {
InnerReceipt::Fake(receipt) => {
let seal = receipt.claim.digest().as_bytes().to_vec();
let selector = &[0u8; 4];
// Create a new vector with the capacity to hold both selector and seal
let mut selector_seal = Vec::with_capacity(selector.len() + seal.len());
selector_seal.extend_from_slice(selector);
selector_seal.extend_from_slice(&seal);
selector_seal
}
InnerReceipt::Groth16(receipt) => {
let selector = &receipt.verifier_parameters.as_bytes()[..4];
// Create a new vector with the capacity to hold both selector and seal
let mut selector_seal = Vec::with_capacity(selector.len() + receipt.seal.len());
selector_seal.extend_from_slice(selector);
selector_seal.extend_from_slice(receipt.seal.as_ref());
selector_seal
}
_ => bail!("Unsupported receipt type"),
};
Ok(seal)
}
8 changes: 5 additions & 3 deletions examples/erc20-counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ risc0-build = { git = "https://github.com/risc0/risc0", branch = "main", feature
risc0-zkvm = { git = "https://github.com/risc0/risc0", branch = "main", default-features = false }
risc0-zkp = { git = "https://github.com/risc0/risc0", branch = "main", default-features = false }

alloy-primitives = { version = "0.7", default-features = false, features = ["rlp", "serde", "std"] }
alloy = { version = "0.2.1", features = ["full"] }
alloy-primitives = { version = "0.7", features = ["rlp", "serde", "std"] }
alloy-sol-types = { version = "0.7" }
anyhow = { version = "1.0.75" }
bincode = { version = "1.3" }
bytemuck = { version = "1.14" }
ethers = { version = "2.0" }
clap = { version = "4.5" }
hex = { version = "0.4" }
log = { version = "0.4" }
erc20-counter-methods = { path = "./methods" }
serde = { version = "1.0", features = ["derive", "std"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tokio = { version = "1.39", features = ["full"] }
url = { version = "2.5" }

[profile.release]
debug = 1
Expand Down
29 changes: 6 additions & 23 deletions examples/erc20-counter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,10 @@ The contract includes functionality to query the current value of the counter at

## Dependencies

First, [install Rust] and [Foundry], and then restart your terminal.
Wollac marked this conversation as resolved.
Show resolved Hide resolved

```sh
# Install Rust
curl https://sh.rustup.rs -sSf | sh
# Install Foundry
curl -L https://foundry.paradigm.xyz | bash
```

Next, you will need to install the `cargo risczero` tool.
We'll use [`cargo binstall`][cargo-binstall] to get `cargo-risczero` installed, and then install the `risc0` toolchain.
See [RISC Zero installation] for more details.

```sh
cargo install cargo-binstall
cargo binstall cargo-risczero
cargo risczero install
```

Now you have all the tools you need to develop and deploy an application with [RISC Zero].
To get started, you need to have the following installed:
- [Rust]
- [Foundry]
- [RISC Zero]

### Configuring Bonsai

Expand All @@ -73,11 +57,10 @@ When you're ready, follow the [deployment guide] to get your application running

[Foundry]: https://getfoundry.sh/
[Groth16 SNARK proof]: https://www.risczero.com/news/on-chain-verification
[RISC Zero installation]: https://dev.risczero.com/api/zkvm/install
[RISC Zero]: https://www.risczero.com/
[RISC Zero]: https://dev.risczero.com/api/zkvm/install
[Sepolia]: https://www.alchemy.com/overviews/sepolia-testnet
[cargo-binstall]: https://github.com/cargo-bins/cargo-binstall#cargo-binaryinstall
[deployment guide]: ./deployment-guide.md
[install Rust]: https://doc.rust-lang.org/cargo/getting-started/installation.html
[Rust]: https://doc.rust-lang.org/cargo/getting-started/installation.html
[Counter]: ./contracts/Counter.sol
[Steel]: https://www.risczero.com/blog/introducing-steel
9 changes: 4 additions & 5 deletions examples/erc20-counter/apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ version = { workspace = true }
edition = { workspace = true }

[dependencies]
alloy = { workspace = true }
alloy-primitives = { workspace = true }
alloy-sol-types = { workspace = true }
anyhow = { workspace = true }
clap = { version = "4.0", features = ["derive", "env"] }
clap = { workspace = true, features = ["derive", "env"] }
erc20-counter-methods = { workspace = true }
ethers = { workspace = true }
log = { workspace = true }
risc0-ethereum-contracts = { workspace = true }
risc0-steel = { workspace = true, features = ["host"] }
risc0-zkvm = { workspace = true, features = ["client"] }
tokio = { version = "1.35", features = ["full"] }
tokio = { workspace = true }
tracing-subscriber = { workspace = true }
url = { workspace = true }
14 changes: 4 additions & 10 deletions examples/erc20-counter/apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ cargo run --bin publisher
```text
$ cargo run --bin publisher -- --help

Usage: publisher --chain-id <CHAIN_ID> --eth-wallet-private-key <ETH_WALLET_PRIVATE_KEY> --rpc-url <RPC_URL> --contract <CONTRACT> --account <ACCOUNT>
Usage: publisher --eth-wallet-private-key <ETH_WALLET_PRIVATE_KEY> --rpc-url <RPC_URL> --contract <CONTRACT> --token <TOKEN> --account <ACCOUNT>

Options:
--chain-id <CHAIN_ID>
Ethereum chain ID
--eth-wallet-private-key <ETH_WALLET_PRIVATE_KEY>
Ethereum Node endpoint [env: ETH_WALLET_PRIVATE_KEY=0x2a5369d12693b5a8c4e1d0e85788bea5ccb1c90fb6f82bb33a25a216e6cce071]
Ethereum Node endpoint [env: ETH_WALLET_PRIVATE_KEY=]
--rpc-url <RPC_URL>
Ethereum Node endpoint [env: RPC_URL=]
--contract <CONTRACT>
Counter's contract address on Ethereum
--token <TOKEN>
ERC20 contract address on Ethereum
--account <ACCOUNT>
Account address to read the balance_of on Ethereum
-h, --help
Expand All @@ -34,11 +34,5 @@ Options:
Print version
```

## Library

We provide a small rust [library] containing utility functions to help with sending
transactions to a deployed app contract on Ethereum.

[publisher]: ./src/bin/publisher.rs
[library]: ./src/lib.rs
[Counter]: ../contracts/Counter.sol
Loading
Loading