From ea8003af8fd668b52a4cc6418e00eaa697db0e9a Mon Sep 17 00:00:00 2001 From: KtorZ Date: Thu, 1 Aug 2024 13:08:29 +0200 Subject: [PATCH] Fix bool soft-casting. While the ledger doesn't allow deserializing negative constr value, they are still possible at the machine level. So, we better make sure that we don't make assumptions regarding this. --- crates/uplc/src/builder.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/uplc/src/builder.rs b/crates/uplc/src/builder.rs index aedcd665..edd99643 100644 --- a/crates/uplc/src/builder.rs +++ b/crates/uplc/src/builder.rs @@ -599,11 +599,17 @@ impl Term { .apply(Term::fst_pair().apply(pair.clone())) .if_then_else( otherwise.clone(), - callback( - Term::equals_integer() - .apply(Term::fst_pair().apply(pair)) - .apply(Term::integer(1.into())), - ), + Term::less_than_integer() + .apply(Term::fst_pair().apply(pair.clone())) + .apply(Term::integer(0.into())) + .if_then_else( + otherwise.clone(), + callback( + Term::equals_integer() + .apply(Term::integer(1.into())) + .apply(Term::fst_pair().apply(pair)), + ), + ), ), otherwise.clone(), )