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

Eliminate hashing shims for hardcoded tags across the LEM codebase #810

Merged
merged 1 commit into from
Oct 30, 2023
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
10 changes: 1 addition & 9 deletions src/cli/zstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
lem::{
pointers::{Ptr, ZChildren, ZPtr},
store::Store,
Tag,
},
tag::ContTag::{Dummy, Error, Outermost, Terminal},
};

use super::field_data::HasFieldModulus;
Expand Down Expand Up @@ -68,13 +66,7 @@
} else {
let z_ptr = match ptr {
Ptr::Atom(tag, f) => {
let z_ptr = match tag {
Tag::Cont(Outermost | Error | Dummy | Terminal) => {
// temporary shim for compatibility with Lurk Alpha
ZPtr::from_parts(*tag, store.poseidon_cache.hash8(&[F::ZERO; 8]))
}
Comment on lines -72 to -75
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is gone

_ => ZPtr::from_parts(*tag, *f),
};
let z_ptr = ZPtr::from_parts(*tag, *f);

Check warning on line 69 in src/cli/zstore.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/zstore.rs#L69

Added line #L69 was not covered by tests
z_store.dag.insert(z_ptr, ZChildren::Atom);
z_ptr
}
Expand Down
30 changes: 9 additions & 21 deletions src/coprocessor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
use super::*;
use crate::circuit::gadgets::constraints::{add, alloc_equal, and, mul};
use crate::lem::Tag as LEMTag;
use crate::tag::{ContTag, ExprTag, Tag};
use crate::tag::{ExprTag, Tag};
use std::marker::PhantomData;

/// A dumb Coprocessor for testing.
Expand Down Expand Up @@ -347,18 +347,10 @@
.get_allocated_const(LEMTag::Expr(ExprTag::Num).to_field())
.expect("Num tag should have been allocated");

// the following is a temporary shim for compatibility with Lurk Alpha
// otherwise we could just have a pointer whose value is zero
Comment on lines -350 to -351
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is gone

let err_cont_ptr = LEMPtr::null(LEMTag::Cont(ContTag::Error));
let err_cont_z_ptr = s.hash_ptr(&err_cont_ptr).expect("hash_ptr failed");
let allocated_error_tag = g
.get_allocated_const(err_cont_z_ptr.tag_field())
.expect("Error tag should have been allocated");
let allocated_error_hash = g
.get_allocated_const(*err_cont_z_ptr.value())
.expect("Error hash should have been allocated");
let cont_err =
AllocatedPtr::from_parts(allocated_error_tag.clone(), allocated_error_hash.clone());
let err_cont_z_ptr = s.hash_ptr(&s.cont_error()).expect("hash_ptr failed");
let cont_err = g
.get_allocated_ptr_from_z_ptr(&err_cont_z_ptr)
.expect("Error pointer should have been allocated");

Check warning on line 353 in src/coprocessor/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/coprocessor/mod.rs#L350-L353

Added lines #L350 - L353 were not covered by tests

let (expr, env, cont) =
self.synthesize_aux(cs, input_exprs, input_env, input_cont, num_tag, &cont_err)?;
Expand Down Expand Up @@ -433,22 +425,18 @@

fn evaluate_lem(
&self,
_s: &LEMStore<F>,
s: &LEMStore<F>,

Check warning on line 428 in src/coprocessor/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/coprocessor/mod.rs#L428

Added line #L428 was not covered by tests
args: &[LEMPtr<F>],
env: &LEMPtr<F>,
cont: &LEMPtr<F>,
) -> Vec<LEMPtr<F>> {
let LEMPtr::Atom(LEMTag::Expr(ExprTag::Num), a) = &args[0] else {
return vec![args[0], *env, LEMPtr::null(LEMTag::Cont(ContTag::Error))];
return vec![args[0], *env, s.cont_error()];

Check warning on line 434 in src/coprocessor/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/coprocessor/mod.rs#L434

Added line #L434 was not covered by tests
};
let LEMPtr::Atom(LEMTag::Expr(ExprTag::Num), b) = &args[1] else {
return vec![args[1], *env, LEMPtr::null(LEMTag::Cont(ContTag::Error))];
return vec![args[1], *env, s.cont_error()];

Check warning on line 437 in src/coprocessor/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/coprocessor/mod.rs#L437

Added line #L437 was not covered by tests
};
vec![
LEMPtr::Atom(LEMTag::Expr(ExprTag::Num), (*a * *a) + *b),
*env,
*cont,
]
vec![LEMPtr::num((*a * *a) + *b), *env, *cont]

Check warning on line 439 in src/coprocessor/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/coprocessor/mod.rs#L439

Added line #L439 was not covered by tests
}
}

Expand Down
Loading
Loading