zksecurity / stark-evm-adapter

Adapt your STARK stone proofs for verifications on Ethereum
https://zksecurity.github.io/stark-evm-adapter/stark_evm_adapter/index.html
17 stars 4 forks source link

Convert split proofs for contract args #15

Closed katat closed 11 months ago

katat commented 11 months ago

The following proof formats are converted in json to align with the contract interfaces.

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)
        )
    ]