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): Calculate fee/reward based on proof time w/ 1559 math #13489

Merged
merged 101 commits into from
Apr 22, 2023
Merged
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
167d957
change timebased fee calculation
dantaik Mar 24, 2023
c693da5
change timebased fee calculation
dantaik Mar 24, 2023
749c63f
change timebased fee calculation
dantaik Mar 24, 2023
d0c5c5a
Merge branch 'major_protocol_upgrade_rebase' into fee_reward_fix
dantaik Mar 24, 2023
d2cd0d5
Merge branch 'major_protocol_upgrade_rebase' into fee_reward_fix
dantaik Mar 24, 2023
ae82406
Merge branch 'major_protocol_upgrade_rebase' into fee_reward_fix
dantaik Mar 25, 2023
699a045
rename
dantaik Mar 26, 2023
fc5863f
Merge branch 'major_protocol_upgrade_rebase' into fee_reward_fix
dantaik Mar 27, 2023
975b057
rename
dantaik Mar 27, 2023
0e6242c
rename
dantaik Mar 27, 2023
b256bc1
implement 1559 for L2
dantaik Mar 27, 2023
0725c7a
implement 1559 for L2
dantaik Mar 27, 2023
ccec538
implement 1559 for L2
dantaik Mar 27, 2023
4f0162e
implement 1559 for L2
dantaik Mar 27, 2023
64548f0
implement 1559 for L2
dantaik Mar 27, 2023
c85f74e
implement 1559 for L2
dantaik Mar 27, 2023
c10f480
more
dantaik Mar 27, 2023
bafe0eb
fix tests
dantaik Mar 27, 2023
8ff0da3
fix tests
dantaik Mar 27, 2023
8a22c88
fix tests
dantaik Mar 27, 2023
b161046
fix tests
dantaik Mar 27, 2023
ca8dec2
fix tests
dantaik Mar 27, 2023
cd4605d
fix tests
dantaik Mar 27, 2023
467d1ad
fix tests
dantaik Mar 27, 2023
dcd55ec
fix tests
dantaik Mar 27, 2023
ec38ef3
fix tests
dantaik Mar 27, 2023
a48a6b7
fix tests
dantaik Mar 27, 2023
51df62e
fix tests
dantaik Mar 27, 2023
9010aea
fix tests
dantaik Mar 27, 2023
269896b
Merge branch 'fee_reward_fix' into L2_1559
dantaik Mar 27, 2023
95fc8cd
fix tests
dantaik Mar 27, 2023
80388a2
fix tests
dantaik Mar 27, 2023
718f25f
fix tests
dantaik Mar 27, 2023
45da2f6
Merge branch 'major_protocol_upgrade_rebase' into L2_1559
dantaik Mar 28, 2023
da2b35f
fix tests
dantaik Mar 28, 2023
8c6e3fa
fix tests
dantaik Mar 28, 2023
dd658eb
fix tests
dantaik Mar 28, 2023
f9bb2a9
Add FeeAndRewardConfig structure to calculate fee-rewards based on pr…
adaki2004 Mar 28, 2023
626957a
Following changes:
adaki2004 Mar 28, 2023
120d408
Changes
adaki2004 Mar 29, 2023
dc442e5
Delete logging and unnecessary vars and enable one additional test
adaki2004 Mar 29, 2023
a3be428
feat(protocol): calculate L2 EIP-1558 basefee on L1 (#13468)
dantaik Mar 30, 2023
81509c6
update foundry.toml
dantaik Mar 30, 2023
a4eae93
minor fix TaikoL2
dantaik Mar 30, 2023
9c1592c
fix
dantaik Mar 30, 2023
d287942
fix
dantaik Mar 30, 2023
e4ddb8d
+deploy_on_l1.sh
dantaik Mar 30, 2023
ee225b8
+deploy_on_l1.sh
dantaik Mar 30, 2023
c56dcbf
+deploy_on_l1.sh
dantaik Mar 30, 2023
5066081
Changes
adaki2004 Mar 30, 2023
51da738
Remove old archived files
adaki2004 Mar 30, 2023
9786d10
Remove archived test file
adaki2004 Mar 30, 2023
266b021
add doc
dantaik Mar 31, 2023
5b294a9
add doc
dantaik Mar 31, 2023
fcc1fac
+deploy_on_l1.sh
dantaik Mar 31, 2023
d9d4940
+deploy_on_l1.sh
dantaik Mar 31, 2023
45a94fa
+deploy_on_l1.sh
dantaik Mar 31, 2023
ccebb17
Changes:
adaki2004 Mar 31, 2023
867f384
Remove python algo
adaki2004 Mar 31, 2023
37c0928
PR review 1
adaki2004 Apr 1, 2023
22bb8f5
rebase with upstream
dantaik Apr 3, 2023
0a93f38
Changes:
adaki2004 Apr 3, 2023
eae7519
Added mechanism to pool and distribute rewards based on deposits
adaki2004 Apr 3, 2023
d5cc8e8
step1
dantaik Apr 4, 2023
b162d88
step1
dantaik Apr 4, 2023
13354c0
fix
dantaik Apr 4, 2023
475399e
fix
dantaik Apr 4, 2023
f5ed9c2
fix
dantaik Apr 4, 2023
be2d91a
fix
dantaik Apr 4, 2023
709c895
fix
dantaik Apr 4, 2023
1f73d97
fix
dantaik Apr 4, 2023
e3648b8
fix
dantaik Apr 4, 2023
c02042d
fix
dantaik Apr 4, 2023
e1b099d
fix
dantaik Apr 4, 2023
0a8f01d
fix
dantaik Apr 4, 2023
00ff4dc
fix
dantaik Apr 4, 2023
48f950c
fix
dantaik Apr 4, 2023
58936eb
fix
dantaik Apr 4, 2023
0945a2d
fix
dantaik Apr 4, 2023
1994877
fix
dantaik Apr 4, 2023
14e4fb7
fix
dantaik Apr 4, 2023
97330af
fix
dantaik Apr 4, 2023
24f1df9
PR review findings II.
adaki2004 Apr 4, 2023
93fee3a
Merge with base and resolve conflicts
adaki2004 Apr 4, 2023
f72110b
test(protocol): test 1559 calculation (#13534)
dantaik Apr 4, 2023
dd627c4
Remove unused libs
adaki2004 Apr 4, 2023
a7ec002
Drop typescript deployment task
adaki2004 Apr 4, 2023
e293932
Disable one (inentionally) failing tesst and remove unused gasAccumul…
adaki2004 Apr 4, 2023
6897c68
Merge branch 'L2_1559_rebase_in_anchor' into prove_time_based_rewards…
dantaik Apr 4, 2023
a05fb76
Deduct 1 from lastVerifiedBlock
adaki2004 Apr 4, 2023
cffbf21
refactor(protocol): recommend changes to Dani's PR (part1) (#13540)
dantaik Apr 17, 2023
10aa351
Function modifier and shadow declaration in test fix
adaki2004 Apr 17, 2023
5a4b51b
Resolve merge conflicts with base
adaki2004 Apr 18, 2023
c40f5a7
Merge branch 'major_protocol_upgrade_rebase' into prove_time_based_re…
adaki2004 Apr 18, 2023
be00cdc
Resolve build issues after massive merge conflicts fix
adaki2004 Apr 18, 2023
5fd3d91
Rename getProverFee to getBlockFee
adaki2004 Apr 18, 2023
6348487
Changes:
adaki2004 Apr 20, 2023
aa27af7
Merge branch 'major_protocol_upgrade_rebase' into prove_time_based_re…
dantaik Apr 21, 2023
d75f3b3
Changes:
adaki2004 Apr 21, 2023
519dca7
Change simulated L1 blocktime to 12
adaki2004 Apr 22, 2023
7537cd1
refactor(protocol): improve on top of Dani's PR (#13635)
dantaik Apr 22, 2023
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: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -45,7 +45,6 @@ taiko-mono/
│ ├── <a href="./packages/relayer">relayer</a>: Bridge backend relayer in Go
│ ├── <a href="./packages/starter-dapp">starter-dapp</a>: Template for Taiko dapps
│ ├── <a href="./packages/status-page">status-page</a>: Taiko protocol status page
│ ├── <a href="./packages/tokenomics">tokenomics</a>: Taiko tokenomics simulations
│ ├── <a href="./packages/website">website</a>: Main documentation website at taiko.xyz (https://taiko.xyz/)
│ └── <a href="./packages/whitepaper">whitepaper</a>: Whitepaper source files with automated publishing
...
3 changes: 2 additions & 1 deletion packages/protocol/.solhintignore
Original file line number Diff line number Diff line change
@@ -3,4 +3,5 @@ lib/
contracts/test/TestLibRLPReader.sol
contracts/test/TestLibRLPWriter.sol
**/contracts/thirdparty/**/*.sol
test2/GasComparison.t.sol
test2/GasComparison.t.sol
test2/TestLn.sol
17 changes: 3 additions & 14 deletions packages/protocol/contracts/L1/TaikoConfig.sol
Original file line number Diff line number Diff line change
@@ -31,26 +31,15 @@ library TaikoConfig {
// transactions list calldata, 8K for the remaining tx fields.
maxBytesPerTxList: 120000,
minTxGasLimit: 21000,
slotSmoothingFactor: 946649,
// 100 basis points or 1%
rewardBurnBips: 100,
proposerDepositPctg: 25, // - 25%
// Moving average factors
feeBaseMAF: 1024,
txListCacheExpiry: 0,
proofTimeTarget: 1800, // 85s based on A2 testnet status, or set to 1800 for 30mins (mainnet mock)
adjustmentQuotient: 16,
relaySignalRoot: false,
enableSoloProposer: false,
enableOracleProver: true,
enableTokenomics: true,
skipZKPVerification: false,
proposingConfig: TaikoData.FeeConfig({
avgTimeMAF: 1024,
dampingFactorBips: 2500 // [125% -> 75%]
}),
provingConfig: TaikoData.FeeConfig({
avgTimeMAF: 1024,
dampingFactorBips: 2500 // [75% -> 125%]
})
skipZKPVerification: false
});
}
}
50 changes: 22 additions & 28 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
@@ -7,11 +7,6 @@
pragma solidity ^0.8.18;

