Skip to content

policy: add checks for exact annex padding of simplicity programs

4a9b55e
Select commit
Loading
Failed to load commit list.
Draft

policy: allow exact annex padding for simplicity spends #1539

policy: add checks for exact annex padding of simplicity programs
4a9b55e
Select commit
Loading
Failed to load commit list.
Cirrus CI / lint [bionic] failed Mar 13, 2026 in 2m 24s

Task Summary

Instruction lint failed in 01:00

Details

✅ 01:01 clone
✅ 00:19 merge_base
❌ 01:00 lint

+    return IS_PERMANENT(*error);
+  }
+
+  simplicity_assert(NULL != dag);
+  simplicity_assert((uint_fast32_t)dag_len <= DAG_LEN_MAX);
+  *error = simplicity_closeBitstream(&stream);
+  if (!IS_OK(*error)) {
+    simplicity_free(dag);
+    return IS_PERMANENT(*error);
+  }
+
+  *error = simplicity_mallocTypeInference(&type_dag, simplicity_elements_mallocBoundVars, dag, dag_len, &census);
+  if (!IS_OK(*error)) {
+    simplicity_free(type_dag);
+    simplicity_free(dag);
+    return IS_PERMANENT(*error);
+  }
+
+  simplicity_assert(NULL != type_dag);
+
+  ubounded cellsBound, UWORDBound, frameBound;
+  *error = simplicity_analyseBounds(&cellsBound, &UWORDBound, &frameBound, cost_bound, UBOUNDED_MAX, 0, UBOUNDED_MAX, dag, type_dag, dag_len);
+
+  simplicity_free(type_dag);
+  simplicity_free(dag);
+  return IS_PERMANENT(*error);
+}
diff --git a/include/simplicity/elements/cost.h b/include/simplicity/elements/cost.h
new file mode 100644
index 000000000..30121961e
--- /dev/null
+++ b/include/simplicity/elements/cost.h
@@ -0,0 +1,22 @@
+#ifndef SIMPLICITY_ELEMENTS_COST_H
+#define SIMPLICITY_ELEMENTS_COST_H
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <simplicity/errorCodes.h>
+
+/* Deserialize a Simplicity 'program', perform type inference, and compute its cost bound.
+ *
+ * If at any time malloc fails then '*error' is set to 'SIMPLICITY_ERR_MALLOC' and 'false' is returned.
+ * Otherwise, 'true' is returned indicating that the result was successfully computed and returned in the '*error' value.
+ *
+ * If the operation completes successfully then '*error' is set to 'SIMPLICITY_NO_ERROR',
+ * and '*cost_bound' is set to the program's cost bound in milli weight units.
+ *
+ * Precondition: NULL != error;
+ *               NULL != cost_bound;
+ *               unsigned char program[program_len]
+ */
+extern bool simplicity_elements_computeCostBound(simplicity_err* error, uint_least32_t* cost_bound, const unsigned char* program, size_t program_len);
+#endif
FAIL: subtree directory was touched without subtree merge