#Experimental.Recursive Ocaml binding error
1 messages · Page 1 of 1 (latest)
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.
I'll take a look first thing tomorrow!
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?
Yes, it succeeds but it does not produce the correct hash.
Here is it:
https://github.com/mina-builders-team/anon-aadhaar-o1js/tree/static-hashing
By the way - i tried to run the hash-chain.ts, which has the similar conditional recursion mechanism. It works pretty fine - so i assume i don't have a local problem.
Any ideas on problem?
looking now! sorry
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
Hmmm... so it seems that is a deadlock for the current approach. Gotta find a workaround.
Thank you so much!
I’ll try to fix it but can’t estimate how long it will take
Any news about it 😦 @dire timber
Not yet, sorry :( I'll resurface it again
Thank you so much!
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?
Tbh i already applied some workaround-ish thing, by using recursive hashing method implemented in mina-attestations .
I just want to learn & understand how the error is solved
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
Is there an issue regarding this issue in the repo that i can see?
Thats where it is i guess