Skip to content

Commit

Permalink
Make some assertions more conservative (#876)
Browse files Browse the repository at this point in the history
* Make the REPL raise errors properly instead of just printing locally so loading files
  with mistakes causes an unsuccessful termination

* Fix errors on some of our demos due to the fix above

* Fix the chain meta command so it persists commitments with the right secret

* Assert that the output of the padded frame is the same as the one from the original last frame
  • Loading branch information
arthurpaulino authored Nov 10, 2023
1 parent fe70ad3 commit dae0d6c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 40 deletions.
10 changes: 5 additions & 5 deletions demo/bank.lurk
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,24 @@ ledger2

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

!(chain 0x0757a47095c97d0a58a8ff66a2146949ee9d60d3f0a82887c203edf1748be711 '(1 0 2))
!(chain 0x099f5f1cef164ac0a5ef8d6b0cefd930d2d0bf40666df3ae1b12abc33a5d297a '(1 0 2))

!(prove)

!(verify "Nova_Pallas_10_118481b08f97e5ea84499dd305d5c2b86089d5d5e5253e6c345119d55020bde3")

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

!(chain 0x0d0b562063718f3623c1749268da4dd74ed33142edc411f4e74d7a84e64f3f30 '(5 0 2))
!(chain 0x11abc1857d88646e3a6a2d0be605a3639feca2b79191c65efb7c6c139465820e '(5 0 2))

!(prove)

!(verify "Nova_Pallas_10_045d2fef5862777cf50a9dc8df50650f1aebfcbfb8135adfea57fb8f45389af4")
!(verify "Nova_Pallas_10_3b5c0928297a8380b1003b343b2b35522b3c16a03fbf69b3deea91c50cbdfc66")

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

!(chain 0x3e232dc8d44c85697fa4205d0d945014d34b980af498aed9194216c27c489e05 '(20 1 0))
!(chain 0x007f5ed09b15a2af11a0504a46884aff364eb7bb1e7e9543431443b962166cb5 '(20 1 0))

!(prove)

!(verify "Nova_Pallas_10_25c76318cda48570568b9bb766ee9a906790c4dc94c96b1d6549e96c3bff8aa7")
!(verify "Nova_Pallas_10_3dc75e7fc1fd2a629b04e6e7469ed20711a4012b03c3f1205c18a351b9cdb7ca")
2 changes: 1 addition & 1 deletion demo/vdf.lurk
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

!(prove)

!(verify "Nova_Pallas_10_20c429019e3eade18d0182febe27b987af8da1ab15cf55b0794296deb0435929")
!(verify "Nova_Pallas_10_0edc673ca67889bd824bb09d6be89a1b93fc7bc013fff4f4cd50e7bf10587831")

!(def timelock-encrypt (lambda (secret-key plaintext rounds)
(let ((ciphertext (+ secret-key plaintext))
Expand Down
53 changes: 24 additions & 29 deletions src/cli/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,22 +411,21 @@ impl Repl<F> {
}

pub fn handle_non_meta(&mut self, expr_ptr: Ptr<F>) -> Result<()> {
self.eval_expr_and_memoize(expr_ptr)
.map(|(output, iterations)| {
let iterations_display = Self::pretty_iterations_display(iterations);
match output[2].tag() {
Tag::Cont(ContTag::Terminal) => {
println!(
"[{iterations_display}] => {}",
output[0].fmt_to_string(&self.store, &self.state.borrow())
)
}
Tag::Cont(ContTag::Error) => {
println!("Evaluation encountered an error after {iterations_display}")
}
_ => println!("Limit reached after {iterations_display}"),
}
})
let (output, iterations) = self.eval_expr_and_memoize(expr_ptr)?;
let iterations_display = Self::pretty_iterations_display(iterations);
match output[2].tag() {
Tag::Cont(ContTag::Terminal) => {
println!(
"[{iterations_display}] => {}",
output[0].fmt_to_string(&self.store, &self.state.borrow())
);
Ok(())
}
Tag::Cont(ContTag::Error) => {
bail!("Evaluation encountered an error after {iterations_display}")
}
_ => bail!("Limit reached after {iterations_display}"),
}
}

fn handle_meta(&mut self, expr_ptr: Ptr<F>) -> Result<()> {
Expand All @@ -437,7 +436,7 @@ impl Repl<F> {
match self.meta.get(cmdstr) {
Some(cmd) => match (cmd.run)(self, cmdstr, &cdr) {
Ok(()) => (),
Err(e) => println!("meta command failed with {}", e),
Err(e) => bail!("Meta command failed with {}", e),
},
None => bail!("Unsupported meta command: {cmdstr}"),
}
Expand All @@ -464,6 +463,8 @@ impl Repl<F> {
let (syntax_start, mut new_input, ptr, is_meta) =
self.store.read_maybe_meta(self.state.clone(), &input)?;
if demo {
// adjustment to print the exclamation mark in the right place
let syntax_start = syntax_start - usize::from(is_meta);
let potential_commentaries = &input[..syntax_start];
let actual_syntax = &input[syntax_start..new_input.location_offset()];
let input_marker = &self.input_marker();
Expand All @@ -488,11 +489,7 @@ impl Repl<F> {
}

pub fn load_file(&mut self, file_path: &Utf8Path, demo: bool) -> Result<()> {
let input = if std::env::var("LURK_PANIC_IF_CANT_LOAD") == Ok("true".into()) {
read_to_string(file_path).unwrap_or_else(|_| panic!("File not found: {}", file_path))
} else {
read_to_string(file_path)?
};
let input = read_to_string(file_path)?;
if demo {
println!("Loading {file_path} in demo mode");
} else {
Expand Down Expand Up @@ -543,24 +540,22 @@ impl Repl<F> {
Ok((.., expr_ptr, is_meta)) => {
if is_meta {
if let Err(e) = self.handle_meta(expr_ptr) {
println!("!Error: {e}");
eprintln!("!Error: {e}")
}
} else if let Err(e) = self.handle_non_meta(expr_ptr) {
println!("Error: {e}");
eprintln!("Error: {e}")
}
}
Err(parser::Error::NoInput) => (),
Err(e) => {
println!("Read error: {e}")
}
Err(e) => eprintln!("Read error: {e}"),
}
}
Err(ReadlineError::Interrupted | ReadlineError::Eof) => {
println!("Exiting...");
break;
}
Err(err) => {
println!("Read line error: {err}");
Err(e) => {
eprintln!("Read line error: {e}");
break;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/cli/repl/meta_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,12 @@ impl MetaCmd<F> {
let Ptr::Atom(Tag::Expr(ExprTag::Comm), hash) = comm else {
bail!("Second component of a chain must be a commitment")
};
let (_, fun) = repl
// retrieve from store to persist
let (secret, fun) = repl
.store
.open(hash)
.expect("data must have been committed");
repl.hide(F::NON_HIDING_COMMITMENT_SECRET, *fun)
repl.hide(*secret, *fun)
},
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/lem/multiframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ impl<'a, F: LurkField, C: Coprocessor<F> + 'a> MultiFrameTrait<'a, F, C> for Mul
let padding_frame = lurk_step
.call_simple(&output, store, lang, 0)
.expect("reduction step failed");
assert_eq!(padding_frame.input, padding_frame.output);
assert_eq!(output, padding_frame.output);
inner_frames.resize(reduction_count, padding_frame.clone());
inner_frames
} else {
Expand Down Expand Up @@ -554,7 +554,7 @@ impl<'a, F: LurkField, C: Coprocessor<F> + 'a> MultiFrameTrait<'a, F, C> for Mul
let padding_frame = lurk_step
.call_simple(&output, store, lang, 0)
.expect("reduction step failed");
assert_eq!(padding_frame.input, padding_frame.output);
assert_eq!(output, padding_frame.output);
inner_frames.resize(reduction_count, padding_frame);
}

Expand Down
17 changes: 17 additions & 0 deletions tests/lurk-cli-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ fn test_prove_and_verify() {
file.write_all(b"!(verify \"Nova_Pallas_10_3f2526abf20fc9006dd93c0d3ff49954ef070ef52d2e88426974de42cc27bdb2\")\n").unwrap();

let mut cmd = lurk_cmd();
cmd.env("LURK_PERF", "max-parallel-simple");
cmd.arg("load");
cmd.arg(lurk_file.into_string());
cmd.arg("--public-params-dir");
Expand All @@ -69,3 +70,19 @@ fn test_prove_and_verify() {

cmd.assert().success();
}

#[test]
fn test_repl_panic() {
let tmp_dir = Builder::new().prefix("tmp").tempdir().unwrap();
let tmp_dir = Utf8Path::from_path(tmp_dir.path()).unwrap();
let lurk_file = tmp_dir.join("panic.lurk");

let mut file = File::create(lurk_file.clone()).unwrap();
// `x` is not bound
file.write_all(b"x\n").unwrap();

let mut cmd = lurk_cmd();
cmd.arg("load");
cmd.arg(lurk_file.into_string());
cmd.assert().failure();
}
1 change: 0 additions & 1 deletion tests/lurk-files-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ fn test_lurk_lib() {
lurk_lib_examples.into_par_iter().for_each(|f| {
let mut cmd = lurk_cmd();
cmd.current_dir(LURK_LIB_EXAMPLES_DIR);
cmd.env("LURK_PANIC_IF_CANT_LOAD", "true");
cmd.arg(f);
cmd.assert().success();
});
Expand Down

1 comment on commit dae0d6c

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks

Table of Contents

Overview

This benchmark report shows the Fibonacci GPU benchmark.
Tesla T4
Intel(R) Xeon(R) CPU @ 2.30GHz
117.905 GB RAM

Benchmark Results

LEM Fibonacci Prove - rc = 100

fib-ref=fe70ad3079f5535261011dd95f1131fbe90b3b4e fib-ref=dae0d6c478a83c80e3b3753c29f89e4ecd2a6313
num-100 5.82 s (✅ 1.00x) 5.95 s (✅ 1.02x slower)
num-200 14.14 s (✅ 1.00x) 14.51 s (✅ 1.03x slower)

LEM Fibonacci Prove - rc = 600

fib-ref=fe70ad3079f5535261011dd95f1131fbe90b3b4e fib-ref=dae0d6c478a83c80e3b3753c29f89e4ecd2a6313
num-100 5.51 s (✅ 1.00x) 5.50 s (✅ 1.00x faster)
num-200 12.40 s (✅ 1.00x) 12.48 s (✅ 1.01x slower)

Made with criterion-table

Please sign in to comment.