ITADN

Convert split proofs for contract args

#15Pull Requestkatat 创建于 2023-11-27已合并
K
katatcommented
The following proof formats are converted in json to align with the contract interfaces. - main proof - merkle statements - fri merkle statements **Logic for merkle statements** ``` def build_merkle_proof_tx_args(input_json) -> Tuple[List[int], List[int], int, int]: """ Create a tx for merkle proof verification. """ statement_contract_input = MerkleStatement.load(data=input_json) return statement_contract_args(statement_contract_input) def statement_contract_args( statement_contract_input: MerkleStatement, ) -> Tuple[List[int], List[int], int, int]: return ( statement_contract_input.proof, statement_contract_input.merkle_queue, statement_contract_input.merkle_height, statement_contract_input. ``` **Logic for FRI merkle statements** ``` def build_fri_merkle_proof_tx_args(statement_contract_input: dict): """ Create a tx for fri-merkle proof verification. """ statement_contract_args = ( statement_contract_input["proof"], list(statement_contract_input["input_interleaved"]) + [0], statement_contract_input["evaluation_point"], statement_contract_input["fri_step_size"], statement_contract_input["expected_root"], ) return statement_contract_args ``` **Logic for main proof conversion** ``` def proof_hex2int_list(proof_hex: str) -> List[int]: """ Gets a hex string integer and returns it as a 256bits padded list of integer. This conversion is what's needed in order to send a binary proof (represented as a HexString) into an EVM deployed verifier. """ assert not proof_hex.startswith("0x"), "proof_hex must be without 0x prefix" chunk_size = 64 padded_proof = proof_hex.ljust(len(proof_hex) + (-len(proof_hex)) % chunk_size, "0") return [ int(chunk, 16) for chunk in ( padded_proof[i : i + chunk_size] for i in range(0, len(padded_proof), chunk_size) ) ] ```
合并状态:已合并 合并于 2023-11-28 关闭于 2023-11-28 0 条评论