Skip to content

Commit

Permalink
chore: make Bn256 the default field for the REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Feb 6, 2024
1 parent 222255f commit 24ff3b0
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 54 deletions.
16 changes: 8 additions & 8 deletions demo/bank.lurk
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ ledger2

;; Now we can open the committed ledger transfer function on a transaction.

!(call 0x348a2e97903fff808be52461d19c3192b6868830598be397b361a21bfc8a45f9 '(1 0 2))
!(call 0x207bca2dcc9fb4d1d3e3939d2c1e6a3adaabf41dc0174dd39b9949d697b55aaa '(1 0 2))

;; And the record reflects that Church sent one unit to Satoshi.

Expand All @@ -202,7 +202,7 @@ ledger2

;; We can verify the proof..

!(verify "Nova_Pallas_10_398a87b5f99157b86abde88a67754791f72fed93ccd8db68d693bc9f7e26738c")
!(verify "Nova_BN256_10_11882126c5f0dd9a94f76ff58ea5c499cfe2364162585c320c55f53651e16ffd")

;; Unfortunately, this functional commitment doesn't let us maintain state.
;; Let's turn our single-transaction function into a chained function.
Expand All @@ -219,24 +219,24 @@ ledger2

;; Now we can transfer one unit from Church to Satoshi like before.

!(chain 0x0e484bf02f72ad529ebb9ded8fc2f4c2b1519a758e0f0238973bf0cd8dd97f72 '(1 0 2))
!(chain 0x07ec757321b69b7902c2c5629535c343c1eb335c0ca12275a95ec28918e0af47 '(1 0 2))

!(prove)

!(verify "Nova_Pallas_10_11df37aff14b2fc8c1fea85fcc07ebececa4ef3e974764c73c49a2ce64eeb8f1")
!(verify "Nova_BN256_10_0b72908859e73ee3014067a5eaa557a995aea262cfb5f3621922024a176b8281")

;; Then we can transfer 5 more, proceeding from the new head of the chain.

!(chain 0x3cb56c66573d29a478b62ff6d59df557dd2e6a924ff408644e61e31c3847a9cd '(5 0 2))
!(chain 0x18b99c6b580d518129921ebf70023b5d757861b935f7f537460c99130eb4447d '(5 0 2))

!(prove)

!(verify "Nova_Pallas_10_3541178de43221c6d12f82ff6da37807971079d11ced58e3564ba2f34e77cfc4")
!(verify "Nova_BN256_10_0d8159faab0d85855d4cf53c7e36a2357a1766a1540afbafb0ef93d7e1537ca8")

;; And once more, this time we'll transfer 20 from Turing to Church.

!(chain 0x38172b9b6212b557d94b9896ea569e77fa35ac979700bedcc97f711322169905 '(20 1 0))
!(chain 0x0b2d868fad0e6ec88e9ba6818ae9a0345aab06abc2c226200ff3ed45c60a41db '(20 1 0))

!(prove)

!(verify "Nova_Pallas_10_2dd41df4b593c4f8b4a0a058d94b8dbcded8343f829d1aaf2765f0b8e0eda03b")
!(verify "Nova_BN256_10_0a253296edb4d6c204edd92e63176efed7c30e9f5928b52ba9be2b3f2e6e8b08")
8 changes: 4 additions & 4 deletions demo/chained-functional-commitment.lurk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

;; We chain a next commitment by applying the committed function to a value of 9.

!(chain 0x3e47de9fb674019306d566345ab360d92f955e29e015432b10ecb58476f42f01 9)
!(chain 0x2b444b40b27bac0dff8416c0f3c708a505a636d86ba66bdbe86497c515afb651 9)

;; The new counter value is 9, and the function returns a new functional commitment.

Expand All @@ -21,7 +21,7 @@

;; We can verify the proof.

!(verify "Nova_Pallas_10_1b894ae4e13a74970afb9ff982fd0e9c4dc439a8317ac85eeaf97ab6c3d8f35e")
!(verify "Nova_BN256_10_0f54f9e56fa6c436618597c971daa7b525ad80ac48be11226284fd4f8167e60a")

;; Now let's chain another call to the new head, adding 12 to the counter.

Expand All @@ -35,7 +35,7 @@

;; And verify.

!(verify "Nova_Pallas_10_29a1a6b7ceca05a40f92883dc7d3c11dd8e7cca698665bc7a9faaaa96cdde96a")
!(verify "Nova_BN256_10_281771b7af2f96cac51cb7579d94f0a6f56e9a9d951b753f8514b2b4ec6ce4db")

;; One more time, we'll add 14 to the head commitment's internal state.

Expand All @@ -49,7 +49,7 @@

;; Verify.

!(verify "Nova_Pallas_10_13f092af20ac415822a0528d41e5c1f5565bfa6d0ec376445e677f411eb3ddd4")
!(verify "Nova_BN256_10_22ab68c1fa6e75f54d213a3ada71edd21331bf58826263a79e3fdd32f1c4c62d")

;; Repeat indefinitely.

Expand Down
8 changes: 4 additions & 4 deletions demo/functional-commitment.lurk
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

;; We open the functional commitment on input 5: Evaluate f(5).

!(call 0x05adecdb07d3d8d4a9d8027c163a70ef66c18ec311abc8381c2df92c58e216b5 5)
!(call 0x1a1975f9bc4e30d4c0e80482418a314c9d2a5bc0eea2770da310886f455825d1 5)

;; We can prove the functional-commitment opening.

!(prove)

;; We can inspect the input/output expressions of the proof.

!(inspect "Nova_Pallas_10_1c3654a2491282df9c31cba2d104649a496b3d1bac4bb5352004a21c94554027")
!(inspect "Nova_BN256_10_15c837e5040ac70c00030c228b61fde2c164d930ba6ea396353b3cfcaa16609d")

;; Or the full proof claim

!(inspect-full "Nova_Pallas_10_1c3654a2491282df9c31cba2d104649a496b3d1bac4bb5352004a21c94554027")
!(inspect-full "Nova_BN256_10_15c837e5040ac70c00030c228b61fde2c164d930ba6ea396353b3cfcaa16609d")

;; Finally, and most importantly, we can verify the proof.

!(verify "Nova_Pallas_10_1c3654a2491282df9c31cba2d104649a496b3d1bac4bb5352004a21c94554027")
!(verify "Nova_BN256_10_15c837e5040ac70c00030c228b61fde2c164d930ba6ea396353b3cfcaa16609d")
4 changes: 2 additions & 2 deletions demo/protocol.lurk
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
:descr "demo protocol")

;; This is the prover's pair, whose hash is
;; 0x09910d31a7568d66855bcc83fccc4826063dfdf93fe5e1f736c83ec892ed139e
;; 0x237fe43a25f3830ab6ac86451b93e74e8ef6ef1e8735a3f53478b7fe76b1a466
(commit '(13 . 17))

;; Let's prove it and write the proof to the file protocol-proof
!(prove-protocol my-protocol
"protocol-proof"
0x09910d31a7568d66855bcc83fccc4826063dfdf93fe5e1f736c83ec892ed139e
0x237fe43a25f3830ab6ac86451b93e74e8ef6ef1e8735a3f53478b7fe76b1a466
'(13 . 17))

;; Now it can be verified
Expand Down
8 changes: 4 additions & 4 deletions demo/vdf.lurk
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
(fastexp 2 5)

;; (4p - 3) / 5
!(def r 23158417847463239084714197001737581570690445185553317903743794198714690358477)
!(def r 17510594297471420177797124596205820070838691520332827474958563349260646796493)

!(def fifth-root (lambda (n) (fastexp n r)))

!(def fifth (lambda (n) (fastexp n 5)))

(fifth-root 42)

(fifth 0x2e6606ca7e8983f71964677e06cd8fd13ee0d46bf3c3e52d3af1b80df06f730b)
(fifth 0x2a7b0ae43e98616d25287ce004700ac747ed8f5e95761ee4869ac0a851b3d3ee)

!(def round (lambda (state)
(let ((x (car state))
Expand Down Expand Up @@ -47,11 +47,11 @@

(minroot '(123 456 1) 10)

(minroot-inverse '(0x27ec1d892ff1b85d98dd8e61509c0ce63b6954da8a743ee54b1f405cde722eb1 0x0da555f3ff604e853948466204d773c4c34d8cf38cea55351c9c97593613fb3b 11) 10)
(minroot-inverse '(0x1896bbc5df5819f436df3f86f6c707bdee372c1046bfa70196cf0f358497acc2 0x0ba0c60958b05f0ca1153cab833cbc315f7f10c4e1b9630ec8829cea907cb688 11) 10)

!(prove)

!(verify "Nova_Pallas_10_3d385361e08449cad361ccbe45d4c41685bcee7ece87b33c47b8953309002f64")
!(verify "Nova_BN256_10_2b96123c7e47229622beeef7080c005e9d18ed0cfd2c0b7f06e1d9f1cfcf83a8")

!(def timelock-encrypt (lambda (secret-key plaintext rounds)
(let ((ciphertext (+ secret-key plaintext))
Expand Down
10 changes: 5 additions & 5 deletions src/cli/field_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<T: Serialize + HasFieldModulus> Serialize for FieldData<T> {
mod tests {
use crate::field::LurkField;
use ff::Field;
use pasta_curves::Fq;
use halo2curves::bn256::Fr as Bn;
use serde::{Deserialize, Serialize};

use super::{de, ser, HasFieldModulus};
Expand Down Expand Up @@ -113,7 +113,7 @@ mod tests {
let s = Struct {
str: "hi".into(),
int: 42,
ff: Fq::double(&Fq::ONE),
ff: Bn::double(&Bn::ONE),
};
assert_eq!(s, de(&ser(s.clone()).unwrap()).unwrap())
}
Expand All @@ -122,7 +122,7 @@ mod tests {
fn enum1_roundtrips() {
let e11 = Enum1::CaseStr("bye".into());
let e12 = Enum1::CaseInt(11);
let e13 = Enum1::CaseFF(Fq::double(&Fq::double(&Fq::ONE)));
let e13 = Enum1::CaseFF(Bn::double(&Bn::double(&Bn::ONE)));
for e in [e11, e12, e13] {
assert_eq!(e, de(&ser(e.clone()).unwrap()).unwrap());
}
Expand All @@ -147,11 +147,11 @@ mod tests {
}
let e11 = Enum1::CaseStr("bye".into());
let e12 = Enum1::CaseInt(11);
let e13 = Enum1::CaseFF(Fq::double(&Fq::double(&Fq::ONE)));
let e13 = Enum1::CaseFF(Bn::double(&Bn::double(&Bn::ONE)));

let e21 = Enum2::CaseStr2("bye".into());
let e22 = Enum2::CaseInt2(11);
let e23 = Enum2::CaseFF2(Fq::double(&Fq::double(&Fq::ONE)));
let e23 = Enum2::CaseFF2(Bn::double(&Bn::double(&Bn::ONE)));

for (e1, e2) in [(e11, e21), (e12, e22), (e13, e23)] {
assert_eq!(e2.clone(), de(&ser(e1.clone()).unwrap()).unwrap());
Expand Down
8 changes: 4 additions & 4 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct LoadArgs {
#[clap(long, value_enum)]
backend: Option<Backend>,

/// Arithmetic field (defaults to "Pallas")
/// Arithmetic field (defaults to "Bn256")
#[clap(long, value_enum)]
field: Option<LanguageField>,

Expand Down Expand Up @@ -207,7 +207,7 @@ struct ReplArgs {
#[clap(long, value_enum)]
backend: Option<Backend>,

/// Arithmetic field (defaults to "Pallas")
/// Arithmetic field (defaults to "Bn256")
#[clap(long, value_enum)]
field: Option<LanguageField>,

Expand Down Expand Up @@ -422,7 +422,7 @@ struct VerifyArgs {
#[clap(value_parser)]
proof_key: String,

/// Arithmetic field (defaults to "Pallas")
/// Arithmetic field (defaults to "Bn256")
#[clap(long, value_enum)]
field: Option<LanguageField>,

Expand All @@ -445,7 +445,7 @@ struct InspectArgs {
#[clap(value_parser)]
proof_key: String,

/// Arithmetic field (defaults to "Pallas")
/// Arithmetic field (defaults to "Bn256")
#[clap(long, value_enum)]
field: Option<LanguageField>,

Expand Down
24 changes: 12 additions & 12 deletions src/cli/repl/meta_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ where
description: &[],
example: &[
"!(commit '(13 . 21))",
"(let ((n (open 0x0071a3fe5e3a0dea9f7257e3210ea719f3464f2aa52a2cd6e6176c8275a75b25))) (* (car n) (cdr n)))",
"(let ((n (open 0x178217493faea2931df4e333837ba9312d0bb9f59bb787c1f40fd3af6d845001))) (* (car n) (cdr n)))",
],
run: |repl, args, _path| {
let first = repl.peek1(args)?;
Expand All @@ -254,8 +254,8 @@ where
description: &[],
example: &[
"!(hide 12345 '(13 . 21))",
"(secret (comm 0x3be5f551534baa53a9c180e49b48c4a75ed7642a82197be5f674d54681de4425))",
"(open 0x3be5f551534baa53a9c180e49b48c4a75ed7642a82197be5f674d54681de4425)",
"(secret (comm 0x1884a703eea837ffae6ae99ec9af8e90d3fce7666c7953ffbe5eac7463ed1819))",
"(open 0x1884a703eea837ffae6ae99ec9af8e90d3fce7666c7953ffbe5eac7463ed1819)",
],
run: |repl, args, _path| {
let (first, second) = repl.peek2(args)?;
Expand Down Expand Up @@ -284,7 +284,7 @@ where
description: &[],
example: &[
"!(commit '(13 . 21))",
"!(fetch 0x0071a3fe5e3a0dea9f7257e3210ea719f3464f2aa52a2cd6e6176c8275a75b25)",
"!(fetch 0x178217493faea2931df4e333837ba9312d0bb9f59bb787c1f40fd3af6d845001)",
],
run: |repl, args, _path| {
let hash = *repl.get_comm_hash(args)?;
Expand All @@ -299,7 +299,7 @@ where
description: &[],
example: &[
"!(commit '(13 . 21))",
"!(open 0x0071a3fe5e3a0dea9f7257e3210ea719f3464f2aa52a2cd6e6176c8275a75b25)",
"!(open 0x178217493faea2931df4e333837ba9312d0bb9f59bb787c1f40fd3af6d845001)",
],
run: |repl, args, _path| {
let hash = *repl.get_comm_hash(args)?;
Expand Down Expand Up @@ -349,8 +349,8 @@ where
],
example: &[
"!(prove '(1 2 3))",
"!(verify \"Nova_Pallas_10_002cd7baecd8e781d217cd1eb8b67d4f890005fd3763541e37ce49550bd9f4bf\")",
"!(open 0x002cd7baecd8e781d217cd1eb8b67d4f890005fd3763541e37ce49550bd9f4bf)",
"!(verify \"Nova_BN256_10_048476fa5e4804639fe4ccfe73d43bf96da6183f670f0b08e4ac8c82bf8efa47\")",
"!(open 0x048476fa5e4804639fe4ccfe73d43bf96da6183f670f0b08e4ac8c82bf8efa47)",
],
run: |repl, args, _path| {
if !args.is_nil() {
Expand All @@ -368,8 +368,8 @@ where
description: &["Verify proof key <string> and print the result."],
example: &[
"!(prove '(1 2 3))",
"!(verify \"Nova_Pallas_10_166fafef9d86d1ddd29e7b62fa5e4fb2d7f4d885baf28e23187860d0720f74ca\")",
"!(open 0x166fafef9d86d1ddd29e7b62fa5e4fb2d7f4d885baf28e23187860d0720f74ca)",
"!(verify \"Nova_BN256_10_048476fa5e4804639fe4ccfe73d43bf96da6183f670f0b08e4ac8c82bf8efa47\")",
"!(open 0x048476fa5e4804639fe4ccfe73d43bf96da6183f670f0b08e4ac8c82bf8efa47)",
],
run: |repl, args, _path| {
let first = repl.peek1(args)?;
Expand Down Expand Up @@ -548,7 +548,7 @@ where
description: &[],
example: &[
"(commit (lambda (x) x))",
"!(call 0x2f14c82533e8347d128b07e6610d0fc901f71418c2a6ea3e618cfe654f73f4b1 0)",
"!(call 0x2f31ee658b82c09daebbd2bd976c9d6669ad3bd6065056763797d5aaf4a3001b 0)",
],
run: Self::call,
};
Expand All @@ -567,7 +567,7 @@ where
(let ((counter (+ counter x)))
(cons counter (commit (add counter)))))))
(add 0)))",
"!(chain 0x14cb06e2d3c594af90d5b670e73595791d7462b20442c24cd56ba2919947d769 1)",
"!(chain 0x2b444b40b27bac0dff8416c0f3c708a505a636d86ba66bdbe86497c515afb651 1)",
],
run: |repl, args, path| {
Self::call(repl, args, path)?;
Expand Down Expand Up @@ -905,7 +905,7 @@ where
"(commit '(13 . 17))",
"!(prove-protocol my-protocol",
" \"protocol-proof\"",
" 0x09910d31a7568d66855bcc83fccc4826063dfdf93fe5e1f736c83ec892ed139e",
" 0x237fe43a25f3830ab6ac86451b93e74e8ef6ef1e8735a3f53478b7fe76b1a466",
" '(13 . 17))",
],
run: |repl, args, _path| {
Expand Down
10 changes: 5 additions & 5 deletions src/cli/zstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl<F: LurkField> ZStore<F> {

#[cfg(test)]
mod tests {
use pasta_curves::Fp;
use halo2curves::bn256::Fr as Bn;
use rand::{rngs::StdRng, Rng};
use rand_core::SeedableRng;
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
Expand All @@ -331,7 +331,7 @@ mod tests {
use super::{ZDag, ZStore};

/// helper function that interns random data into a store
fn rng_interner(rng: &mut StdRng, max_depth: usize, store: &Store<Fp>) -> Ptr {
fn rng_interner(rng: &mut StdRng, max_depth: usize, store: &Store<Bn>) -> Ptr {
let rnd = rng.gen::<u64>();
let tag = match rnd % 4 {
0 => Tag::Expr(ExprTag::try_from((rnd % 11) as u16).unwrap()),
Expand All @@ -341,10 +341,10 @@ mod tests {
_ => unreachable!(),
};
if max_depth == 0 {
store.intern_atom(tag, Fp::from_u64(rnd))
store.intern_atom(tag, Bn::from_u64(rnd))
} else {
match rnd % 4 {
0 => store.intern_atom(tag, Fp::from_u64(rnd)),
0 => store.intern_atom(tag, Bn::from_u64(rnd)),
1 => intern_ptrs!(
store,
tag,
Expand Down Expand Up @@ -397,7 +397,7 @@ mod tests {

#[test]
fn test_filtered_dag() {
let store = Store::<Fp>::default();
let store = Store::<Bn>::default();
let one = store.num_u64(1);
let two = store.num_u64(2);
let thr = store.num_u64(3);
Expand Down
10 changes: 5 additions & 5 deletions src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ use crate::tag::{ContTag, ExprTag, Op1, Op2};
#[cfg_attr(not(target_arch = "wasm32"), derive(Arbitrary))]
#[cfg_attr(not(target_arch = "wasm32"), serde_test)]
pub enum LanguageField {
/// The Pallas field,
#[default]
Pallas,
/// The Vesta field,
Vesta,
/// The BN256 scalar field,
#[default]
BN256,
/// THe Grumpkin scalar field,
Grumpkin,
/// The Pallas field,
Pallas,
/// The Vesta field,
Vesta,
}

impl std::fmt::Display for LanguageField {
Expand Down
2 changes: 1 addition & 1 deletion tests/lurk-cli-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn test_prove_and_verify() {

let mut file = File::create(lurk_file.clone()).unwrap();
file.write_all(b"!(prove (+ 1 1))\n").unwrap();
file.write_all(b"!(verify \"Nova_Pallas_10_090cee5a184bc9b76a965e59b87cd1a1eac30c2b0f243e7ee0232e51d14ebbf6\")\n").unwrap();
file.write_all(b"!(verify \"Nova_BN256_10_18748ce7ba3dd0e7560ec64983d6b01d84a6303880b3b0b24878133aa1b4a6bb\")\n").unwrap();

let mut cmd = lurk_cmd();
cmd.env("LURK_PERF", "max-parallel-simple");
Expand Down

0 comments on commit 24ff3b0

Please sign in to comment.