library TaikoData {
struct FeeConfig {
uint16 avgTimeMAF;
uint16 dampingFactorBips;
}

struct Config {
uint256 chainId;
uint256 maxNumProposedBlocks;
@@ -24,29 +19,26 @@ library TaikoData {
uint256 maxTransactionsPerBlock;
uint256 maxBytesPerTxList;
uint256 minTxGasLimit;
uint256 slotSmoothingFactor;
uint256 rewardBurnBips;
uint256 proposerDepositPctg;
// Moving average factors
uint256 feeBaseMAF;
uint256 txListCacheExpiry;
uint64 proofTimeTarget;
uint8 adjustmentQuotient;
bool relaySignalRoot;
bool enableSoloProposer;
bool enableOracleProver;
bool enableTokenomics;
bool skipZKPVerification;
FeeConfig proposingConfig;
FeeConfig provingConfig;
}

struct StateVariables {
uint64 feeBase;
uint64 basefee;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is blockFee a better name? Just asking, not sure...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, represent more what we mean ATM i agree - however if we do not stick to this tokenomics later on (which is definitely probable) it might be just a basefee + some staked/staking fee, or whatever. Currently indeed a blockfee, tho.

uint64 accBlockFees;
uint64 genesisHeight;
uint64 genesisTimestamp;
uint64 numBlocks;
uint64 proofTimeIssued;
uint64 lastVerifiedBlockId;
uint64 avgBlockTime;
uint64 avgProofTime;
uint64 accProposedAt;
uint64 lastProposedAt;
}

@@ -142,24 +134,26 @@ library TaikoData {
mapping(uint256 blockId => mapping(bytes32 parentHash => mapping(uint32 parentGasUsed => uint256 forkChoiceId))) forkChoiceIds;
mapping(address account => uint256 balance) balances;
mapping(bytes32 txListHash => TxListInfo) txListInfo;
// Never or rarely changed
// Slot 5: never or rarely changed
uint64 genesisHeight;
uint64 genesisTimestamp;
uint64 __reserved1;
uint64 __reserved2;
// Changed when a block is proposed or proven/verified
// Changed when a block is proposed
uint64 __reserved51;
uint64 __reserved52;
// Slot 6: changed by proposeBlock
uint64 lastProposedAt;
uint64 numBlocks;
uint64 lastProposedAt; // Timestamp when the last block is proposed.
uint64 avgBlockTime; // miliseconds
uint64 __reserved3;
// Changed when a block is proven/verified
uint64 accProposedAt; // also by verifyBlocks
uint64 accBlockFees; // also by verifyBlocks
// Slot 7: changed by proveBlock
// uint64 __reserved71;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets uncomment these 4 fields so we actually reserve a slot for them. Then change uint256[43] __gap; to uint256[42] __gap;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure i understand this. Uncomment these 4 used slots ? (accProposedAt, and rewardPool ?)

// uint64 __reserved72;
// uint64 __reserved73;
// uint64 __reserved74;
// Slot 8: changed by verifyBlocks
uint64 basefee;
uint64 proofTimeIssued;
uint64 lastVerifiedBlockId;
uint64 __reserved4;
// the proof time moving average, note that for each block, only the
// first proof's time is considered.
uint64 avgProofTime; // miliseconds
uint64 feeBase;
uint64 __reserved81;
// Reserved
uint256[43] __gap;
}
41 changes: 20 additions & 21 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
@@ -29,20 +29,23 @@ contract TaikoL1 is EssentialContract, IXchainSync, TaikoEvents, TaikoErrors {
* Initialize the rollup.
*
* @param _addressManager The AddressManager address.
* @param _feeBase The initial value of the proposer-fee/prover-reward feeBase.
* @param _genesisBlockHash The block hash of the genesis block.
* @param _initBasefee Initial (reasonable) basefee value.
* @param _initProofTimeIssued Initial proof time which keeps the inflow/outflow in balance
*/
function init(
address _addressManager,
uint64 _feeBase,
bytes32 _genesisBlockHash
bytes32 _genesisBlockHash,
uint64 _initBasefee,
uint64 _initProofTimeIssued
dantaik marked this conversation as resolved.
Show resolved Hide resolved
) external initializer {
EssentialContract._init(_addressManager);
LibVerifying.init({
state: state,
config: getConfig(),
feeBase: _feeBase,
genesisBlockHash: _genesisBlockHash
genesisBlockHash: _genesisBlockHash,
initBasefee: _initBasefee,
initProofTimeIssued: _initProofTimeIssued
});
}

@@ -155,27 +158,19 @@ contract TaikoL1 is EssentialContract, IXchainSync, TaikoEvents, TaikoErrors {
return state.balances[addr];
}

function getBlockFee()
public
view
returns (uint256 feeAmount, uint256 depositAmount)
{
(, feeAmount, depositAmount) = LibTokenomics.getBlockFee(
state,
getConfig()
);
function getBlockFee() public view returns (uint64) {
return state.basefee;
}

function getProofReward(
uint64 provenAt,
uint64 proposedAt
) public view returns (uint256 reward) {
(, reward, ) = LibTokenomics.getProofReward({
state: state,
config: getConfig(),
provenAt: provenAt,
proposedAt: proposedAt
});
) public view returns (uint64) {
return
LibTokenomics.getProofReward({
state: state,
proofTime: provenAt - proposedAt
});
}

function getBlock(
@@ -256,4 +251,8 @@ contract TaikoL1 is EssentialContract, IXchainSync, TaikoEvents, TaikoErrors {
function getConfig() public pure virtual returns (TaikoData.Config memory) {
return TaikoConfig.getConfig();
}

function getVerifierName(uint16 id) public pure returns (string memory) {
return LibUtils.getVerifierName(id);
}
}
37 changes: 6 additions & 31 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
@@ -90,45 +90,20 @@ library LibProposing {
blk.metaHash = LibUtils.hashMetadata(meta);
blk.proposer = msg.sender;

if (config.enableTokenomics) {
(uint256 newFeeBase, uint256 fee, uint64 deposit) = LibTokenomics
.getBlockFee(state, config);

uint256 burnAmount = fee + deposit;
if (state.balances[msg.sender] < burnAmount)
revert L1_INSUFFICIENT_TOKEN();

unchecked {
state.balances[msg.sender] -= burnAmount;
}

// Update feeBase and avgBlockTime
state.feeBase = LibUtils
.movingAverage({
maValue: state.feeBase,
newValue: newFeeBase,
maf: config.feeBaseMAF
})
.toUint64();

blk.deposit = uint64(deposit);
}
if (state.balances[msg.sender] < state.basefee)
revert L1_INSUFFICIENT_TOKEN();

unchecked {
state.avgBlockTime = LibUtils
.movingAverage({
maValue: state.avgBlockTime,
newValue: (meta.timestamp - state.lastProposedAt) * 1000,
maf: config.proposingConfig.avgTimeMAF
})
.toUint64();
state.lastProposedAt = meta.timestamp;
state.balances[msg.sender] -= state.basefee;
state.accBlockFees += state.basefee;
state.accProposedAt += meta.timestamp;
}

emit BlockProposed(state.numBlocks, meta);
unchecked {
++state.numBlocks;
}
state.lastProposedAt = meta.timestamp;
}

function getBlock(
10 changes: 4 additions & 6 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
@@ -201,13 +201,11 @@ library LibProving {
}
}

bytes memory verifierId = abi.encodePacked(
"verifier_",
evidence.zkproof.verifierId
);

(bool verified, bytes memory ret) = resolver
.resolve(string(verifierId), false)
.resolve(
LibUtils.getVerifierName(evidence.zkproof.verifierId),
false
)
.staticcall(bytes.concat(instance, evidence.zkproof.data));

if (
Loading