#Experimental.Recursive Ocaml binding error

1 messages · Page 1 of 1 (latest)

full echo
#

Experimental.Recursive Ocaml binding error

full echo
#

While trying to figure out experimenting the Experimental.Recursive API ( see) with conditional hashing, i encountered an error that seems to be an OCaml level error:

 [
  0,
  [ 248, MlBytes { t: 0, c: 'Assert_failure', l: 14 }, -11 ],
  [
    0,
    MlBytes {
      t: 0,
      c: 'src/mina/src/lib/crypto/kimchi_backend/common/plonk_types.ml',
      l: 60
    },
    398,
    51
  ]
]
#

What i've been doing was this:


/**
 * Recursive hash that processes blocks in correct order
 */
const hashProgram = ZkProgram({
  name: 'recursive-hashing',
  publicOutput: State32,
  methods: {
    hashStep: {
      privateInputs: [DataBlocks, State32, Field, Field],
      async method(
        blocks: DataBlocks,
        currentState: State32,
        remainingBlocks: Field,
        currentIndex: Field
      ) {
        let shouldRecurse = Bool(false);

        const currentBlock = blocks.getBlockAt(currentIndex);

        const nextState = hashBlock256(currentState, currentBlock);

        const newRemainingBlocks = remainingBlocks.sub(Field.from(1));
        const nextIndex = currentIndex.add(Field.from(1));

        shouldRecurse = newRemainingBlocks.greaterThan(Field.from(0));

        const recursiveResult: State32 =
          await ReverseRecursiveHashProgram.hashStep.if(
            shouldRecurse,
            blocks,
            nextState,
            newRemainingBlocks,
            nextIndex
          );

        // Return the appropriate result
        const output = Provable.if(
          shouldRecurse,
          State32,
          recursiveResult,
          nextState
        );

        return {
          publicOutput: output,
        };
      },
    },
  },
});

let recursiveHash = Experimental.Recursive(hashProgram);
#

Where types State32and Block32are from mina-attestations.

DataBlocks class is like this:

class DataBlocks extends Struct({
  data: Provable.Array(Block32, 2),
}) {
  getBlockAt(idx: Field): Block32 {
    let result = this.data[0];

    for (let i = 0; i < 2; i++) {
      const isIdx = idx.equals(Field.from(i));
      result = Provable.if(isIdx, Block32, this.data[i], result);
    }
    return result;
  }
}

When proofsEnabled=false, everything works pretty well and output is as i desired.

But when it is true - the error i posted shows up.

GitHub

Private Attestations for Mina wallets. Contribute to zksecurity/mina-attestations development by creating an account on GitHub.

dire timber
#

I'll take a look first thing tomorrow!

dire timber
#

Can you share the entire example?

#

I assume commenting out this line

await ReverseRecursiveHashProgram.hashStep.if(
            shouldRecurse,
            blocks,
            nextState,
            newRemainingBlocks,
            nextIndex
          );

succeeds as expected, right?

full echo
full echo
full echo
#

Any ideas on problem?

dire timber
#

looking now! sorry

dire timber
#

Looks like the issue is that whenever the condition for recursiveHash.hashStep.if is false and the circuit uses a gadgets that requires a proof system feature flag to be enabled such as SHA256 then the dummy proof that's being generated not correctly account for the required feature flag

#

Looks like thats the issue Gregor was referring to a while ago

full echo
#

Hmmm... so it seems that is a deadlock for the current approach. Gotta find a workaround.

Thank you so much!

dire timber
#

I’ll try to fix it but can’t estimate how long it will take

full echo
#

Any news about it 😦 @dire timber

dire timber
full echo
#

Thank you so much!

full echo
#

Any updates on this ?

dire timber
# full echo Any updates on this ?

I did look into it and identified some of the issues but it's deep down in the recursive code so I had to put it on pause for now. Maybe we can find a workaround for you?

full echo
dire timber
# full echo Tbh i already applied some workaround-ish thing, by using recursive hashing meth...

I can explain it for you - the issue is that the recursive reducer relies on dummy proof to conditional verify them, which works fine, but if a real proof actually requires some specific feature flags to be set the dummy proof needs to set the exact same feature flags and that's where things go wrong - i added those feature flags to the dummy proof but they aren't propagated correctly into the lower levels of the crypto stack for some reason

full echo
#

Is there an issue regarding this issue in the repo that i can see?

dire timber
full echo