Skip to content

Commit

Permalink
feat(protocol): Modify LibProposing to accept oracle as assigned prov…
Browse files Browse the repository at this point in the history
…er (#14695)
  • Loading branch information
adaki2004 committed Sep 16, 2023
1 parent 6a2679a commit 52a50b7
Show file tree
Hide file tree
Showing 3 changed files with 4,334 additions and 3,504 deletions.
30 changes: 19 additions & 11 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ library LibProposing {
// Check prover assignment
if (
assignment.prover == address(0)
|| assignment.prover == LibUtils.ORACLE_PROVER
|| assignment.expiry <= block.timestamp
) {
revert L1_INVALID_ASSIGNMENT();
Expand All @@ -83,27 +82,34 @@ library LibProposing {
revert L1_TOO_MANY_BLOCKS();
}

TaikoToken tt = LibTaikoToken.receiveTaikoToken({
state: state,
resolver: resolver,
from: assignment.prover,
amount: config.proofBond
});
if (assignment.prover != LibUtils.ORACLE_PROVER) {
LibTaikoToken.receiveTaikoToken({
state: state,
resolver: resolver,
from: assignment.prover,
amount: config.proofBond
});

emit BondReceived(assignment.prover, b.numBlocks, config.proofBond);
emit BondReceived(assignment.prover, b.numBlocks, config.proofBond);
}

// Pay prover after verifying assignment
if (config.skipProverAssignmentVerificaiton) {
// For testing only
assignment.prover.sendEther(msg.value);
} else if (!assignment.prover.isContract()) {
address assignedProver = assignment.prover;
if (assignment.prover == LibUtils.ORACLE_PROVER) {
assignedProver = resolver.resolve("oracle_prover", false);
}

if (
_hashAssignment(input, assignment).recover(assignment.data)
!= assignment.prover
!= assignedProver
) {
revert L1_INVALID_PROVER_SIG();
}
assignment.prover.sendEther(msg.value);
assignedProver.sendEther(msg.value);
} else if (
assignment.prover.supportsInterface(type(IProver).interfaceId)
) {
Expand Down Expand Up @@ -145,7 +151,9 @@ library LibProposing {
);

// Reward must be minted
tt.mint(input.proposer, reward);
TaikoToken(resolver.resolve("taiko_token", false)).mint(
input.proposer, reward
);
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,22 @@ library LibVerifying {
signalRoot = tran.signalRoot;
blk.verifiedTransitionId = tid;

// Refund bond or give 1/4 of it to the actual prover and burn
// the rest.
if (
tran.prover == LibUtils.ORACLE_PROVER
|| tran.provenAt <= blk.proposedAt + config.proofWindow
) {
state.taikoTokenBalances[blk.prover] += blk.proofBond;
emit BondReturned(blk.prover, blockId, blk.proofBond);
} else {
uint256 rewardAmount = blk.proofBond / 4;
state.taikoTokenBalances[tran.prover] += rewardAmount;
emit BondRewarded(tran.prover, blockId, rewardAmount);
// If the default assigned prover is the oracle do not refund
// because was not even charged.
if (blk.prover != LibUtils.ORACLE_PROVER) {
// Refund bond or give 1/4 of it to the actual prover and
// burn the rest.
if (
tran.prover == LibUtils.ORACLE_PROVER
|| tran.provenAt <= blk.proposedAt + config.proofWindow
) {
state.taikoTokenBalances[blk.prover] += blk.proofBond;
emit BondReturned(blk.prover, blockId, blk.proofBond);
} else {
uint256 rewardAmount = blk.proofBond / 4;
state.taikoTokenBalances[tran.prover] += rewardAmount;
emit BondRewarded(tran.prover, blockId, rewardAmount);
}
}

emit BlockVerified(blockId, tran.prover, tran.blockHash);
Expand Down
Loading

0 comments on commit 52a50b7

Please sign in to comment.