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): Auctioning - DRAFT, not ready #13811

Closed
wants to merge 12 commits into from
Closed
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
2 changes: 1 addition & 1 deletion packages/eventindexer/contracts/taikol1/TaikoL1.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions packages/protocol/contracts/L1/TaikoConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ library TaikoConfig {
ethDepositGas: 21000,
ethDepositMaxFee: 1 ether / 10,
txListCacheExpiry: 0,
adjustmentQuotient: 16,
relaySignalRoot: false
relaySignalRoot: false,
auctionDelayInSeconds: 100, // lasts 100 seconds after a bid
auctionTimeForProverToSubmitProofInSeconds: 1000, //
proposerBlockFeeMultiplier: 2
});
}
}
39 changes: 27 additions & 12 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,33 @@ library TaikoData {
uint256 realProofSkipSize;
uint256 ethDepositGas;
uint256 ethDepositMaxFee;
uint256 auctionDelayInSeconds;
uint256 auctionTimeForProverToSubmitProofInSeconds;
uint256 proposerBlockFeeMultiplier;
uint64 minEthDepositsPerBlock;
uint64 maxEthDepositsPerBlock;
uint96 maxEthDepositAmount;
uint96 minEthDepositAmount;
uint8 adjustmentQuotient;
// how many blocks you win per batch
uint64 auctionBlockBatchSize;
// how many blocks past lastVerifiedId you can bid for
uint64 auctionBatchGap;
// how long after initial bid the auction lives for
uint256 auctionLengthInSeconds;
bool relaySignalRoot;
}

struct StateVariables {
uint64 blockFee;
uint64 accBlockFees;
uint64 genesisHeight;
uint64 genesisTimestamp;
uint64 numBlocks;
uint64 proofTimeIssued;
uint64 proofTimeTarget;
uint64 lastVerifiedBlockId;
uint64 accProposedAt;
uint64 nextEthDepositToProcess;
uint64 numEthDeposits;
uint256 avgProofTime;
uint256 avgProofReward;
uint256 avgSuccessfulBidFeePerGas;
}

// 3 slots
Expand Down Expand Up @@ -119,6 +126,14 @@ library TaikoData {
uint96 amount;
}

struct Bid {
uint256 feePerGasInWei;
uint256 batchId;
uint256 deposit;
address bidder;
uint256 auctionStartedAt;
}

