Skip to content

Commit

Permalink
feat(protocol): force assigned prover to be the block's proposer (#17575
Browse files Browse the repository at this point in the history
)

Co-authored-by: dantaik <[email protected]>
  • Loading branch information
dantaik and dantaik authored Jun 13, 2024
1 parent 0863c91 commit 1194f53
Show file tree
Hide file tree
Showing 28 changed files with 462 additions and 818 deletions.
16 changes: 0 additions & 16 deletions packages/protocol/contract_layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,22 +360,6 @@
| __gap | uint256[46] | 355 | 0 | 1472 | contracts/tokenvault/BridgedERC1155.sol:BridgedERC1155 |

## AssignmentHook
| Name | Type | Slot | Offset | Bytes | Contract |
|----------------|-------------|------|--------|-------|------------------------------------------------------|
| _initialized | uint8 | 0 | 0 | 1 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| _initializing | bool | 0 | 1 | 1 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| __gap | uint256[50] | 1 | 0 | 1600 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| _owner | address | 51 | 0 | 20 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| __gap | uint256[49] | 52 | 0 | 1568 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| _pendingOwner | address | 101 | 0 | 20 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| __gap | uint256[49] | 102 | 0 | 1568 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| addressManager | address | 151 | 0 | 20 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| __gap | uint256[49] | 152 | 0 | 1568 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| __reentry | uint8 | 201 | 0 | 1 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| __paused | uint8 | 201 | 1 | 1 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| lastUnpausedAt | uint64 | 201 | 2 | 8 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| __gap | uint256[49] | 202 | 0 | 1568 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |
| __gap | uint256[50] | 251 | 0 | 1600 | contracts/L1/hooks/AssignmentHook.sol:AssignmentHook |

