Skip to content

Commit

Permalink
feat(protocol): update PlonkVerifier to accept new public inputs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Feb 25, 2023
1 parent 0f281f4 commit 9804099
Show file tree
Hide file tree
Showing 14 changed files with 4,482 additions and 1,678 deletions.
30 changes: 21 additions & 9 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,6 @@ library LibProving {

if (!skipZKPVerification) {
for (uint256 i; i < config.zkProofsPerBlock; ++i) {
bytes32 instance = keccak256(
abi.encode(
blockHash,
evidence.prover,
evidence.meta.txListHash
)
);

if (
!proofVerifier.verifyZKP({
verifierId: string(
Expand All @@ -234,7 +226,7 @@ library LibProving {
)
),
zkproof: evidence.proofs[i],
instance: instance
instance: _getInstance(evidence)
})
) revert L1_ZKP();
}
Expand Down Expand Up @@ -459,4 +451,24 @@ library LibProving {
header.mixHash != meta.mixHash
) revert L1_META_MISMATCH();
}

function _getInstance(
Evidence memory evidence
) internal pure returns (bytes32 instance) {
bytes[] memory headerRLPItemsList = LibBlockHeader
.getBlockHeaderRLPItemsList(evidence.header);
bytes[] memory instanceRLPItemsList = new bytes[](
headerRLPItemsList.length + 2
);

for (uint256 i; i < headerRLPItemsList.length; ++i) {
instanceRLPItemsList[i] = headerRLPItemsList[i];
}
instanceRLPItemsList[headerRLPItemsList.length] = LibRLPWriter
.writeAddress(evidence.prover);
instanceRLPItemsList[headerRLPItemsList.length + 1] = LibRLPWriter
.writeHash(evidence.meta.txListHash);

instance = keccak256(LibRLPWriter.writeList(instanceRLPItemsList));
}
}
13 changes: 9 additions & 4 deletions packages/protocol/contracts/libs/LibBlockHeader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ library LibBlockHeader {
function hashBlockHeader(
BlockHeader memory header
) internal pure returns (bytes32) {
bytes[] memory list;
bytes memory rlpHeader = LibRLPWriter.writeList(
getBlockHeaderRLPItemsList(header)
);
return keccak256(rlpHeader);
}

function getBlockHeaderRLPItemsList(
BlockHeader memory header
) internal pure returns (bytes[] memory list) {
if (header.baseFeePerGas == 0) {
// non-EIP11559 transaction
list = new bytes[](15);
Expand Down Expand Up @@ -63,9 +71,6 @@ library LibBlockHeader {
// non-EIP11559 transaction
list[15] = LibRLPWriter.writeUint(header.baseFeePerGas);
}

bytes memory rlpHeader = LibRLPWriter.writeList(list);
return keccak256(rlpHeader);
}

function isPartiallyValidForTaiko(
Expand Down
13 changes: 9 additions & 4 deletions packages/protocol/contracts/libs/LibZKP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ library LibZKP {
bytes calldata zkproof,
bytes32 instance
) internal view returns (bool verified) {
// TODO(david):public input is assembled in client software
// for testing purposes right now, move this part of logic
// here in this contract.
(verified, ) = plonkVerifier.staticcall(zkproof);
(verified, ) = plonkVerifier.staticcall(
bytes.concat(
bytes16(0),
bytes16(instance), // left 16 bytes of the given instance
bytes16(0),
bytes16(uint128(uint256(instance))), // right 16 bytes of the given instance
zkproof
)
);
}
}

0 comments on commit 9804099

Please sign in to comment.