Skip to content

Commit

Permalink
add abiEncode public input
Browse files Browse the repository at this point in the history
  • Loading branch information
Keszey Dániel authored and Keszey Dániel committed May 17, 2024
1 parent 75a6125 commit e895ea7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/protocol/contracts/verifiers/SP1Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ contract SP1Verifier is EssentialContract, IVerifier, SP1VerifierBase {
}

uint64 chainId = ITaikoL1(resolve(LibStrings.B_TAIKO, false)).getConfig().chainId;
bytes32 hash = LibPublicInput.hashPublicInputs(

bytes memory encodedPublicInput = LibPublicInput.abiEncodePublicInputs(
_tran, address(this), address(0), _ctx.prover, _ctx.metaHash, chainId
);

// @Brecht: Is 'hash' var the public value ? OR the input params of the LibPublicInput.hashPublicInputs() encoded as a bytes stream ?
this.verifyProof(programVKey, abi.encode(hash), proof);
this.verifyProof(programVKey, encodedPublicInput, proof);
// SP1VerifierBase.verifyProof() will revert if invalid
}
}
30 changes: 25 additions & 5 deletions packages/protocol/contracts/verifiers/libs/LibPublicInput.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,30 @@ library LibPublicInput {
pure
returns (bytes32)
{
return keccak256(
abi.encode(
"VERIFY_PROOF", _chainId, _verifierContract, _tran, _newInstance, _prover, _metaHash
)
);
return keccak256(abiEncodePublicInputs(_tran, _verifierContract,_newInstance, _prover, _metaHash, _chainId));
}

/// @notice Abi encode the public input for the proof verification.
/// @param _tran The transition to verify.
/// @param _verifierContract The contract address which as current verifier.
/// @param _newInstance The new instance address. For SGX it is the new signer address, for ZK
/// this variable is not used and must have value address(0).
/// @param _prover The prover address.
/// @param _metaHash The meta hash.
/// @param _chainId The chain id.
/// @return The public input hash.
function abiEncodePublicInputs(
TaikoData.Transition memory _tran,
address _verifierContract,
address _newInstance,
address _prover,
bytes32 _metaHash,
uint64 _chainId
)
internal
pure
returns (bytes memory)
{
return abi.encode("VERIFY_PROOF", _chainId, _verifierContract, _tran, _newInstance, _prover, _metaHash);
}
}

0 comments on commit e895ea7

Please sign in to comment.