Skip to content

Commit

Permalink
Merge branch 'main' into custom_errors_in_brige_contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
adaki2004 authored Feb 27, 2023
2 parents 85badc8 + 72f9c1d commit b14a791
Show file tree
Hide file tree
Showing 16 changed files with 4,512 additions and 1,708 deletions.
25 changes: 16 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,19 @@ library LibProving {
header.mixHash != meta.mixHash
) revert L1_META_MISMATCH();
}

function _getInstance(
Evidence memory evidence
) internal pure returns (bytes32) {
bytes[] memory list = LibBlockHeader.getBlockHeaderRLPItemsList(
evidence.header,
2
);

uint256 len = list.length;
list[len - 2] = LibRLPWriter.writeAddress(evidence.prover);
list[len - 1] = LibRLPWriter.writeHash(evidence.meta.txListHash);

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

function getBlockHeaderRLPItemsList(
BlockHeader memory header,
uint256 extraCapacity
) internal pure returns (bytes[] memory list) {
if (header.baseFeePerGas == 0) {
// non-EIP11559 transaction
list = new bytes[](15);
list = new bytes[](15 + extraCapacity);
} else {
// EIP1159 transaction
list = new bytes[](16);
list = new bytes[](16 + extraCapacity);
}
list[0] = LibRLPWriter.writeHash(header.parentHash);
list[1] = LibRLPWriter.writeHash(header.ommersHash);
Expand All @@ -63,9 +72,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

0 comments on commit b14a791

Please sign in to comment.