Skip to content

Commit

Permalink
fix(protocol): fix guardian prover (#16606)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Apr 2, 2024
1 parent 39d4be6 commit 643bd17
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
21 changes: 14 additions & 7 deletions packages/protocol/contracts/L1/provers/GuardianProver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ contract GuardianProver is Guardians {
/// @param blockId The block ID.
/// @param blockHash The block hash.
/// @param approved If the proof is approved.
/// @param proofData The proof data.
event GuardianApproval(
address indexed addr, uint256 indexed blockId, bytes32 blockHash, bool approved
address indexed addr,
uint256 indexed blockId,
bytes32 indexed blockHash,
bool approved,
bytes proofData
);

/// @notice Initializes the contract.
Expand All @@ -30,8 +35,7 @@ contract GuardianProver is Guardians {
/// @param _meta The block's metadata.
/// @param _tran The valid transition.
/// @param _proof The tier proof.
/// @return approved_ If the minimum number of participants sent the same proof, and proving
/// transaction is fired away returns true, false otherwise.
/// @return approved_ True if the minimum number of approval is acquired, false otherwise.
function approve(
TaikoData.BlockMetadata calldata _meta,
TaikoData.Transition calldata _tran,
Expand All @@ -42,15 +46,18 @@ contract GuardianProver is Guardians {
nonReentrant
returns (bool approved_)
{
if (_proof.tier != LibTiers.TIER_GUARDIAN) revert INVALID_PROOF();
bytes32 hash = keccak256(abi.encode(_meta, _tran));
if (_proof.tier != LibTiers.TIER_GUARDIAN) {
revert INVALID_PROOF();
}

bytes32 hash = keccak256(abi.encode(_meta, _tran, _proof.data));
approved_ = approve(_meta.id, hash);

emit GuardianApproval(msg.sender, _meta.id, _tran.blockHash, approved_, _proof.data);

if (approved_) {
deleteApproval(hash);
ITaikoL1(resolve("taiko", false)).proveBlock(_meta.id, abi.encode(_meta, _tran, _proof));
}

emit GuardianApproval(msg.sender, _meta.id, _tran.blockHash, approved_);
}
}
12 changes: 9 additions & 3 deletions packages/protocol/contracts/verifiers/GuardianVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
pragma solidity 0.8.24;

import "../common/EssentialContract.sol";
import "../L1/tiers/ITierProvider.sol";
import "./IVerifier.sol";

/// @title GuardianVerifier
/// @custom:security-contact [email protected]
contract GuardianVerifier is EssentialContract, IVerifier {
uint256[50] private __gap;

error PERMISSION_DENIED();
error GV_INVALID_PROOF();
error GV_PERMISSION_DENIED();

/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
Expand All @@ -22,13 +24,17 @@ contract GuardianVerifier is EssentialContract, IVerifier {
function verifyProof(
Context calldata _ctx,
TaikoData.Transition calldata,
TaikoData.TierProof calldata
TaikoData.TierProof calldata _proof
)
external
view
{
if (_proof.tier != LibTiers.TIER_GUARDIAN) {
revert GV_INVALID_PROOF();
}

if (_ctx.msgSender != resolve("guardian_prover", false)) {
revert PERMISSION_DENIED();
revert GV_PERMISSION_DENIED();
}
}
}
2 changes: 1 addition & 1 deletion packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
blockHash,
stateRoot,
LibTiers.TIER_GUARDIAN,
GuardianVerifier.PERMISSION_DENIED.selector
GuardianVerifier.GV_PERMISSION_DENIED.selector
);

vm.roll(block.number + 15 * 12);
Expand Down
8 changes: 5 additions & 3 deletions packages/protocol/test/verifiers/GuardianVerifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ contract TestGuardianVerifier is TaikoL1TestBase {
});

// TierProof
TaikoData.TierProof memory proof = TaikoData.TierProof({ tier: 0, data: "" });
TaikoData.TierProof memory proof =
TaikoData.TierProof({ tier: LibTiers.TIER_GUARDIAN, data: "" });

// `verifyProof()`
gv.verifyProof(ctx, transition, proof);
Expand Down Expand Up @@ -65,10 +66,11 @@ contract TestGuardianVerifier is TaikoL1TestBase {
});

// TierProof
TaikoData.TierProof memory proof = TaikoData.TierProof({ tier: 0, data: "" });
TaikoData.TierProof memory proof =
TaikoData.TierProof({ tier: LibTiers.TIER_GUARDIAN, data: "" });

// `verifyProof()` with invalid ctx.prover
vm.expectRevert(GuardianVerifier.PERMISSION_DENIED.selector);
vm.expectRevert(GuardianVerifier.GV_PERMISSION_DENIED.selector);
gv.verifyProof(ctx, transition, proof);
}
}
3 changes: 2 additions & 1 deletion packages/protocol/test/verifiers/SgxVerifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ contract TestSgxVerifier is TaikoL1TestBase, AttestationBase {
});

// TierProof
TaikoData.TierProof memory proof = TaikoData.TierProof({ tier: 0, data: "" });
TaikoData.TierProof memory proof =
TaikoData.TierProof({ tier: LibTiers.TIER_GUARDIAN, data: "" });

// `verifyProof()`
sv.verifyProof(ctx, transition, proof);
Expand Down

0 comments on commit 643bd17

Please sign in to comment.