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): enable whitelisting provers (disabled for now) #287

Merged
merged 8 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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/LibData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ library LibData {
// block id => parent hash => fork choice
mapping(uint256 => mapping(bytes32 => ForkChoice)) forkChoices;
mapping(bytes32 => uint256) commits;
mapping(address => bool) provers; // Whitelisted provers
uint64 genesisHeight;
uint64 latestFinalizedHeight;
uint64 latestFinalizedId;
Expand Down
25 changes: 24 additions & 1 deletion packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract TaikoL1 is EssentialContract, IHeaderSync, V1Events {
using SafeCastUpgradeable for uint256;

LibData.State public state;
uint256[45] private __gap;
uint256[44] private __gap;

function init(
address _addressManager,
Expand Down Expand Up @@ -134,6 +134,29 @@ contract TaikoL1 is EssentialContract, IHeaderSync, V1Events {
);
}

/**
* Add or remove a prover from the whitelist.
*
* @param prover The prover to be added or removed.
* @param whitelisted True to add; remove otherwise.
*/
function whitelistProver(
address prover,
bool whitelisted
) public onlyOwner {
V1Proving.whitelistProver(state, prover, whitelisted);
}

/**
* Return whether a prover is whitelisted.
*
* @param prover The prover.
* @return True if the prover is whitelisted, false otherwise.
*/
function isProverWhitelisted(address prover) public view returns (bool) {
return V1Proving.isProverWhitelisted(state, prover);
}

/// @notice Finalize up to N blocks.
/// @param maxBlocks Max number of blocks to finalize.
function finalizeBlocks(uint256 maxBlocks) external nonReentrant {
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/contracts/L1/v1/V1Events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ abstract contract V1Events {
uint64 provenAt,
address prover
);

event ProverWhitelisted(address prover, bool whitelisted);
}
36 changes: 34 additions & 2 deletions packages/protocol/contracts/L1/v1/V1Proving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,21 @@ library V1Proving {
address prover
);

event ProverWhitelisted(address prover, bool whitelisted);

modifier onlyWhitelistedProver(LibData.State storage s) {
if (LibConstants.TAIKO_WHITELIST_PROVERS) {
require(s.provers[msg.sender], "L1:whitelist");
}
_;
}

function proveBlock(
LibData.State storage s,
AddressResolver resolver,
uint256 blockIndex,
bytes[] calldata inputs
) public {
) public onlyWhitelistedProver(s) {
// Check and decode inputs
require(inputs.length == 3, "L1:inputs:size");
Evidence memory evidence = abi.decode(inputs[0], (Evidence));
Expand Down Expand Up @@ -126,7 +135,7 @@ library V1Proving {
AddressResolver resolver,
uint256 blockIndex,
bytes[] calldata inputs
) public {
) public onlyWhitelistedProver(s) {
// Check and decode inputs
require(inputs.length == 3, "L1:inputs:size");
Evidence memory evidence = abi.decode(inputs[0], (Evidence));
Expand Down Expand Up @@ -182,6 +191,29 @@ library V1Proving {
);
}

function whitelistProver(
LibData.State storage s,
address prover,
bool enabled
) public {
require(LibConstants.TAIKO_WHITELIST_PROVERS, "L1:featureDisabled");
require(
prover != address(0) && s.provers[prover] != enabled,
"L1:precondition"
);

s.provers[prover] = enabled;
emit ProverWhitelisted(prover, enabled);
}

function isProverWhitelisted(
LibData.State storage s,
address prover
) public view returns (bool) {
require(LibConstants.TAIKO_WHITELIST_PROVERS, "L1:featureDisabled");
return s.provers[prover];
}

function _proveBlock(
LibData.State storage s,
AddressResolver resolver,
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/contracts/libs/LibConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ library LibConstants {

bytes32 public constant V1_INVALIDATE_BLOCK_LOG_TOPIC =
keccak256("BlockInvalidated(bytes32)");

bool public constant TAIKO_WHITELIST_PROVERS = false;
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯
pragma solidity ^0.8.9;


contract TestBadReceiver {
receive() external payable {
revert("can not send to this contract");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ contract TestLibBridgeRetry is EssentialContract {
EssentialContract._init(_addressManager);
}

function retryMessage(IBridge.Message calldata message, bool lastAttempt)
public
payable
{
function retryMessage(
IBridge.Message calldata message,
bool lastAttempt
) public payable {
LibBridgeRetry.retryMessage(
state,
AddressResolver(this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity ^0.8.9;
import "../../bridge/IBridge.sol";

contract TestMessageSender {

bytes32 signal = 0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abab;
bytes32 signal =
0x3fd54831f488a22b28398de0c567a3b064b937f54f81739ae9bd545967f3abab;

function sendMessage(
IBridge.Message calldata message
Expand Down