Closed MartinMinkov closed 4 days ago
It's important to note that the documentation mentioning poseidon_3w_hash
and to_roinput
is incorrect and outdated. These functions are not used in the current implementation of the state hash derivation.
The actual process for deriving the stateHash
is as follows:
The state hash is computed in the hashes_abstract function within the Protocol_state
module. Here's the relevant code:
let hashes_abstract ~hash_body
({ previous_state_hash; body } : (State_hash.t, _) Poly.t) =
let state_body_hash : State_body_hash.t = hash_body body in
let state_hash =
Random_oracle.hash ~init:Hash_prefix.protocol_state
[| (previous_state_hash :> Field.t); (state_body_hash :> Field.t) |]
|> State_hash.of_hash
in
{ State_hash.State_hashes.state_hash
; state_body_hash = Some state_body_hash
}
The stateHash
(referred to as state_hash
in the code) is computed using the following steps:
a. It takes two inputs: previous_state_hash
and body
.
b. It first calculates the state_body_hash
by calling the hash_body
function on the body
.
c. It then uses a Random_oracle.hash
function to compute the state_hash
.
d. The Random_oracle.hash
function is initialized with Hash_prefix.protocol_state
.
e. The hash function takes an array of two elements:
previous_state_hash
converted to a Field.t
typestate_body_hash
converted to a Field.t
typef. The result is then converted to a State_hash.t
type using State_hash.of_hash
.
In the context of the blockchain snark, the hash_checked function is used to compute and verify the state hash within the SNARK circuit. This function is called in the step
function of the blockchain snark:
let%bind previous_state_hash, body = Protocol_state.hash_checked t in
And later:
let%bind h, _ = Protocol_state.hash_checked t in
with_label __LOC__ (fun () -> State_hash.assert_equal h new_state_hash)
We need to provide a detailed explanation of how the
stateHash
is derived in our OCaml code for Lambda's implementation of the Mina-EVM bridge. There's a specific focus on two functions mentioned in our documentation but not fully explained:poseidon_3w_hash
andto_roinput
.Objective:
Provide a clear and comprehensive explanation of the stateHash derivation process, including detailed information about the poseidon_3w_hash and to_roinput functions.
Key Points to Address:
Explain the overall process of deriving the stateHash.
Provide details on the
poseidon_3w_hash
function:Clarify the
to_roinput
function:Describe how these functions interact in the state hash derivation process.