Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protocol): update PlonkVerifier to accept new public inputs #13208

Merged
merged 7 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
dantaik marked this conversation as resolved.
Show resolved Hide resolved
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(
dantaik marked this conversation as resolved.
Show resolved Hide resolved
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
)
);
}
}
Loading