Skip to content

Commit

Permalink
refactor(protocol): clean up permission code (whitelisting disabled) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Jan 3, 2023
1 parent dcb9ab7 commit 972f527
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 177 deletions.
9 changes: 0 additions & 9 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,4 @@ library TaikoData {
// Reserved
uint256[42] __gap;
}

struct TentativeState {
mapping(address => bool) proposers; // Whitelisted proposers
mapping(address => bool) provers; // Whitelisted provers
bool whitelistProposers;
bool whitelistProvers;
// // Reserved
uint256[46] __gap;
}
}
6 changes: 0 additions & 6 deletions packages/protocol/contracts/L1/TaikoEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,5 @@ abstract contract TaikoEvents {
address prover
);

event WhitelistingEnabled(bool whitelistProposers, bool whitelistProvers);

event ProposerWhitelisted(address indexed prover, bool whitelisted);

event ProverWhitelisted(address indexed prover, bool whitelisted);

event Halted(bool halted);
}
81 changes: 1 addition & 80 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {
using LibUtils for TaikoData.State;

TaikoData.State public state;
TaikoData.TentativeState public tentative;
uint256[50] private __gap;
uint256[100] private __gap;

function init(
address _addressManager,
Expand All @@ -40,9 +39,6 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {
genesisBlockHash: _genesisBlockHash,
feeBase: _feeBase
});

tentative.whitelistProposers = false;
tentative.whitelistProvers = true;
}

/**
Expand Down Expand Up @@ -88,7 +84,6 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {
LibProposing.proposeBlock({
state: state,
config: config,
tentative: tentative,
resolver: AddressResolver(this),
inputs: inputs
});
Expand Down Expand Up @@ -123,7 +118,6 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {
TaikoData.Config memory config = getConfig();
LibProving.proveBlock({
state: state,
tentative: tentative,
config: config,
resolver: AddressResolver(this),
blockId: blockId,
Expand Down Expand Up @@ -160,7 +154,6 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {

LibProving.proveBlockInvalid({
state: state,
tentative: tentative,
config: config,
resolver: AddressResolver(this),
blockId: blockId,
Expand Down Expand Up @@ -190,56 +183,6 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {
});
}

/**
* Enable or disable proposer and prover whitelisting
* @param whitelistProposers True to enable proposer whitelisting.
* @param whitelistProvers True to enable prover whitelisting.
*/
function enableWhitelisting(
bool whitelistProposers,
bool whitelistProvers
) public onlyOwner {
LibUtils.enableWhitelisting({
tentative: tentative,
whitelistProposers: whitelistProposers,
whitelistProvers: whitelistProvers
});
}

/**
* Add or remove a proposer from the whitelist.
*
* @param proposer The proposer to be added or removed.
* @param whitelisted True to add; remove otherwise.
*/
function whitelistProposer(
address proposer,
bool whitelisted
) public onlyOwner {
LibUtils.whitelistProposer({
tentative: tentative,
proposer: proposer,
whitelisted: whitelisted
});
}

/**
* 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 {
LibUtils.whitelistProver({
tentative: tentative,
prover: prover,
whitelisted: whitelisted
});
}

/**
* Halt or resume the chain.
* @param toHalt True to halt, false to resume.
Expand All @@ -248,28 +191,6 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {
LibUtils.halt(state, toHalt);
}

/**
* Check whether a proposer is whitelisted.
*
* @param proposer The proposer.
* @return True if the proposer is whitelisted, false otherwise.
*/
function isProposerWhitelisted(
address proposer
) public view returns (bool) {
return LibUtils.isProposerWhitelisted(tentative, proposer);
}

