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

encoding/decoding for saffron data #2955

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 35 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ members = [
"utils",
"internal-tracing",
"ivc",
"folding"
"folding",
"saffron"
]
resolver = "2"

Expand Down Expand Up @@ -96,6 +97,7 @@ o1-utils = { path = "./utils", version = "0.1.0" }
o1vm = { path = "./o1vm", version = "0.1.0" }
optimism = { path = "./optimism", version = "0.1.0" }
poly-commitment = { path = "./poly-commitment", version = "0.1.0" }
saffron = { path = "./poly-commitment", version = "0.1.0" }
signer = { path = "./signer", version = "0.1.0" }
turshi = { path = "./turshi", version = "0.1.0" }
utils = { path = "./utils", version = "0.1.0" }
Expand Down
3 changes: 3 additions & 0 deletions saffron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
proptest-regressions
fixtures/lorem.bin
fixtures/lorem-decoded.txt
30 changes: 30 additions & 0 deletions saffron/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "saffron"
version = "0.1.0"
description = "He who controls the spice controls the universe."
repository = "https://github.com/o1-labs/proof-systems"
homepage = "https://o1-labs.github.io/proof-systems/"
documentation = "https://o1-labs.github.io/proof-systems/rustdoc/"
readme = "README.md"
edition = "2021"
license = "Apache-2.0"

# [lib]
# path = "src/lib.rs"

[[bin]]
name = "saffron"
path = "src/main.rs"

[dependencies]
anyhow = "1.0"
ark-ff.workspace = true
ark-serialize = { workspace = true, features = ["derive"]}
clap = { workspace = true, features = ["derive"] }
mina-curves.workspace = true
o1-utils.workspace = true


[dev-dependencies]
ark-std.workspace = true
proptest.workspace = true
1 change: 1 addition & 0 deletions saffron/fixtures/lorem.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
42 changes: 42 additions & 0 deletions saffron/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use clap::{arg, Parser};

#[derive(Parser, Debug, Clone)]
pub struct EncodeFileArgs {
#[arg(long, short = 'i', value_name = "FILE", help = "input file")]
pub input: String,

#[arg(
long,
short = 'o',
value_name = "FILE",
help = "output file (encoded as field elements)"
)]
pub output: String,
}

#[derive(Parser, Debug, Clone)]
pub struct DecodeFileArgs {
#[arg(
long,
short = 'i',
value_name = "FILE",
help = "input file (encoded as field elements)"
)]
pub input: String,

#[arg(long, short = 'o', value_name = "FILE", help = "output file")]
pub output: String,
}

#[derive(Parser, Debug, Clone)]
#[command(
name = "saffron",
version = "0.1",
about = "saffron - a data availability layer"
)]
pub enum Commands {
#[command(name = "encode")]
Encode(EncodeFileArgs),
#[command(name = "decode")]
Decode(DecodeFileArgs),
}
3 changes: 3 additions & 0 deletions saffron/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod serialization;

pub mod cli;
40 changes: 40 additions & 0 deletions saffron/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use anyhow::Result;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use clap::Parser;
use mina_curves::pasta::Fp;
use saffron::{cli, serialization::FieldBlob};
use std::{
fs::File,
io::{Read, Write},
};

fn decode_file(args: cli::DecodeFileArgs) -> Result<()> {
let mut file = File::open(args.input)?;
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
let blob: FieldBlob<Fp> = FieldBlob::<Fp>::deserialize_compressed(&buf[..])?;
let data = FieldBlob::<Fp>::decode(blob);
let mut writer = File::create(args.output)?;
writer.write_all(&data)?;
Ok(())
}

fn encode_file(args: cli::EncodeFileArgs) -> Result<()> {
let mut file = File::open(args.input)?;
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
let blob = FieldBlob::<Fp>::encode(&buf);
let mut bytes_to_write = Vec::with_capacity(buf.len());
blob.serialize_compressed(&mut bytes_to_write)?;
let mut writer = File::create(args.output)?;
writer.write_all(&bytes_to_write)?;
Ok(())
}

pub fn main() -> Result<()> {
let args = cli::Commands::parse();
match args {
cli::Commands::Encode(args) => encode_file(args),
cli::Commands::Decode(args) => decode_file(args),
}
}
Loading
Loading