-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2955 from o1-labs/martin/saffron-skeleton
encoding/decoding for saffron data
- Loading branch information
Showing
10 changed files
with
307 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
proptest-regressions | ||
fixtures/lorem.bin | ||
fixtures/lorem-decoded.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod serialization; | ||
|
||
pub mod cli; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} |
Oops, something went wrong.