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): Add prover param #15758

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ library TaikoData {
}

struct TierProof {
address prover;
uint16 tier;
bytes data;
}
Expand Down
27 changes: 12 additions & 15 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ library LibProving {

// The new proof must meet or exceed the minimum tier required by the
// block or the previous proof; it cannot be on a lower tier.
if (proof.tier == 0 || proof.tier < meta.minTier || proof.tier < ts.tier) {
if (
proof.tier == 0 || proof.tier < meta.minTier || proof.tier < ts.tier
|| proof.prover == address(0)
) {
revert L1_INVALID_TIER();
}

Expand All @@ -128,7 +131,7 @@ library LibProving {
ITierProvider(resolver.resolve("tier_provider", false)).getTier(proof.tier);

// Check if this prover is allowed to submit a proof for this block
_checkProverPermission(state, blk, ts, tid, tier);
_checkProverPermission(state, blk, ts, tid, proof, tier);

// We must verify the proof, and any failure in proof verification will
// result in a revert.
Expand All @@ -153,13 +156,6 @@ library LibProving {
IVerifier.Context memory ctx = IVerifier.Context({
metaHash: blk.metaHash,
blobHash: meta.blobHash,
// TODO(Brecht): Quite limiting this is required to be the same address as
// msg.sender,
// less flexibility on the prover's side for proof generation/proof submission
// using
// multiple accounts.
// Added msgSender to allow the prover to be any address in the future.
prover: msg.sender,
msgSender: msg.sender,
blockId: blk.blockId,
isContesting: isContesting,
Expand Down Expand Up @@ -201,7 +197,7 @@ library LibProving {
emit TransitionProved({
blockId: blk.blockId,
tran: tran,
prover: msg.sender,
prover: proof.prover,
validityBond: tier.validityBond,
tier: proof.tier
});
Expand All @@ -215,22 +211,22 @@ library LibProving {
assert(tier.validityBond == 0);
assert(ts.validityBond == 0 && ts.contestBond == 0 && ts.contester == address(0));

ts.prover = msg.sender;
ts.prover = proof.prover;
ts.blockHash = tran.blockHash;
ts.stateRoot = tran.stateRoot;

emit TransitionProved({
blockId: blk.blockId,
tran: tran,
prover: msg.sender,
prover: proof.prover,
validityBond: 0,
tier: proof.tier
});
} else {
// Contesting but not on the highest tier
if (ts.contester != address(0)) revert L1_ALREADY_CONTESTED();

// Burn the contest bond from the prover.
// Burn the contest bond from the sender.
tko.transferFrom(msg.sender, address(this), tier.contestBond);

// We retain the contest bond within the transition, just in
Expand Down Expand Up @@ -382,7 +378,7 @@ library LibProving {
ts.validityBond = tier.validityBond;
ts.contestBond = 1; // to save gas
ts.contester = address(0);
ts.prover = msg.sender;
ts.prover = proof.prover;
ts.tier = proof.tier;

if (!sameTransition) {
Expand All @@ -397,6 +393,7 @@ library LibProving {
TaikoData.Block storage blk,
TaikoData.TransitionState storage ts,
uint32 tid,
TaikoData.TierProof memory proof,
ITierProvider.Tier memory tier
)
private
Expand All @@ -407,7 +404,7 @@ library LibProving {

bool inProvingWindow = uint256(ts.timestamp).max(state.slotB.lastUnpausedAt)
+ tier.provingWindow >= block.timestamp;
bool isAssignedPover = msg.sender == blk.assignedProver;
bool isAssignedPover = proof.prover == blk.assignedProver;

// The assigned prover can only submit the very first transition.
if (tid == 1 && ts.tier == 0 && inProvingWindow) {
Expand Down
3 changes: 1 addition & 2 deletions packages/protocol/contracts/verifiers/IVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ interface IVerifier {
struct Context {
bytes32 metaHash;
bytes32 blobHash;
address prover;
address msgSender;
uint64 blockId;
bool isContesting;
bool blobUsed;
address msgSender;
}

function verifyProof(
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/verifiers/PseZkVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract PseZkVerifier is EssentialContract, IVerifier {

bytes32 instance = calcInstance({
tran: tran,
prover: ctx.prover,
prover: proof.prover,
metaHash: ctx.metaHash,
txListHash: txListHash,
pointValue: pointValue
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/verifiers/SgxVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ contract SgxVerifier is EssentialContract, IVerifier {
bytes memory signature = Bytes.slice(proof.data, 24);

address oldInstance =
ECDSA.recover(getSignedHash(tran, newInstance, ctx.prover, ctx.metaHash), signature);
ECDSA.recover(getSignedHash(tran, newInstance, proof.prover, ctx.metaHash), signature);

if (!_isInstanceValid(id, oldInstance)) revert SGX_INVALID_INSTANCE();
_replaceInstance(id, oldInstance, newInstance);
Expand Down
8 changes: 5 additions & 3 deletions packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,11 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
__reserved: [bytes32(0), bytes32(0)]
});

TaikoData.TierProof memory proof;
proof.tier = LibTiers.TIER_GUARDIAN;
proof.data = bytes.concat(keccak256("RETURN_LIVENESS_BOND"));
TaikoData.TierProof memory proof = TaikoData.TierProof({
prover: Carol,
tier: LibTiers.TIER_GUARDIAN,
data: bytes.concat(keccak256("RETURN_LIVENESS_BOND"))
});

uint256 balanceBeforeReimbursement = tko.balanceOf(Bob);

Expand Down
1 change: 1 addition & 0 deletions packages/protocol/test/L1/TaikoL1TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ abstract contract TaikoL1TestBase is TaikoTest {
pv.calcInstance(tran, prover, keccak256(abi.encode(meta)), meta.blobHash, 0);

TaikoData.TierProof memory proof;
proof.prover = prover;
proof.tier = tier;
{
PseZkVerifier.ZkEvmProof memory zkProof;
Expand Down
10 changes: 6 additions & 4 deletions packages/protocol/test/verifiers/GuardianVerifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ contract TestGuardianVerifier is TaikoL1TestBase {
IVerifier.Context memory ctx = IVerifier.Context({
metaHash: bytes32(0),
blobHash: bytes32(0),
prover: address(gp),
msgSender: address(gp),
blockId: 10,
isContesting: false,
Expand All @@ -38,7 +37,7 @@ contract TestGuardianVerifier is TaikoL1TestBase {
});

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

// `verifyProof()`
gv.verifyProof(ctx, transition, proof);
Expand All @@ -50,7 +49,6 @@ contract TestGuardianVerifier is TaikoL1TestBase {
IVerifier.Context memory ctx = IVerifier.Context({
metaHash: bytes32(0),
blobHash: bytes32(0),
prover: Alice, // invalid
msgSender: Alice,
blockId: 10,
isContesting: false,
Expand All @@ -67,7 +65,11 @@ contract TestGuardianVerifier is TaikoL1TestBase {
});

// TierProof
TaikoData.TierProof memory proof = TaikoData.TierProof({ tier: 0, data: "" });
TaikoData.TierProof memory proof = TaikoData.TierProof({
prover: Alice, // invalid
tier: 0,
data: ""
});

// `verifyProof()` with invalid ctx.prover
vm.expectRevert(GuardianVerifier.PERMISSION_DENIED.selector);
Expand Down
Loading
Loading