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): Modify LibProposing to accept oracle as assigned prover #14695

Merged
merged 4 commits into from
Sep 16, 2023
Merged
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
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(
dantaik marked this conversation as resolved.
Show resolved Hide resolved
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