struct State {
// Ring buffer for proposed blocks and a some recent verified blocks.
mapping(uint256 blockId_mode_ringBufferSize => Block) blocks;
Expand All @@ -131,24 +146,24 @@ library TaikoData {
) forkChoiceIds;
mapping(address account => uint256 balance) taikoTokenBalances;
mapping(bytes32 txListHash => TxListInfo) txListInfo;
mapping(uint256 batchId => Bid bid) bids;
EthDeposit[] ethDeposits;
// Never or rarely changed
// Slot 7: never or rarely changed
uint64 genesisHeight;
uint64 genesisTimestamp;
uint64 __reserved71;
uint64 __reserved72;
// Slot 8
uint64 accProposedAt;
uint64 accBlockFees;
uint64 numBlocks;
// Slot 8
uint64 nextEthDepositToProcess;
// Slot 9
uint64 blockFee;
uint64 proofTimeIssued;
uint64 lastVerifiedBlockId;
uint64 proofTimeTarget;
uint64 __reversed71;
uint256 avgProofTime;
uint256 avgProofReward;
uint256 avgSuccessfulBidFeePerGas;
// Reserved
uint256[42] __gap;
uint256[38] __gap;
}
}
1 change: 1 addition & 0 deletions packages/protocol/contracts/L1/TaikoErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ abstract contract TaikoErrors {
error L1_TX_LIST_HASH();
error L1_TX_LIST_RANGE();
error L1_TX_LIST();
error L1_AUCTION_NOT_OVER();
}
15 changes: 14 additions & 1 deletion packages/protocol/contracts/L1/TaikoEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,18 @@ abstract contract TaikoEvents {

event EthDeposited(TaikoData.EthDeposit deposit);

event ProofTimeTargetChanged(uint64 proofTimeTarget);
event Bid(
uint256 batchId,
address bidder,
uint256 bidAt,
uint256 deposit,
uint256 minFeePerGas,
uint256 weight,
uint256 auctionStartedAt,
uint256 feePerGasInWei
);

event BidDepositRefunded(
uint256 indexed id, address claimer, uint256 refundedAt, uint256 refund
);
}
65 changes: 20 additions & 45 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {AddressResolver} from "../common/AddressResolver.sol";
import {EssentialContract} from "../common/EssentialContract.sol";
import {ICrossChainSync} from "../common/ICrossChainSync.sol";
import {Proxied} from "../common/Proxied.sol";
import {LibAuction} from "./libs/LibAuction.sol";
import {LibEthDepositing} from "./libs/LibEthDepositing.sol";
import {LibTokenomics} from "./libs/LibTokenomics.sol";
import {LibProposing} from "./libs/LibProposing.sol";
Expand Down Expand Up @@ -37,26 +38,27 @@ contract TaikoL1 is EssentialContract, ICrossChainSync, TaikoEvents, TaikoErrors
*
* @param _addressManager The AddressManager address.
* @param _genesisBlockHash The block hash of the genesis block.
* @param _initBlockFee Initial (reasonable) block fee value.
* @param _initProofTimeTarget Initial (reasonable) proof submission time target.
* @param _initProofTimeIssued Initial proof time issued corresponding
* with the initial block fee.
*/
function init(
address _addressManager,
bytes32 _genesisBlockHash,
uint64 _initBlockFee,
uint64 _initProofTimeTarget,
uint64 _initProofTimeIssued
) external initializer {
function init(address _addressManager, bytes32 _genesisBlockHash) external initializer {
EssentialContract._init(_addressManager);
LibVerifying.init({
LibVerifying.init({state: state, config: getConfig(), genesisBlockHash: _genesisBlockHash});
}

/**
* Propose a Taiko L2 block.
*
* @param batchId the id of the batch you are submitting a bid for.
* @param feePerGasInWei The minimum fee, in wei, per gas you will accept
* being paid as a reward for proving the block.
*/

function bidForBatch(uint256 batchId, uint256 feePerGasInWei) external payable nonReentrant {
LibAuction.bidForBatch({
state: state,
resolver: AddressResolver(this),
config: getConfig(),
genesisBlockHash: _genesisBlockHash,
initBlockFee: _initBlockFee,
initProofTimeTarget: _initProofTimeTarget,
initProofTimeIssued: _initProofTimeIssued
batchId: batchId,
feePerGasInWei: feePerGasInWei
});
}

Expand Down Expand Up @@ -134,29 +136,6 @@ contract TaikoL1 is EssentialContract, ICrossChainSync, TaikoEvents, TaikoErrors
});
}

/**
* Change proof parameters (time target and time issued) - to avoid complex/risky upgrades in case need to change relatively frequently.
* @param newProofTimeTarget New proof time target.
* @param newProofTimeIssued New proof time issued. If set to type(uint64).max, let it be unchanged.
*/
function setProofParams(uint64 newProofTimeTarget, uint64 newProofTimeIssued)
external
onlyOwner
{
if (newProofTimeTarget == 0 || newProofTimeIssued == 0) {
revert L1_INVALID_PARAM();
}

state.proofTimeTarget = newProofTimeTarget;
// Special case in a way - that we leave the proofTimeIssued unchanged
// because we think provers will adjust behavior.
if (newProofTimeIssued != type(uint64).max) {
state.proofTimeIssued = newProofTimeIssued;
}

emit ProofTimeTargetChanged(newProofTimeTarget);
}

function depositTaikoToken(uint256 amount) external nonReentrant {
LibTokenomics.depositTaikoToken(state, AddressResolver(this), amount);
}
Expand All @@ -173,12 +152,8 @@ contract TaikoL1 is EssentialContract, ICrossChainSync, TaikoEvents, TaikoErrors
return state.taikoTokenBalances[addr];
}

function getBlockFee() public view returns (uint64) {
return state.blockFee;
}

function getProofReward(uint64 proofTime) public view returns (uint64) {
return LibTokenomics.getProofReward(state, proofTime);
function getBlockFee() public view returns (uint256) {
return LibProposing.getBlockFee(getConfig(), state);
}

function getBlock(uint256 blockId)
Expand Down
Loading