Skip to content

Commit

Permalink
fix: account for empty tables without cols
Browse files Browse the repository at this point in the history
  • Loading branch information
iajoiner committed Nov 12, 2024
1 parent 33c745b commit f8ce3b5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion crates/proof-of-sql/src/sql/proof_exprs/and_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ impl ProofExpr for AndExpr {
let rhs_column: Column<'a, S> = self.rhs.result_evaluate(alloc, table);
let lhs = lhs_column.as_boolean().expect("lhs is not boolean");
let rhs = rhs_column.as_boolean().expect("rhs is not boolean");
Column::Boolean(alloc.alloc_slice_fill_with(table.num_rows(), |i| lhs[i] && rhs[i]))
Column::Boolean(
alloc.alloc_slice_fill_with(table.num_rows().unwrap_or(0), |i| lhs[i] && rhs[i]),
)
}

#[tracing::instrument(name = "AndExpr::prover_evaluate", level = "debug", skip_all)]
Expand Down
6 changes: 5 additions & 1 deletion crates/proof-of-sql/src/sql/proof_exprs/equals_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ impl ProofExpr for EqualsExpr {
let rhs_scale = self.rhs.data_type().scale().unwrap_or(0);
let res = scale_and_subtract(alloc, lhs_column, rhs_column, lhs_scale, rhs_scale, true)
.expect("Failed to scale and subtract");
Column::Boolean(result_evaluate_equals_zero(table.num_rows(), alloc, res))
Column::Boolean(result_evaluate_equals_zero(
table.num_rows().unwrap_or(0),
alloc,
res,
))
}

#[tracing::instrument(name = "EqualsExpr::prover_evaluate", level = "debug", skip_all)]
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/src/sql/proof_exprs/inequality_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl ProofExpr for InequalityExpr {
let rhs_column = self.rhs.result_evaluate(alloc, table);
let lhs_scale = self.lhs.data_type().scale().unwrap_or(0);
let rhs_scale = self.rhs.data_type().scale().unwrap_or(0);
let table_length = table.num_rows();
let table_length = table.num_rows().unwrap_or(0);
let diff = if self.is_lte {
scale_and_subtract(alloc, lhs_column, rhs_column, lhs_scale, rhs_scale, false)
.expect("Failed to scale and subtract")
Expand Down
4 changes: 2 additions & 2 deletions crates/proof-of-sql/src/sql/proof_exprs/literal_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl ProofExpr for LiteralExpr {
alloc: &'a Bump,
table: &Table<'a, S>,
) -> Column<'a, S> {
Column::from_literal_with_length(&self.value, table.num_rows(), alloc)
Column::from_literal_with_length(&self.value, table.num_rows().unwrap_or(0), alloc)
}

#[tracing::instrument(name = "LiteralExpr::prover_evaluate", level = "debug", skip_all)]
Expand All @@ -60,7 +60,7 @@ impl ProofExpr for LiteralExpr {
alloc: &'a Bump,
table: &Table<'a, S>,
) -> Column<'a, S> {
Column::from_literal_with_length(&self.value, table.num_rows(), alloc)
Column::from_literal_with_length(&self.value, table.num_rows().unwrap_or(0), alloc)
}

fn verifier_evaluate<C: Commitment>(
Expand Down
7 changes: 6 additions & 1 deletion crates/proof-of-sql/src/sql/proof_exprs/or_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ impl ProofExpr for OrExpr {
let rhs_column: Column<'a, S> = self.rhs.result_evaluate(alloc, table);
let lhs = lhs_column.as_boolean().expect("lhs is not boolean");
let rhs = rhs_column.as_boolean().expect("rhs is not boolean");
Column::Boolean(result_evaluate_or(table.num_rows(), alloc, lhs, rhs))
Column::Boolean(result_evaluate_or(
table.num_rows().unwrap_or(0),
alloc,
lhs,
rhs,
))
}

#[tracing::instrument(name = "OrExpr::prover_evaluate", level = "debug", skip_all)]
Expand Down

0 comments on commit f8ce3b5

Please sign in to comment.