diff --git a/binary.nu b/.nushell/binary.nu similarity index 100% rename from binary.nu rename to .nushell/binary.nu diff --git a/.nushell/cargo.nu b/.nushell/cargo.nu new file mode 100644 index 0000000000000000000000000000000000000000..4314a32647a49f247cb9e96d9b350d27acaaefac --- /dev/null +++ b/.nushell/cargo.nu @@ -0,0 +1,55 @@ +use std log +use error.nu "error throw" + +def get-workspace-bins []: nothing -> table<name: string, toml: path> { + open Cargo.toml + | get workspace.members + | each { path join "Cargo.toml" } + | wrap toml + | insert name { get toml | open | get package.name } +} + +def get-workspace-bin-names []: nothing -> table<value: string, description: string> { + get-workspace-bins | each {{ + value: $in.name, + description: ($in.toml | open | get package.description? | default "") + }} +} + +# run a binary from the workspace +export def --wrapped "cargo bin" [ + bin: string@get-workspace-bin-names, # the name of the binary to run, press tab to autocomplete + --debug, # run in debug mode + --build, # build the binary in the specified mode + ...args: string, # arguments to pass to the binary +] { + let bin_span = (metadata $bin).span + + let bins = get-workspace-bins + let bin = $bins | where name == $bin | into record + + if $build { + if $debug { + cargo build --manifest-path $bin.toml + } else { + cargo build --release --manifest-path $bin.toml + } + } + + let target = if $debug { + "debug" + } else { + "release" + } + + let bin = "target" | path join $target $bin.name + if not ($bin | path exists) { + error throw { + err: "binary not found", + label: "hasn't been compiled, compile it with --build", + span: $bin_span, + } + } + + ^$bin ...$args +} diff --git a/scripts/color.nu b/.nushell/color.nu similarity index 93% rename from scripts/color.nu rename to .nushell/color.nu index b97c134b39df55108041c3f990caafbe6fca3284..54baf9541e2e9a5101942b16a161331640e63754 100644 --- a/scripts/color.nu +++ b/.nushell/color.nu @@ -1,19 +1,11 @@ +use error.nu "error throw" + export const WHITE = { r: 1.0, g: 1.0, b: 1.0 } export const BLACK = { r: 0.0, g: 0.0, b: 0.0 } export const RED = { r: 1.0, g: 0.0, b: 0.0 } export const GREEN = { r: 0.0, g: 1.0, b: 0.0 } export const BLUE = { r: 0.0, g: 0.0, b: 1.0 } -def "error throw" [err: record<err: string, label: string, span: record<start: int, end: int>>] { - error make { - msg: $"(ansi red_bold)($err.err)(ansi reset)", - label: { - text: $err.label, - span: $err.span, - }, - } -} - export def "color from-floats" [ r: float, g: float, diff --git a/.nushell/error.nu b/.nushell/error.nu new file mode 100644 index 0000000000000000000000000000000000000000..34e30b9b1b8465f85645414dda6a451f4b2ea991 --- /dev/null +++ b/.nushell/error.nu @@ -0,0 +1,9 @@ +export def "error throw" [err: record<err: string, label: string, span: record<start: int, end: int>>] { + error make { + msg: $"(ansi red_bold)($err.err)(ansi reset)", + label: { + text: $err.label, + span: $err.span, + }, + } +} diff --git a/scripts/formats.nu b/.nushell/formats.nu similarity index 100% rename from scripts/formats.nu rename to .nushell/formats.nu diff --git a/scripts/fs.nu b/.nushell/fs.nu similarity index 100% rename from scripts/fs.nu rename to .nushell/fs.nu diff --git a/scripts/math.nu b/.nushell/math.nu similarity index 100% rename from scripts/math.nu rename to .nushell/math.nu diff --git a/scripts/parse.nu b/.nushell/parse.nu similarity index 100% rename from scripts/parse.nu rename to .nushell/parse.nu diff --git a/scripts/plot.nu b/.nushell/plot.nu similarity index 100% rename from scripts/plot.nu rename to .nushell/plot.nu diff --git a/scripts/venv.nu b/.nushell/venv.nu similarity index 100% rename from scripts/venv.nu rename to .nushell/venv.nu diff --git a/Cargo.toml b/Cargo.toml index c30b05a23028ad2aa71bcac21e5eb49f4cecdfe1..e839791511f54bafbcf527a52763451292ffac3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,70 +20,11 @@ tracing-subscriber = "0.3.17" ark-bls12-381 = "0.4.0" rand = "0.8.5" -[dev-dependencies] -clap = { version = "4.5.4", features = ["derive"] } -indicatif = "0.17.8" -plnk = { git = "https://gitlab.isae-supaero.fr/a.stevan/plnk", tag = "0.7.0", version = "0.7.0" } -# all the curve dependencies below are used by the `curves` example -ark-bls12-377 = "0.4.0" -ark-bls12-381 = "0.4.0" -ark-bn254 = "0.4.0" -ark-bw6-761 = "0.4.0" -ark-cp6-782 = "0.4.0" -ark-curve25519 = "0.4.0" -ark-ed-on-bls12-377 = "0.4.0" -ark-ed-on-bls12-381 = "0.4.0" -ark-ed-on-bls12-381-bandersnatch = "0.4.0" -ark-ed-on-bn254 = "0.4.0" -ark-ed-on-bw6-761 = "0.4.0" -ark-ed-on-cp6-782 = "0.4.0" -ark-ed-on-mnt4-298 = "0.4.0" -ark-ed-on-mnt4-753 = "0.4.0" -ark-ed25519 = "0.4.0" -ark-mnt4-298 = "0.4.0" -ark-mnt4-753 = "0.4.0" -ark-mnt6-298 = "0.4.0" -ark-mnt6-753 = "0.4.0" -ark-pallas = "0.4.0" -ark-poly-commit = "0.4.0" -ark-secp256k1 = "0.4.0" -ark-secp256r1 = "0.4.0" -ark-secp384r1 = "0.4.0" -ark-secq256k1 = "0.4.0" -ark-vesta = "0.4.0" - -[[example]] -name = "bench_commit" -path = "examples/benches/commit.rs" - -[[example]] -name = "bench_setup_size" -path = "examples/benches/setup_size.rs" - -[[example]] -name = "bench_field_operations" -path = "examples/benches/operations/field.rs" - -[[example]] -name = "bench_curve_group_operations" -path = "examples/benches/operations/curve_group.rs" - -[[example]] -name = "bench_setup" -path = "examples/benches/setup.rs" - -[[example]] -name = "bench_linalg" -path = "examples/benches/linalg.rs" - -[[example]] -name = "bench_recoding" -path = "examples/benches/recoding.rs" - -[[example]] -name = "bench_fec" -path = "examples/benches/fec.rs" - -[[example]] -name = "inbreeding" -path = "examples/inbreeding/mod.rs" +[workspace] +members = [ + "benchmarks", + "bins/curves", + "bins/inbreeding", + "bins/rank", + "bins/rng", +] diff --git a/README.md b/README.md index cd4f411ccd8a417b3a65d6a30642d6a91139a682..3c0dadab8dfd07197ef47e8acf6436a572837fc0 100644 --- a/README.md +++ b/README.md @@ -20,5 +20,14 @@ tests for the binary application can also be run with nu tests/cli.nu ``` +## other binaries +Komodo provides a bunch of other binaries that might be interesting of useful to use. + +The easiest is to use the `cargo.nu` Nushell module as follows +```bash +use .nushell/cargo.nu "cargo bin" +help cargo bin +``` + ## the benchmarks -see [the `README`](examples/benches/README.md) +see [the `README`](benchmarks/README.md) diff --git a/scripts/commit/plot.nu b/benchmarks/.nushell/commit/plot.nu similarity index 86% rename from scripts/commit/plot.nu rename to benchmarks/.nushell/commit/plot.nu index d89ad560711f30075f602e51e978dcaa31f0a0e7..c0b9e95b799859de2f6e6afef3afc2da9727fad7 100644 --- a/scripts/commit/plot.nu +++ b/benchmarks/.nushell/commit/plot.nu @@ -1,6 +1,6 @@ -use ../math.nu * -use ../fs.nu check-file -use ../plot.nu [ into-axis-options, COMMON_OPTIONS, gplt ] +use ../../../.nushell/math.nu * +use ../../../.nushell/fs.nu check-file +use ../../../.nushell/plot.nu [ into-axis-options, COMMON_OPTIONS, gplt ] export def main [data: path, --save: path] { check-file $data --span (metadata $data).span diff --git a/scripts/commit/run.nu b/benchmarks/.nushell/commit/run.nu similarity index 86% rename from scripts/commit/run.nu rename to benchmarks/.nushell/commit/run.nu index 61712343a88026b10b2b00825309ce92d7956cac..dca9727f35da8c225fe5fcb6c0b4489bc78630d1 100644 --- a/scripts/commit/run.nu +++ b/benchmarks/.nushell/commit/run.nu @@ -10,7 +10,7 @@ export def main [ return } - cargo run --release --example bench_commit -- ...[ + cargo run --release --package benchmarks --bin commit -- ...[ --nb-measurements $nb_measurements ...$input --curves ...$curves diff --git a/scripts/fec/plot.nu b/benchmarks/.nushell/fec/plot.nu similarity index 97% rename from scripts/fec/plot.nu rename to benchmarks/.nushell/fec/plot.nu index e8b90bdfcc69d031d7019eea5901848a81d9d797..1d6efeb62c9a638ce293bb99c04a26ab599c71f3 100644 --- a/scripts/fec/plot.nu +++ b/benchmarks/.nushell/fec/plot.nu @@ -1,7 +1,7 @@ -use ../math.nu * -use ../plot.nu [ into-axis-options, COMMON_OPTIONS ] -use ../fs.nu check-file -use ../plot.nu gplt +use ../../../.nushell/math.nu * +use ../../../.nushell/plot.nu [ into-axis-options, COMMON_OPTIONS ] +use ../../../.nushell/fs.nu check-file +use ../../../.nushell/plot.nu gplt export def encoding [data: path, --save: path] { check-file $data --span (metadata $data).span diff --git a/scripts/fec/run.nu b/benchmarks/.nushell/fec/run.nu similarity index 85% rename from scripts/fec/run.nu rename to benchmarks/.nushell/fec/run.nu index a905ac891c1287356a29123d47259236afee2879..8eccebecf59ad2ca466d926c0829ac4a15703ec8 100644 --- a/scripts/fec/run.nu +++ b/benchmarks/.nushell/fec/run.nu @@ -1,4 +1,4 @@ -use ../formats.nu * +use ../../../.nushell/formats.nu * export def main [ --output: path = "./fec.ndjson", @@ -16,7 +16,7 @@ export def main [ "" out> $output for k in $ks { - cargo run --release --example bench_fec -- ...[ + cargo run --release --package benchmarks --bin fec -- ...[ --nb-measurements $nb_measurements ...$input --encoding vandermonde diff --git a/scripts/recoding/plot.nu b/benchmarks/.nushell/recoding/plot.nu similarity index 83% rename from scripts/recoding/plot.nu rename to benchmarks/.nushell/recoding/plot.nu index c803fcd48fe45e5ae75bfd97b6d8b0520fc13730..64657f1a6323ecbc9355e8e97b3442fde3e3b3e2 100644 --- a/scripts/recoding/plot.nu +++ b/benchmarks/.nushell/recoding/plot.nu @@ -1,7 +1,7 @@ -use ../math.nu * -use ../plot.nu [ into-axis-options, COMMON_OPTIONS ] -use ../fs.nu check-file -use ../plot.nu gplt +use ../../../.nushell/math.nu * +use ../../../.nushell/plot.nu [ into-axis-options, COMMON_OPTIONS ] +use ../../../.nushell/fs.nu check-file +use ../../../.nushell/plot.nu gplt export def main [data: path, --save: path] { check-file $data --span (metadata $data).span diff --git a/scripts/recoding/run.nu b/benchmarks/.nushell/recoding/run.nu similarity index 83% rename from scripts/recoding/run.nu rename to benchmarks/.nushell/recoding/run.nu index a983ef9ede77895898b58602cc86e15e9c348ace..0bd79e73104d0d7ef463775a8e22d117cd638e72 100644 --- a/scripts/recoding/run.nu +++ b/benchmarks/.nushell/recoding/run.nu @@ -1,4 +1,4 @@ -use ../formats.nu * +use ../../../.nushell/formats.nu * export def main [ --output: path = "./recoding.ndjson", @@ -16,7 +16,7 @@ export def main [ "" out> $output for k in $ks { - cargo run --release --example bench_recoding -- ...[ + cargo run --release --package benchmarks --bin recoding -- ...[ --nb-measurements $nb_measurements ...$input --shards $k diff --git a/scripts/setup/plot.nu b/benchmarks/.nushell/setup/plot.nu similarity index 89% rename from scripts/setup/plot.nu rename to benchmarks/.nushell/setup/plot.nu index a6baeebaeb64f944bb1ae992b5e2d2f0a3862a4f..c2ce80e4f5233d7a4f3adf2cf390e97557d2855d 100644 --- a/scripts/setup/plot.nu +++ b/benchmarks/.nushell/setup/plot.nu @@ -1,6 +1,6 @@ -use ../math.nu * -use ../fs.nu check-file -use ../plot.nu [ into-axis-options, COMMON_OPTIONS, gplt ] +use ../../../.nushell/math.nu * +use ../../../.nushell/fs.nu check-file +use ../../../.nushell/plot.nu [ into-axis-options, COMMON_OPTIONS, gplt ] export def main [data: path, --save: path] { check-file $data --span (metadata $data).span diff --git a/scripts/setup/run.nu b/benchmarks/.nushell/setup/run.nu similarity index 86% rename from scripts/setup/run.nu rename to benchmarks/.nushell/setup/run.nu index 1631551a9b363e0b09972edcd753e6c660174221..50862c3dd79aa6bbaf5fb293fe4bf915a705a4be 100644 --- a/scripts/setup/run.nu +++ b/benchmarks/.nushell/setup/run.nu @@ -10,7 +10,7 @@ export def main [ return } - cargo run --release --example bench_setup -- ...[ + cargo run --release --package benchmarks --bin setup -- ...[ --nb-measurements $nb_measurements ...$input --curves ...$curves diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..a0b4e825bcfee0dddbbf93b0006221de0d328854 --- /dev/null +++ b/benchmarks/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "benchmarks" +version = "0.1.0" +edition = "2021" + +[dependencies] +ark-bls12-381 = "0.4.0" +ark-bn254 = "0.4.0" +ark-ec = "0.4.2" +ark-ff = "0.4.2" +ark-pallas = "0.4.0" +ark-poly = "0.4.0" +ark-poly-commit = "0.4.0" +ark-serialize = "0.4.0" +ark-secp256k1 = "0.4.0" +ark-secp256r1 = "0.4.0" +ark-std = "0.4.0" +ark-vesta = "0.4.0" +clap = { version = "4.5.4", features = ["derive"] } +komodo = { version = "0.2.0", path = ".." } +plnk = { git = "https://gitlab.isae-supaero.fr/a.stevan/plnk", tag = "0.7.0", version = "0.7.0" } +rand = "0.8.5" diff --git a/examples/benches/README.md b/benchmarks/README.md similarity index 76% rename from examples/benches/README.md rename to benchmarks/README.md index e8cb4e5d14f3825bc1f2a35f712c56ec0b805966..4dfeffaf2cfc45dcf1f448e0b48cb5460e3f7abc 100644 --- a/examples/benches/README.md +++ b/benchmarks/README.md @@ -2,8 +2,8 @@ - install [GPLT](https://gitlab.isae-supaero.fr/a.stevan/gplt) ```nushell -use scripts/math.nu * -use scripts/formats.nu * +use .nushell/math.nu * +use .nushell/formats.nu * ``` ## atomic operations @@ -12,7 +12,7 @@ cargo run --release --example bench_field_operations -- --nb-measurements 1000 o cargo run --release --example bench_curve_group_operations -- --nb-measurements 1000 out> curve_group.ndjson ``` ```nushell -use scripts/parse.nu read-atomic-ops +use .nushell/parse.nu read-atomic-ops gplt multi_bar --title "simple field operations" -l "time (in ns)" ( open field.ndjson @@ -77,47 +77,47 @@ for graph in [ ## trusted setup ```nushell -use scripts/setup/run.nu; seq 0 13 | each { 2 ** $in } | run --output setup.ndjson --curves [ bls12381, pallas, bn254 ] +use .nushell/setup/run.nu; seq 0 13 | each { 2 ** $in } | run --output setup.ndjson --curves [ bls12381, pallas, bn254 ] ``` ```nushell -use ./scripts/setup/plot.nu; plot setup.ndjson +use ./.nushell/setup/plot.nu; plot setup.ndjson ``` ## commit ```nushell -use scripts/commit/run.nu; seq 0 13 | each { 2 ** $in } | run --output commit.ndjson --curves [bls12381, pallas, bn254 ] +use .nushell/commit/run.nu; seq 0 13 | each { 2 ** $in } | run --output commit.ndjson --curves [bls12381, pallas, bn254 ] ``` ```nushell -use ./scripts/commit/plot.nu; plot commit.ndjson +use ./.nushell/commit/plot.nu; plot commit.ndjson ``` ## end-to-end benchmarks ### recoding ```nushell -use scripts/recoding/run.nu +use .nushell/recoding/run.nu seq 0 18 | each { 512 * 2 ** $in } | run --ks [2, 4, 8, 16] --output recoding.ndjson --curves [ bls12381 ] ``` ```nushell -use ./scripts/recoding/plot.nu; plot recoding.ndjson +use ./.nushell/recoding/plot.nu; plot recoding.ndjson ``` ### FEC ```nushell -use scripts/fec/run.nu +use .nushell/fec/run.nu seq 0 18 | each { 512 * 2 ** $in } | run --ks [2, 4, 8, 16] --output fec.ndjson --curves [ bls12381 ] ``` ```nushell -use ./scripts/fec/plot.nu; plot encoding fec.ndjson -use ./scripts/fec/plot.nu; plot decoding fec.ndjson -use ./scripts/fec/plot.nu; plot e2e fec.ndjson +use ./.nushell/fec/plot.nu; plot encoding fec.ndjson +use ./.nushell/fec/plot.nu; plot decoding fec.ndjson +use ./.nushell/fec/plot.nu; plot e2e fec.ndjson ``` ## combined graph ```nushell -use ./scripts/fec/plot.nu; plot combined fec.ndjson --recoding recoding.ndjson +use ./.nushell/fec/plot.nu; plot combined fec.ndjson --recoding recoding.ndjson ``` ## ratio graph ```nushell -use ./scripts/fec/plot.nu; plot ratio fec.ndjson --recoding recoding.ndjson +use ./.nushell/fec/plot.nu; plot ratio fec.ndjson --recoding recoding.ndjson ``` diff --git a/examples/benches/commit.rs b/benchmarks/src/bin/commit.rs similarity index 100% rename from examples/benches/commit.rs rename to benchmarks/src/bin/commit.rs diff --git a/examples/benches/fec.rs b/benchmarks/src/bin/fec.rs similarity index 100% rename from examples/benches/fec.rs rename to benchmarks/src/bin/fec.rs diff --git a/examples/benches/linalg.rs b/benchmarks/src/bin/linalg.rs similarity index 100% rename from examples/benches/linalg.rs rename to benchmarks/src/bin/linalg.rs diff --git a/examples/benches/operations/curve_group.rs b/benchmarks/src/bin/operations/curve_group.rs similarity index 100% rename from examples/benches/operations/curve_group.rs rename to benchmarks/src/bin/operations/curve_group.rs diff --git a/examples/benches/operations/field.rs b/benchmarks/src/bin/operations/field.rs similarity index 100% rename from examples/benches/operations/field.rs rename to benchmarks/src/bin/operations/field.rs diff --git a/examples/benches/recoding.rs b/benchmarks/src/bin/recoding.rs similarity index 100% rename from examples/benches/recoding.rs rename to benchmarks/src/bin/recoding.rs diff --git a/examples/benches/setup.rs b/benchmarks/src/bin/setup.rs similarity index 100% rename from examples/benches/setup.rs rename to benchmarks/src/bin/setup.rs diff --git a/examples/benches/setup_size.rs b/benchmarks/src/bin/setup_size.rs similarity index 100% rename from examples/benches/setup_size.rs rename to benchmarks/src/bin/setup_size.rs diff --git a/bins/curves/Cargo.toml b/bins/curves/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..11dbf377bec67863695e4cd0051654a0efef807d --- /dev/null +++ b/bins/curves/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "curves" +version = "0.1.0" +edition = "2021" +description = "Explore Arkworks elliptic curves." + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ark-bls12-377 = "0.4.0" +ark-bls12-381 = "0.4.0" +ark-bn254 = "0.4.0" +ark-bw6-761 = "0.4.0" +ark-cp6-782 = "0.4.0" +ark-curve25519 = "0.4.0" +ark-ed-on-bls12-377 = "0.4.0" +ark-ed-on-bls12-381 = "0.4.0" +ark-ed-on-bls12-381-bandersnatch = "0.4.0" +ark-ed-on-bn254 = "0.4.0" +ark-ed-on-bw6-761 = "0.4.0" +ark-ed-on-cp6-782 = "0.4.0" +ark-ed-on-mnt4-298 = "0.4.0" +ark-ed-on-mnt4-753 = "0.4.0" +ark-ed25519 = "0.4.0" +ark-ff = "0.4.2" +ark-mnt4-298 = "0.4.0" +ark-mnt4-753 = "0.4.0" +ark-mnt6-298 = "0.4.0" +ark-mnt6-753 = "0.4.0" +ark-pallas = "0.4.0" +ark-poly-commit = "0.4.0" +ark-secp256k1 = "0.4.0" +ark-secp256r1 = "0.4.0" +ark-secp384r1 = "0.4.0" +ark-secq256k1 = "0.4.0" +ark-vesta = "0.4.0" diff --git a/bins/curves/README.md b/bins/curves/README.md new file mode 100644 index 0000000000000000000000000000000000000000..6d4da6aa8bc56726b567566f8619a0b1d7aad373 --- /dev/null +++ b/bins/curves/README.md @@ -0,0 +1,37 @@ +```shell +cargo run + | lines + | parse "{curve}: {fq} -> {fr}" + | into int fq fr + | insert x { (1 - $in.fr / $in.fq) * 100 | math round --precision 1 } +``` + +which gives the followin table + +| curve | fq | fr | x | +| -------------------------------- | --- | --- | ---- | +| ark_bls12_377 | 377 | 253 | 32.9 | +| ark_bls12_381 | 381 | 255 | 33.1 | +| ark_bn254 | 254 | 254 | 0 | +| ark_bw6_761 | 761 | 377 | 50.5 | +| ark_cp6_782 | 782 | 377 | 51.8 | +| ark_curve25519 | 255 | 253 | 0.8 | +| ark_ed25519 | 255 | 253 | 0.8 | +| ark_ed_on_bls12_377 | 253 | 251 | 0.8 | +| ark_ed_on_bls12_381 | 255 | 252 | 1.2 | +| ark_ed_on_bls12_381_bandersnatch | 255 | 253 | 0.8 | +| ark_ed_on_bn254 | 254 | 251 | 1.2 | +| ark_ed_on_bw6_761 | 377 | 374 | 0.8 | +| ark_ed_on_cp6_782 | 377 | 374 | 0.8 | +| ark_ed_on_mnt4_298 | 298 | 296 | 0.7 | +| ark_ed_on_mnt4_753 | 753 | 750 | 0.4 | +| ark_mnt4_298 | 298 | 298 | 0 | +| ark_mnt4_753 | 753 | 753 | 0 | +| ark_mnt6_298 | 298 | 298 | 0 | +| ark_mnt6_753 | 753 | 753 | 0 | +| ark_pallas | 255 | 255 | 0 | +| ark_secp256k1 | 256 | 256 | 0 | +| ark_secp256r1 | 256 | 256 | 0 | +| ark_secp384r1 | 384 | 384 | 0 | +| ark_secq256k1 | 256 | 256 | 0 | +| ark_vesta | 255 | 255 | 0 | diff --git a/bins/curves/src/main.rs b/bins/curves/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..037976ed47abea4fa592d6a560d99457d8c78080 --- /dev/null +++ b/bins/curves/src/main.rs @@ -0,0 +1,74 @@ +use ark_ff::PrimeField; + +fn show_curve<Fr: PrimeField, Fq: PrimeField>(name: &str) { + println!( + "{}: {} -> {}", + name, + Fq::MODULUS_BIT_SIZE, + Fr::MODULUS_BIT_SIZE + ); +} + +/// takes a sequence of curve crate names and calls the [`show_curve`] function +/// for you +/// +/// this macro accepts a trailling comma in case you have a big list that spans +/// over multiple lines, e.g. +/// +/// ## examples +/// ```rust +/// show_curve(ark_bls12_381) +/// ``` +/// or +/// ```rust +/// show_curve( +/// ark_bls12_381, +/// ark_bn254, +/// ark_pallas, +/// ark_vesta +/// ) +/// ``` +/// or +/// ```rust +/// show_curve( +/// ark_bls12_381, +/// ark_bn254, +/// ark_pallas, +/// ark_vesta, +/// ) +/// ``` +macro_rules! show_curve { + ($($c:ident),+ $(,)?) => { + $(show_curve::<$c::Fr, $c::Fq>(stringify!($c));)* + } +} + +fn main() { + show_curve!( + ark_bls12_377, + ark_bls12_381, + ark_bn254, + ark_bw6_761, + ark_cp6_782, + ark_curve25519, + ark_ed_on_bls12_377, + ark_ed_on_bls12_381, + ark_ed_on_bls12_381_bandersnatch, + ark_ed_on_bn254, + ark_ed_on_bw6_761, + ark_ed_on_cp6_782, + ark_ed_on_mnt4_298, + ark_ed_on_mnt4_753, + ark_ed25519, + ark_mnt4_298, + ark_mnt4_753, + ark_mnt6_298, + ark_mnt6_753, + ark_pallas, + ark_secp256k1, + ark_secp256r1, + ark_secp384r1, + ark_secq256k1, + ark_vesta, + ); +} diff --git a/bins/inbreeding/Cargo.toml b/bins/inbreeding/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..c8982f389c03592e9c7cae1ce70f4fc42e4b415b --- /dev/null +++ b/bins/inbreeding/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "inbreeding" +version = "0.1.0" +edition = "2021" +description = "Study the 'inbreeding' phenomenon in a system supporting 'recoding'." + +[dependencies] +komodo = { version = "0.2.0", path = "../.." } +ark-pallas = "0.4.0" +clap = { version = "4.5.4", features = ["derive"] } +rand = "0.8.5" +indicatif = "0.17.8" +ark-ff = "0.4.2" diff --git a/bins/inbreeding/README.md b/bins/inbreeding/README.md new file mode 100644 index 0000000000000000000000000000000000000000..08111b35fe79d23fda792094b60462b4ef430b80 --- /dev/null +++ b/bins/inbreeding/README.md @@ -0,0 +1,38 @@ +- build the example for best performance with [`inbreeding build`](./build.nu) +- run the experiment with [`inbreeding run`](./run.nu) +- plot the results with [`inbreeding plot`](./plot.nu) + +# Example +```bash +use ./bins/inbreeding +``` +```bash +const PRNG_SEED = 123 +const OPTS = { + nb_bytes: (10 * 1_024), + k: 10, + n: 20, + nb_measurements: 10, + nb_scenarii: 100, + measurement_schedule: 1, + measurement_schedule_start: 0, + max_t: 150, + strategies: [ + "single:1", + "double:0.5:1:2", + "single:2" + "double:0.5:2:3", + "single:3" + "single:5", + "single:10", + ], + environment: "fixed:0", +} +``` +```bash +inbreeding build +``` +```bash +inbreeding run --options $OPTS --prng-seed $PRNG_SEED +inbreeding plot ... --options { k: $OPTS.K } +``` diff --git a/bins/inbreeding/build.nu b/bins/inbreeding/build.nu new file mode 100644 index 0000000000000000000000000000000000000000..75de47de734055fae94aeaa185e9861cdcddcde6 --- /dev/null +++ b/bins/inbreeding/build.nu @@ -0,0 +1,4 @@ +export def main [] { + cd bins/inbreeding + cargo build --release +} diff --git a/bins/inbreeding/consts.nu b/bins/inbreeding/consts.nu new file mode 100644 index 0000000000000000000000000000000000000000..177d568cedaf2db37854e65516e47f9fa3a68afc --- /dev/null +++ b/bins/inbreeding/consts.nu @@ -0,0 +1,2 @@ +export const BIN = "./target/release/inbreeding" +export const CACHE = ($nu.home-path | path join .cache komodo inbreeding) diff --git a/scripts/inbreeding/mod.nu b/bins/inbreeding/mod.nu similarity index 100% rename from scripts/inbreeding/mod.nu rename to bins/inbreeding/mod.nu diff --git a/scripts/inbreeding/plot.nu b/bins/inbreeding/plot.nu similarity index 73% rename from scripts/inbreeding/plot.nu rename to bins/inbreeding/plot.nu index 4a7063538972bf139f0ed499cb926df4fada4a21..ec82be6295845000ee27dd5165f22887e73894da 100644 --- a/scripts/inbreeding/plot.nu +++ b/bins/inbreeding/plot.nu @@ -1,9 +1,8 @@ -#!/usr/bin/env nu - use std repeat -use ../plot.nu gplt -use ../color.nu * +use consts.nu +use ../../.nushell/plot.nu gplt +use ../../.nushell/color.nu * def "parse strategy" []: string -> record<type: string> { let s = $in @@ -40,8 +39,41 @@ def get-color []: int -> string { } } -export def main [data: path, --save: path, --options: record<k: int>] { - let data = open $data +def get-experiments []: nothing -> list<string> { + $consts.CACHE + | path join '*' '*' '*' + | into glob + | ls $in + | get name + | path split + | each { last 3 | str join "-" } +} + +export def main [ + experiment: string@get-experiments, # something of the form '<seed>-<timestamp>-<env>' + --save: path, + --options: record<k: int> +] { + let data = [$consts.CACHE, ($experiment | str replace --all '-' (char path_sep)), '*' ] + | path join + | into glob + | ls $in + | insert strategy { get name | path split | last } + | select name strategy + | insert diversity { + ls $in.name + | each { get name | open | lines } + | flatten + | parse "{x}, {y}" + | into float y + | group-by x --to-table + | update items { get y | math avg } + | rename --column { group: "x", items: "y" } + | into int x # NOTE: $.x needs to be converted to int here because + # `group-by --to-table` converts the grouping key to + # string + } + | reject name let l = $data.diversity.0 | length $data diff --git a/scripts/inbreeding/run.nu b/bins/inbreeding/run.nu similarity index 82% rename from scripts/inbreeding/run.nu rename to bins/inbreeding/run.nu index 8171f2975428bd213d93d3aa7e67edd611fee734..920b0a19fc9158078c46df92ec045b3c3dcf4f34 100644 --- a/scripts/inbreeding/run.nu +++ b/bins/inbreeding/run.nu @@ -1,5 +1,5 @@ -const BIN = "./target/release/examples/inbreeding" -const CACHE = ($nu.home-path | path join .cache komodo inbreeding) +use consts.nu +use ../../.nushell/cargo.nu "cargo bin" export def main [ --options: record< @@ -25,7 +25,7 @@ export def main [ let now = date now | format date "%s%f" for s in $options.strategies { - let output_dir = [ $CACHE, $"($prng_seed)", $now, $options.environment, $"($s)" ] | path join + let output_dir = [ $consts.CACHE, $"($prng_seed)", $now, $options.environment, $"($s)" ] | path join mkdir $output_dir print $"data will be dumped to `($output_dir)`" @@ -38,17 +38,14 @@ export def main [ | $"0x($in)" | into int # compute all the seeds for that strategy, one per scenario - let seeds = cargo run --release --example rng -- ...[ - -n $options.nb_scenarii - --prng-seed $prng_seed - ] + let seeds = cargo bin rng ...[ -n $options.nb_scenarii --prng-seed $prng_seed ] | lines | into int for i in 1..$options.nb_scenarii { let output = [ $output_dir, $"($i)" ] | path join - ^$BIN ...[ + ^$consts.BIN ...[ $options.nb_bytes, -k $options.k -n $options.n diff --git a/examples/inbreeding/environment.rs b/bins/inbreeding/src/environment.rs similarity index 100% rename from examples/inbreeding/environment.rs rename to bins/inbreeding/src/environment.rs diff --git a/examples/inbreeding/mod.rs b/bins/inbreeding/src/main.rs similarity index 88% rename from examples/inbreeding/mod.rs rename to bins/inbreeding/src/main.rs index 730e8f2411df4def13b4e5ee38a218548e6f0843..71beb012f7f0bc3b0351ef11e7aa2e87ee7bb097 100644 --- a/examples/inbreeding/mod.rs +++ b/bins/inbreeding/src/main.rs @@ -1,35 +1,3 @@ -/// - build the example for best performance with [`./../../scripts/inbreeding/build.nu`] -/// - run the experiment with [`./../../scripts/inbreeding/run.nu`] -/// - plot the results with [`./../../scripts/inbreeding/plot.nu`] -/// -/// # Example -/// ```nushell -/// use ./scripts/inbreeding -/// -/// let opts = { -/// nb_bytes: (10 * 1_024), -/// k: 10, -/// n: 20, -/// nb_measurements: 10, -/// nb_scenarii: 100, -/// measurement_schedule: 1, -/// max_t: 150, -/// strategies: [ -/// "single:1", -/// "double:0.5:1:2", -/// "single:2" -/// "double:0.5:2:3", -/// "single:3" -/// "single:5", -/// "single:10", -/// ], -/// environment: "fixed:0", -/// } -/// -/// inbreeding build -/// inbreeding run --output data/inbreeding.nuon --options $opts -/// inbreeding plot data/inbreeding.nuon --options { k: $opts.k } -/// ``` use std::process::exit; use ark_ff::PrimeField; diff --git a/examples/inbreeding/strategy.rs b/bins/inbreeding/src/strategy.rs similarity index 100% rename from examples/inbreeding/strategy.rs rename to bins/inbreeding/src/strategy.rs diff --git a/bins/rank/Cargo.toml b/bins/rank/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..4d504b93b143f865ba1b8059cc73fc46e67a7f53 --- /dev/null +++ b/bins/rank/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "rank" +version = "0.1.0" +edition = "2021" +description = "Compute the rank of a matrix." + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ark-bls12-381 = "0.4.0" +ark-ff = "0.4.2" +ark-std = "0.4.0" +komodo = { version = "0.2.0", path = "../.." } +rand = "0.8.5" diff --git a/examples/rank.rs b/bins/rank/src/main.rs similarity index 100% rename from examples/rank.rs rename to bins/rank/src/main.rs diff --git a/bins/rng/Cargo.toml b/bins/rng/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..39f70a07a8bc58a0012463ea4b4643578d459ecc --- /dev/null +++ b/bins/rng/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "rng" +version = "0.1.0" +edition = "2021" +description = "Generate random numbers from a seed." + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4.5.4", features = ["derive"] } +rand = "0.8.5" diff --git a/examples/rng.rs b/bins/rng/src/main.rs similarity index 100% rename from examples/rng.rs rename to bins/rng/src/main.rs diff --git a/examples/cli.nu b/examples/cli.nu index d04bd7102c0ff0e20cad7f1c89d9ae0f66939220..c0cc5c729713bab3834e42b1ccc34589f401e768 100755 --- a/examples/cli.nu +++ b/examples/cli.nu @@ -7,7 +7,7 @@ use ../komodo.nu [ "komodo reconstruct", "komodo ls", ] -use ../binary.nu [ "bytes from_int" ] +use ../.nushell/binary.nu [ "bytes from_int" ] use std assert diff --git a/examples/curves.rs b/examples/curves.rs deleted file mode 100644 index 07bbde08027410564448a5c28e2d3fb977c76585..0000000000000000000000000000000000000000 --- a/examples/curves.rs +++ /dev/null @@ -1,112 +0,0 @@ -//! example usage of this example code -//! ```shell -//! cargo run --example curves -//! | lines -//! | parse "{curve}: {fq} -> {fr}" -//! | into int fq fr -//! | insert x { (1 - $in.fr / $in.fq) * 100 | math round --precision 1 } -//! ``` -//! -//! which gives the followin table -//! -//! | curve | fq | fr | x | -//! | -------------------------------- | --- | --- | ---- | -//! | ark_bls12_377 | 377 | 253 | 32.9 | -//! | ark_bls12_381 | 381 | 255 | 33.1 | -//! | ark_bn254 | 254 | 254 | 0 | -//! | ark_bw6_761 | 761 | 377 | 50.5 | -//! | ark_cp6_782 | 782 | 377 | 51.8 | -//! | ark_curve25519 | 255 | 253 | 0.8 | -//! | ark_ed25519 | 255 | 253 | 0.8 | -//! | ark_ed_on_bls12_377 | 253 | 251 | 0.8 | -//! | ark_ed_on_bls12_381 | 255 | 252 | 1.2 | -//! | ark_ed_on_bls12_381_bandersnatch | 255 | 253 | 0.8 | -//! | ark_ed_on_bn254 | 254 | 251 | 1.2 | -//! | ark_ed_on_bw6_761 | 377 | 374 | 0.8 | -//! | ark_ed_on_cp6_782 | 377 | 374 | 0.8 | -//! | ark_ed_on_mnt4_298 | 298 | 296 | 0.7 | -//! | ark_ed_on_mnt4_753 | 753 | 750 | 0.4 | -//! | ark_mnt4_298 | 298 | 298 | 0 | -//! | ark_mnt4_753 | 753 | 753 | 0 | -//! | ark_mnt6_298 | 298 | 298 | 0 | -//! | ark_mnt6_753 | 753 | 753 | 0 | -//! | ark_pallas | 255 | 255 | 0 | -//! | ark_secp256k1 | 256 | 256 | 0 | -//! | ark_secp256r1 | 256 | 256 | 0 | -//! | ark_secp384r1 | 384 | 384 | 0 | -//! | ark_secq256k1 | 256 | 256 | 0 | -//! | ark_vesta | 255 | 255 | 0 | -use ark_ff::PrimeField; - -fn show_curve<Fr: PrimeField, Fq: PrimeField>(name: &str) { - println!( - "{}: {} -> {}", - name, - Fq::MODULUS_BIT_SIZE, - Fr::MODULUS_BIT_SIZE - ); -} - -/// takes a sequence of curve crate names and calls the [`show_curve`] function -/// for you -/// -/// this macro accepts a trailling comma in case you have a big list that spans -/// over multiple lines, e.g. -/// -/// ## examples -/// ```rust -/// show_curve(ark_bls12_381) -/// ``` -/// or -/// ```rust -/// show_curve( -/// ark_bls12_381, -/// ark_bn254, -/// ark_pallas, -/// ark_vesta -/// ) -/// ``` -/// or -/// ```rust -/// show_curve( -/// ark_bls12_381, -/// ark_bn254, -/// ark_pallas, -/// ark_vesta, -/// ) -/// ``` -macro_rules! show_curve { - ($($c:ident),+ $(,)?) => { - $(show_curve::<$c::Fr, $c::Fq>(stringify!($c));)* - } -} - -fn main() { - show_curve!( - ark_bls12_377, - ark_bls12_381, - ark_bn254, - ark_bw6_761, - ark_cp6_782, - ark_curve25519, - ark_ed_on_bls12_377, - ark_ed_on_bls12_381, - ark_ed_on_bls12_381_bandersnatch, - ark_ed_on_bn254, - ark_ed_on_bw6_761, - ark_ed_on_cp6_782, - ark_ed_on_mnt4_298, - ark_ed_on_mnt4_753, - ark_ed25519, - ark_mnt4_298, - ark_mnt4_753, - ark_mnt6_298, - ark_mnt6_753, - ark_pallas, - ark_secp256k1, - ark_secp256r1, - ark_secp384r1, - ark_secq256k1, - ark_vesta, - ); -} diff --git a/komodo.nu b/komodo.nu index ef82579172f3828f9ea0137b120e3e8e543268ee..f0addc706ee6243bee1bf6e04a21f2d153eeb214 100644 --- a/komodo.nu +++ b/komodo.nu @@ -2,7 +2,7 @@ # # please run `komodo --help` or `komodo <tab>` to have a look at more information -use binary.nu ["bytes from_int"] +use .nushell/binary.nu ["bytes from_int"] const KOMODO_BINARY = "./target/release/komodo" const DEFAULT_LOG_LEVEL = "INFO" diff --git a/scripts/inbreeding/build.nu b/scripts/inbreeding/build.nu deleted file mode 100644 index d72318a6d9f692556d3b73da15345cab760033be..0000000000000000000000000000000000000000 --- a/scripts/inbreeding/build.nu +++ /dev/null @@ -1,3 +0,0 @@ -export def main [] { - cargo build --release --example inbreeding -} diff --git a/tests/binary.nu b/tests/binary.nu index 93988a20066e9122dce0ba238488f9b4209b8258..8f45732ec166a2c61fe1c8050f87ff8620d19a2e 100644 --- a/tests/binary.nu +++ b/tests/binary.nu @@ -1,4 +1,4 @@ -use ../binary.nu [ +use ../.nushell/binary.nu [ "bytes decode", "bytes encode", "bytes from_int", "bytes to_int" ] diff --git a/tests/cli.nu b/tests/cli.nu index f4ed378b282d759091431f6066cadc48614c9a1c..637fcb8f54ca04a96d8b87998b27453120f631b2 100644 --- a/tests/cli.nu +++ b/tests/cli.nu @@ -7,7 +7,7 @@ use ../komodo.nu [ "komodo ls", "komodo clean", ] -use ../binary.nu [ "bytes from_int" ] +use ../.nushell/binary.nu [ "bytes from_int" ] use std assert