elements/deserialize.h
Russell O'Connor aef3f5a7e5 Squashed 'src/simplicity/' changes from b549192109..6d503ea4f8
6d503ea4f8 Rename elements/jets.c
c68063f9ef Add testcases that are an even multiple of 1000 milliWU
92887000e6 Add minCost parameter
82d6260ed8 Remove intermedite primitive directory
09b4eee340 Make raw environment struct tags elements specific
a93cd359df Make environment struct tags elements specific
26de216e24 Make primitive.h functions indirect
35d188a247 rename elementsJets.* to jets.*
7fd6dbe2ca simplicity_computeCmr -> simplicity_elements_computeCmr

git-subtree-dir: src/simplicity
git-subtree-split: 6d503ea4f8859ec63ad22a22c0ccef067b1a0b5d
2025-06-24 11:37:54 -04:00

45 lines
2.5 KiB
C

/* This module provides functions for deserializing Simplicity's bit-wise prefix coding. */
#ifndef SIMPLICITY_DESERIALIZE_H
#define SIMPLICITY_DESERIALIZE_H
#include <simplicity/errorCodes.h>
#include "bitstream.h"
#include "dag.h"
/* Decode an application specific jet from 'stream' into 'node'.
* All jets begin with a bit prefix of '1' which needs to have already been consumed from the 'stream'.
* Returns 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' if the stream's prefix doesn't match any valid code for a jet.
* Returns 'SIMPLICITY_ERR_BITSTRING_EOF' if not enough bits are available in the 'stream'.
* In the above error cases, 'dag' may be modified.
* Returns 'SIMPLICITY_NO_ERROR' if successful.
*
* Precondition: NULL != node
* NULL != stream
*/
typedef simplicity_err (*simplicity_callback_decodeJet)(dag_node* node, bitstream* stream);
/* Decode a length-prefixed Simplicity DAG from 'stream'.
* Returns 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' the length prefix's value is too large.
* Returns 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' if some node's child isn't a reference to one of the preceding nodes.
* Returns 'SIMPLICITY_ERR_FAIL_CODE' if the encoding of a fail expression is encountered
* (all fail subexpressions ought to have been pruned prior to deserialization).
* Returns 'SIMPLICITY_ERR_RESERVED_CODE' if a reserved codeword is encountered.
* Returns 'SIMPLICITY_ERR_HIDDEN' if the decoded node has a HIDDEN child in a position where it is not allowed.
* Returns 'SIMPLICITY_ERR_HIDDEN_ROOT' if the root of the DAG is a HIDDEN node.
* Returns 'SIMPLICITY_ERR_BITSTRING_EOF' if not enough bits are available in the 'stream'.
* Returns 'SIMPLICITY_ERR_MALLOC' if malloc fails.
* In the above error cases, '*dag' is set to NULL.
* If successful, returns a positive value equal to the length of an allocated array of (*dag).
*
* Precondition: NULL != dag
* NULL != stream
*
* Postcondition: if the return value of the function is positive
* then (dag_node (*dag)[return_value] and '*dag' is a well-formed dag without witness data);
* '*census' contains a tally of the different tags that occur in 'dag' when the return value
* of the function is positive and when NULL != census;
* NULL == *dag when the return value is negative.
*/
int_fast32_t simplicity_decodeMallocDag(dag_node** dag, simplicity_callback_decodeJet decodeJet, combinator_counters* census, bitstream* stream);
#endif