/**
* Check 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 LibUtils.isProverWhitelisted(tentative, prover);
}

function getBlockFee() public view returns (uint256) {
(, uint fee, uint deposit) = LibProposing.getBlockFee(
state,
Expand Down
12 changes: 1 addition & 11 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ library LibProposing {
);
event BlockProposed(uint256 indexed id, TaikoData.BlockMetadata meta);

modifier onlyWhitelistedProposer(
TaikoData.TentativeState storage tentative
) {
if (tentative.whitelistProposers) {
require(tentative.proposers[msg.sender], "L1:whitelist");
}
_;
}

function commitBlock(
TaikoData.State storage state,
TaikoData.Config memory config,
Expand Down Expand Up @@ -63,10 +54,9 @@ library LibProposing {
function proposeBlock(
TaikoData.State storage state,
TaikoData.Config memory config,
TaikoData.TentativeState storage tentative,
AddressResolver resolver,
bytes[] calldata inputs
) public onlyWhitelistedProposer(tentative) {
) public {
assert(!LibUtils.isHalted(state));

require(inputs.length == 2, "L1:inputs:size");
Expand Down
13 changes: 2 additions & 11 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,13 @@ library LibProving {
address prover
);

modifier onlyWhitelistedProver(TaikoData.TentativeState storage tentative) {
if (tentative.whitelistProvers) {
require(tentative.provers[msg.sender], "L1:whitelist");
}
_;
}

function proveBlock(
TaikoData.State storage state,
TaikoData.TentativeState storage tentative,
TaikoData.Config memory config,
AddressResolver resolver,
uint256 blockId,
bytes[] calldata inputs
) public onlyWhitelistedProver(tentative) {
) public {
assert(!LibUtils.isHalted(state));

// Check and decode inputs
Expand Down Expand Up @@ -157,12 +149,11 @@ library LibProving {

function proveBlockInvalid(
TaikoData.State storage state,
TaikoData.TentativeState storage tentative,
TaikoData.Config memory config,
AddressResolver resolver,
uint256 blockId,
bytes[] calldata inputs
) public onlyWhitelistedProver(tentative) {
) public {
assert(!LibUtils.isHalted(state));

// Check and decode inputs
Expand Down
60 changes: 0 additions & 60 deletions packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,8 @@ library LibUtils {

bytes32 public constant BLOCK_DEADEND_HASH = bytes32(uint256(1));

event WhitelistingEnabled(bool whitelistProposers, bool whitelistProvers);
event ProposerWhitelisted(address indexed proposer, bool whitelisted);
event ProverWhitelisted(address indexed prover, bool whitelisted);
event Halted(bool halted);

function enableWhitelisting(
TaikoData.TentativeState storage tentative,
bool whitelistProposers,
bool whitelistProvers
) internal {
tentative.whitelistProposers = whitelistProvers;
tentative.whitelistProvers = whitelistProvers;
emit WhitelistingEnabled(whitelistProposers, whitelistProvers);
}

function whitelistProposer(
TaikoData.TentativeState storage tentative,
address proposer,
bool whitelisted
) internal {
assert(tentative.whitelistProposers);
require(
proposer != address(0) &&
tentative.proposers[proposer] != whitelisted,
"L1:precondition"
);

tentative.proposers[proposer] = whitelisted;
emit ProposerWhitelisted(proposer, whitelisted);
}

function whitelistProver(
TaikoData.TentativeState storage tentative,
address prover,
bool whitelisted
) internal {
assert(tentative.whitelistProvers);
require(
prover != address(0) && tentative.provers[prover] != whitelisted,
"L1:precondition"
);

tentative.provers[prover] = whitelisted;
emit ProverWhitelisted(prover, whitelisted);
}

function halt(TaikoData.State storage state, bool toHalt) internal {
require(isHalted(state) != toHalt, "L1:precondition");
setBit(state, MASK_HALT, toHalt);
Expand Down Expand Up @@ -127,22 +83,6 @@ library LibUtils {
return isBitOne(state, MASK_HALT);
}

function isProposerWhitelisted(
TaikoData.TentativeState storage tentative,
address proposer
) internal view returns (bool) {
assert(tentative.whitelistProposers);
return tentative.proposers[proposer];
}

function isProverWhitelisted(
TaikoData.TentativeState storage tentative,
address prover
) internal view returns (bool) {
assert(tentative.whitelistProvers);
return tentative.provers[prover];
}

// Implement "Incentive Multipliers", see the whitepaper.
function getTimeAdjustedFee(
TaikoData.State storage state,
Expand Down

0 comments on commit 972f527

Please sign in to comment.