UAHF implementing sighash, specifically, how are scriptCodes serialized? I have managed to get correct sighashes for situations in which there are no OP_CODESEPARATOR ops in the code.  However, I cannot figure out, based on the UAHF documentation nor on the C++ code in the Bitcoin-ABC repository, how I am supposed to serialize the scriptCodes with the codeseparator OP.  Here is my serialization function (from the Picocoin C library):

void uahf_ser_scriptCode(cstring *s, const cstring *scriptCode){

    if(scriptCode == NULL){
        cstr_append_c(s, 0);
        return;
    }
    struct const_buffer it = { scriptCode-&gt;str, scriptCode-&gt;len };


    struct const_buffer itBegin = it;
    struct bscript_op op;
    unsigned int nCodeSeparators = 0;
    struct bscript_parser bp;

    bsp_start(&amp;bp, &amp;it);
    while (bsp_getop(&amp;op, &amp;bp)) {
        if (op.op == OP_CODESEPARATOR){
            nCodeSeparators++;
            fprintf(stderr,"code separator\n");
        }

    }


    if(nCodeSeparators == 0){
        ser_varlen(s, scriptCode-&gt;len);
        ser_bytes(s, scriptCode-&gt;str, scriptCode-&gt;len);
        return;
    }



    //ser_varlen(s, scriptCode-&gt;len - nCodeSeparators);
    it = itBegin;
    bsp_start(&amp;bp, &amp;it);
    int count = 0;
    cstring *x = cstr_new_sz(1024*10);
    while (bsp_getop(&amp;op, &amp;bp) &amp;&amp; count &lt; nCodeSeparators) {
        if (op.op == OP_CODESEPARATOR) {
            count++;
            //ser_bytes(s, itBegin.p, it.p - itBegin.p - 1);
            /*if(count == nCodeSeparators){
                ser_bytes(x, itBegin.p, it.p - itBegin.p - 1);
            }*/
            itBegin  = it;
        }
    }


    if (itBegin.p != scriptCode-&gt;str + scriptCode-&gt;len)
        ser_bytes(x, itBegin.p, it.p - itBegin.p);

    ser_varlen(s,  x-&gt;len);
    cstr_append_buf(s,x-&gt;str,x-&gt;len);
    cstr_free(x, true);

}
I probably was too eager to ask this question, though perhaps someone can take a look at how I implemented the solution in this pull request.  Here is the relevant code:

// from bp_tx_sigserializer function
void uahf_ser_scriptCode(cstring *s, const cstring *scriptCode){

    if(scriptCode == NULL){
        cstr_append_c(s, 0);
        return;
    }
    /** Serialize the passed scriptCode, skipping OP_CODESEPARATORs */
    struct const_buffer it = { scriptCode-&gt;str, scriptCode-&gt;len };
    struct const_buffer itBegin = it;
    struct bscript_op op;
    unsigned int nCodeSeparators = 0;

    struct bscript_parser bp;
    bsp_start(&amp;bp, &amp;it);

    while (bsp_getop(&amp;op, &amp;bp)) {
        if (op.op == OP_CODESEPARATOR)
            nCodeSeparators++;
    }
    cstring *x = cstr_new_sz(1024*8);

    it = itBegin;
    bsp_start(&amp;bp, &amp;it);

    while (bsp_getop(&amp;op, &amp;bp)) {
        if (op.op == OP_CODESEPARATOR) {
            ser_bytes(x, itBegin.p, it.p - itBegin.p - 1);
            itBegin  = it;
        }
    }

    if (itBegin.p != scriptCode-&gt;str + scriptCode-&gt;len)
        ser_bytes(x, itBegin.p, it.p - itBegin.p);

    if(0 &lt; nCodeSeparators){
        cstr_free(x, true);
        x = cstr_new_sz(1024*8);
        cstr_append_buf(x,scriptCode-&gt;str,scriptCode-&gt;len);
    }
    ser_varlen(s, x-&gt;len);
    cstr_append_buf(s,x-&gt;str,x-&gt;len);
    cstr_free(x, true);
}