Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
feat(zk_toolbox): Add prover init command (matter-labs#2298)
Browse files Browse the repository at this point in the history
## What ❔

Add prover init command.

Initializes proof object storage settings.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
  • Loading branch information
matias-gonz authored Jun 28, 2024
1 parent 70b3a8a commit 159af3c
Show file tree
Hide file tree
Showing 19 changed files with 2,985 additions and 562 deletions.
22 changes: 20 additions & 2 deletions core/lib/protobuf_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ mod utils;
mod vm_runner;
mod wallets;

use std::str::FromStr;
use std::{path::PathBuf, str::FromStr};

use zksync_protobuf::ProtoRepr;
use anyhow::Context;
use zksync_protobuf::{serde::serialize_proto, ProtoRepr};
use zksync_types::{H160, H256};

fn parse_h256(bytes: &str) -> anyhow::Result<H256> {
Expand All @@ -51,3 +52,20 @@ fn parse_h160(bytes: &str) -> anyhow::Result<H160> {
pub fn read_optional_repr<P: ProtoRepr>(field: &Option<P>) -> anyhow::Result<Option<P::Type>> {
field.as_ref().map(|x| x.read()).transpose()
}

pub fn decode_yaml_repr<T: ProtoRepr>(
path: &PathBuf,
deny_unknown_fields: bool,
) -> anyhow::Result<T::Type> {
let yaml = std::fs::read_to_string(path).with_context(|| path.display().to_string())?;
let d = serde_yaml::Deserializer::from_str(&yaml);
let this: T = zksync_protobuf::serde::deserialize_proto_with_options(d, deny_unknown_fields)?;
this.read()
}

pub fn encode_yaml_repr<T: ProtoRepr>(value: &T::Type) -> anyhow::Result<Vec<u8>> {
let mut buffer = vec![];
let mut s = serde_yaml::Serializer::new(&mut buffer);
serialize_proto(&T::build(value), &mut s)?;
Ok(buffer)
}
18 changes: 2 additions & 16 deletions core/lib/protobuf_config/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use std::{path::PathBuf, str::FromStr};

use anyhow::Context;
use zksync_protobuf::{
testonly::{test_encode_all_formats, ReprConv},
ProtoRepr,
};
use zksync_protobuf::testonly::{test_encode_all_formats, ReprConv};

use crate::proto;
use crate::{decode_yaml_repr, proto};

/// Tests config <-> proto (boilerplate) conversions.
#[test]
Expand Down Expand Up @@ -45,16 +41,6 @@ fn test_encoding() {
test_encode_all_formats::<ReprConv<proto::observability::Observability>>(rng);
}

pub fn decode_yaml_repr<T: ProtoRepr>(
path: &PathBuf,
deny_unknown_fields: bool,
) -> anyhow::Result<T::Type> {
let yaml = std::fs::read_to_string(path).with_context(|| path.display().to_string())?;
let d = serde_yaml::Deserializer::from_str(&yaml);
let this: T = zksync_protobuf::serde::deserialize_proto_with_options(d, deny_unknown_fields)?;
this.read()
}

#[test]
fn verify_file_parsing() {
let base_path = PathBuf::from_str("../../../etc/env/file_based/").unwrap();
Expand Down
Loading

0 comments on commit 159af3c

Please sign in to comment.