## ERC20Airdrop
| Name | Type | Slot | Offset | Bytes | Contract |
Expand Down
3 changes: 1 addition & 2 deletions packages/protocol/contracts/L1/ITaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ interface ITaikoL1 {
/// @param _params Block parameters, currently an encoded BlockParams object.
/// @param _txList txList data if calldata is used for DA.
/// @return meta_ The metadata of the proposed L2 block.
/// @return deposits_ The Ether deposits processed.
function proposeBlock(
bytes calldata _params,
bytes calldata _txList
)
external
payable
returns (TaikoData.BlockMetadata memory meta_, TaikoData.EthDeposit[] memory deposits_);
returns (TaikoData.BlockMetadataV2 memory meta_);

/// @notice Proves or contests a block transition.
/// @param _blockId The index of the block to prove. This is also used to
Expand Down
46 changes: 32 additions & 14 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ library TaikoData {
// Group 4: Cross-chain sync
// ---------------------------------------------------------------------
// The max number of L2 blocks that can stay unsynced on L1
uint8 blockSyncThreshold;
uint8 stateRootSyncInternal;
bool checkEOAForCalldataDA;
uint64 forkHeight;
}

/// @dev Struct representing prover fees per given tier
Expand Down Expand Up @@ -66,6 +67,13 @@ library TaikoData {
bytes signature;
}

struct BlockParamsV2 {
address coinbase;
bytes32 extraData;
bytes32 parentMetaHash;
bytes signature;
}

/// @dev Struct containing data only required for proving a block
/// Note: On L2, `block.difficulty` is the pseudo name of
/// `block.prevrandao`, which returns a random number provided by the layer
Expand All @@ -84,7 +92,25 @@ library TaikoData {
uint16 minTier;
bool blobUsed;
bytes32 parentMetaHash;
address sender; // a.k.a proposer
address sender;
}

struct BlockMetadataV2 {
bytes32 l1Hash;
bytes32 difficulty;
bytes32 blobHash; //or txListHash (if Blob not yet supported)
bytes32 extraData;
bytes32 depositsHash;
address coinbase; // L2 coinbase,
uint64 id;
uint32 gasLimit;
uint64 timestamp;
uint64 l1Height;
uint16 minTier;
bool blobUsed;
bytes32 parentMetaHash;
address proposer;
uint96 livenessBond;
}

/// @dev Struct representing transition to be proven.
Expand Down Expand Up @@ -114,27 +140,19 @@ library TaikoData {
/// 3 slots used.
struct Block {
bytes32 metaHash; // slot 1
address assignedProver; // slot 2
uint96 livenessBond;
address assignedProver; // slot 2, DEPRECATED and will always be zero
uint96 livenessBond; // DEPRECATED and will always be zero
uint64 blockId; // slot 3
uint64 proposedAt; // timestamp
uint64 proposedIn; // L1 block number, required/used by node/client.
uint48 proposedIn; // L1 block number, required/used by node/client.
bool livenessBondNotReturned;
uint32 nextTransitionId;
// The ID of the transaction that is used to verify this block. However, if
// this block is not verified as the last block in a batch, verifiedTransitionId
// will remain zero.
uint32 verifiedTransitionId;
}

/// @dev Struct representing an Ethereum deposit.
/// 2 slot used. Currently removed from protocol, but to be backwards compatible, the struct and
/// return values stayed for now.
struct EthDeposit {
address recipient;
uint96 amount;
uint64 id;
}

/// @dev Forge is only able to run coverage in case the contracts by default
/// capable of compiling without any optimization (neither optimizer runs,
/// no compiling --via-ir flag).
Expand Down
1 change: 0 additions & 1 deletion packages/protocol/contracts/L1/TaikoErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ abstract contract TaikoErrors {
error L1_INVALID_BLOCK_ID();
error L1_INVALID_CONFIG();
error L1_INVALID_GENESIS_HASH();
error L1_INVALID_HOOK();
error L1_INVALID_PARAM();
error L1_INVALID_PAUSE_STATUS();
error L1_INVALID_PROVER();
Expand Down
18 changes: 4 additions & 14 deletions packages/protocol/contracts/L1/TaikoEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,11 @@ import "./TaikoData.sol";
/// L1 libraries.
/// @custom:security-contact [email protected]
abstract contract TaikoEvents {
/// @dev Emitted when a block is proposed.
// Warning: Any events defined here must also be defined in TaikoEvents.sol.
/// @notice Emitted when a block is proposed.
/// @param blockId The ID of the proposed block.
/// @param assignedProver The block's assigned prover.
/// @param livenessBond The bond in Taiko token from the assigned prover.
/// @param meta The block metadata containing information about the proposed
/// block.
/// @param depositsProcessed Ether deposits processed.
event BlockProposed(
uint256 indexed blockId,
address indexed assignedProver,
uint96 livenessBond,
TaikoData.BlockMetadata meta,
TaikoData.EthDeposit[] depositsProcessed
);

/// @param meta The metadata of the proposed block.
event BlockProposedV2(uint256 indexed blockId, TaikoData.BlockMetadataV2 meta);
/// @dev Emitted when a block is verified.
/// @param blockId The ID of the verified block.
/// @param prover The prover whose transition is used for verifying the
Expand Down
15 changes: 9 additions & 6 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
whenNotPaused
nonReentrant
emitEventForClient
returns (TaikoData.BlockMetadata memory meta_, TaikoData.EthDeposit[] memory deposits_)
returns (TaikoData.BlockMetadataV2 memory meta_)
{
TaikoData.Config memory config = getConfig();
IERC20 tko = IERC20(resolve(LibStrings.B_TAIKO_TOKEN, false));

(meta_, deposits_) = LibProposing.proposeBlock(state, tko, config, this, _params, _txList);
meta_ = LibProposing.proposeBlock(state, tko, config, this, _params, _txList);

if (LibUtils.shouldVerifyBlocks(config, meta_.id, true) && !state.slotB.provingPaused) {
LibVerifying.verifyBlocks(state, tko, config, this, config.maxBlocksToVerify);
Expand All @@ -100,10 +100,12 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
emitEventForClient
{
(
TaikoData.BlockMetadata memory meta,
TaikoData.BlockMetadataV2 memory meta,
TaikoData.Transition memory tran,
TaikoData.TierProof memory proof
) = abi.decode(_input, (TaikoData.BlockMetadata, TaikoData.Transition, TaikoData.TierProof));
) = abi.decode(
_input, (TaikoData.BlockMetadataV2, TaikoData.Transition, TaikoData.TierProof)
);

if (_blockId != meta.id) revert L1_INVALID_BLOCK_ID();

Expand Down Expand Up @@ -241,8 +243,9 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
// read Taiko's gas limit to be 240_250_000.
blockMaxGasLimit: 240_000_000,
livenessBond: 250e18, // 250 Taiko token
blockSyncThreshold: 32,
checkEOAForCalldataDA: true
stateRootSyncInternal: 16,
checkEOAForCalldataDA: true,
forkHeight: 0
});
}

Expand Down
194 changes: 0 additions & 194 deletions packages/protocol/contracts/L1/hooks/AssignmentHook.sol

This file was deleted.

Loading

0 comments on commit 1194f53

Please sign in to comment.