-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol): decouple proof(s) verification from core protocol (#1…
…4221) Co-authored-by: adaki2004 <adaki2004@users.noreply.github.com> Co-authored-by: Daniel Wang <99078276+dantaik@users.noreply.github.com> Co-authored-by: Daniel Wang <dong77@gmail.com>
- Loading branch information
1 parent
570ae10
commit 4b23d14
Showing
7 changed files
with
181 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
// _____ _ _ _ _ | ||
// |_ _|_ _(_) |_____ | | __ _| |__ ___ | ||
// | |/ _` | | / / _ \ | |__/ _` | '_ (_-< | ||
// |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/ | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
interface IProofVerifier { | ||
/** | ||
* Verifying proof via the ProofVerifier contract. This function must throw | ||
* if verificaiton fails. | ||
* | ||
* @param blockId BlockId | ||
* @param blockProofs Raw bytes of proof(s) | ||
* @param instance Hashed evidence & config data | ||
*/ | ||
function verifyProofs( | ||
uint256 blockId, | ||
bytes calldata blockProofs, | ||
bytes32 instance | ||
) | ||
external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// SPDX-License-Identifier: MIT | ||
// _____ _ _ _ _ | ||
// |_ _|_ _(_) |_____ | | __ _| |__ ___ | ||
// | |/ _` | | / / _ \ | |__/ _` | '_ (_-< | ||
// |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/ | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import { AddressResolver } from "../common/AddressResolver.sol"; | ||
import { EssentialContract } from "../common/EssentialContract.sol"; | ||
import { Proxied } from "../common/Proxied.sol"; | ||
import { LibVerifyZKP } from "./libs/proofTypes/LibVerifyZKP.sol"; | ||
import { IProofVerifier } from "./IProofVerifier.sol"; | ||
import { LibBytesUtils } from "../thirdparty/LibBytesUtils.sol"; | ||
|
||
/// @custom:security-contact hello@taiko.xyz | ||
contract ProofVerifier is EssentialContract, IProofVerifier { | ||
uint256[50] private __gap; | ||
|
||
error L1_INVALID_PROOF(); | ||
|
||
function init(address _addressManager) external initializer { | ||
EssentialContract._init(_addressManager); | ||
} | ||
|
||
/** | ||
* Verifying proofs | ||
* | ||
* @param blockProofs Raw bytes of proof(s) | ||
*/ | ||
function verifyProofs( | ||
uint256, //Can be used later when supporting different types of proofs | ||
bytes calldata blockProofs, | ||
bytes32 instance | ||
) | ||
external | ||
view | ||
{ | ||
// Not checked if oracle/system prover | ||
if (instance == 0) return; | ||
|
||
if ( | ||
!LibBytesUtils.equal( | ||
LibBytesUtils.slice(blockProofs, 2, 32), | ||
bytes.concat(bytes16(0), bytes16(instance)) | ||
) | ||
) { | ||
revert L1_INVALID_PROOF(); | ||
} | ||
|
||
if ( | ||
!LibBytesUtils.equal( | ||
LibBytesUtils.slice(blockProofs, 34, 32), | ||
bytes.concat(bytes16(0), bytes16(uint128(uint256(instance)))) | ||
) | ||
) { | ||
revert L1_INVALID_PROOF(); | ||
} | ||
|
||
uint16 verifierId = uint16(bytes2(blockProofs[0:2])); | ||
|
||
// Verify ZK proof | ||
LibVerifyZKP.verifyProof( | ||
AddressResolver(address(this)), blockProofs[2:], verifierId | ||
); | ||
} | ||
} | ||
|
||
contract ProxiedProofVerifier is Proxied, ProofVerifier { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/protocol/contracts/L1/libs/proofTypes/LibVerifyZKP.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
// _____ _ _ _ _ | ||
// |_ _|_ _(_) |_____ | | __ _| |__ ___ | ||
// | |/ _` | | / / _ \ | |__/ _` | '_ (_-< | ||
// |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/ | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import { AddressResolver } from "../../../common/AddressResolver.sol"; | ||
import { LibUtils } from "../LibUtils.sol"; | ||
import { TaikoData } from "../../TaikoData.sol"; | ||
|
||
library LibVerifyZKP { | ||
error L1_INVALID_PROOF(); | ||
|
||
function verifyProof( | ||
AddressResolver resolver, | ||
bytes memory proof, | ||
uint16 verifierId | ||
) | ||
internal | ||
view | ||
{ | ||
(bool verified, bytes memory ret) = resolver.resolve( | ||
LibUtils.getVerifierName(verifierId), false | ||
).staticcall(bytes.concat(proof)); | ||
|
||
if (!verified || ret.length != 32 || bytes32(ret) != keccak256("taiko")) | ||
{ | ||
revert L1_INVALID_PROOF(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters