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 1 commit
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
Prev Previous commit
Next Next commit
rename
dantaik committed Mar 27, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 975b057114ddd0675b8512a63169826a37881be0
10 changes: 5 additions & 5 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import {EssentialContract} from "../common/EssentialContract.sol";
import {IXchainSync} from "../common/IXchainSync.sol";
import {LibProposing} from "./libs/LibProposing.sol";
import {LibProving} from "./libs/LibProving.sol";
import {LibTokenomics} from "./libs/LibVerifying.sol";
import {LibL1Tokenomics} from "./libs/LibVerifying.sol";
import {LibUtils} from "./libs/LibUtils.sol";
import {LibVerifying} from "./libs/LibVerifying.sol";
import {TaikoConfig} from "./TaikoConfig.sol";
@@ -115,11 +115,11 @@ contract TaikoL1 is EssentialContract, IXchainSync, TaikoEvents, TaikoErrors {
}

function deposit(uint256 amount) external nonReentrant {
LibTokenomics.deposit(state, AddressResolver(this), amount);
LibL1Tokenomics.deposit(state, AddressResolver(this), amount);
}

function withdraw(uint256 amount) external nonReentrant {
LibTokenomics.withdraw(state, AddressResolver(this), amount);
LibL1Tokenomics.withdraw(state, AddressResolver(this), amount);
}

function getBalance(address addr) public view returns (uint256) {
@@ -131,7 +131,7 @@ contract TaikoL1 is EssentialContract, IXchainSync, TaikoEvents, TaikoErrors {
view
returns (uint256 feeAmount, uint256 depositAmount)
{
(, feeAmount, depositAmount) = LibTokenomics.getBlockFee(
(, feeAmount, depositAmount) = LibL1Tokenomics.getBlockFee(
state,
getConfig()
);
@@ -141,7 +141,7 @@ contract TaikoL1 is EssentialContract, IXchainSync, TaikoEvents, TaikoErrors {
uint64 provenAt,
uint64 proposedAt
) public view returns (uint256 reward) {
(, reward, ) = LibTokenomics.getProofReward({
(, reward, ) = LibL1Tokenomics.getProofReward({
state: state,
config: getConfig(),
provenAt: provenAt,
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import {TaikoToken} from "../TaikoToken.sol";

// import {console2} from "forge-std/console2.sol";

library LibTokenomics {
library LibL1Tokenomics {
using LibMath for uint256;
uint256 private constant TWEI_TO_WEI = 1E12;

4 changes: 2 additions & 2 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
pragma solidity ^0.8.18;

import {AddressResolver} from "../../common/AddressResolver.sol";
import {LibTokenomics} from "./LibTokenomics.sol";
import {LibL1Tokenomics} from "./LibL1Tokenomics.sol";
import {LibUtils} from "./LibUtils.sol";
import {
SafeCastUpgradeable
@@ -89,7 +89,7 @@ library LibProposing {
blk.proposer = msg.sender;

if (config.enableTokenomics) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can also remove enableTokenomics and use state.baseFeeProof

if (state.baseFeeProof == 0) // not enabled.

(uint256 newFeeBase, uint256 fee, uint256 deposit) = LibTokenomics
(uint256 newFeeBase, uint256 fee, uint256 deposit) = LibL1Tokenomics
.getBlockFee(state, config);

uint256 burnAmount = fee + deposit;
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
pragma solidity ^0.8.18;

import {AddressResolver} from "../../common/AddressResolver.sol";
import {LibTokenomics} from "./LibTokenomics.sol";
import {LibL1Tokenomics} from "./LibL1Tokenomics.sol";
import {LibUtils} from "./LibUtils.sol";
import {TaikoData} from "../../L1/TaikoData.sol";

2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
pragma solidity ^0.8.18;

import {LibMath} from "../../libs/LibMath.sol";
import {LibTokenomics} from "./LibTokenomics.sol";
import {LibL1Tokenomics} from "./LibL1Tokenomics.sol";
import {
SafeCastUpgradeable
} from "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol";
4 changes: 2 additions & 2 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
pragma solidity ^0.8.18;

import {AddressResolver} from "../../common/AddressResolver.sol";
import {LibTokenomics} from "./LibTokenomics.sol";
import {LibL1Tokenomics} from "./LibL1Tokenomics.sol";
import {LibUtils} from "./LibUtils.sol";
import {
SafeCastUpgradeable
@@ -120,7 +120,7 @@ library LibVerifying {
uint256 newFeeBase,
uint256 amount,
uint256 premiumRate
) = LibTokenomics.getProofReward({
) = LibL1Tokenomics.getProofReward({
state: state,
config: config,
provenAt: fc.provenAt,
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@ pragma solidity ^0.8.18;
import {Test} from "forge-std/Test.sol";
import {console2} from "forge-std/console2.sol";
import {TaikoData} from "../contracts/L1/TaikoData.sol";
import {LibTokenomics} from "../contracts/L1/libs/LibTokenomics.sol";
import {LibL1Tokenomics} from "../contracts/L1/libs/LibL1Tokenomics.sol";

contract TaikoL1WithConfig is Test {
contract TestLibL1Tokenomics is Test {
struct FeeConfig {
uint64 avgTimeMAF;
uint64 avgTimeCap;
@@ -278,7 +278,7 @@ contract TaikoL1WithConfig is Test {
dampingFactorBips: dampingFactorBips
});

(uint256 _feeBase, uint256 _premiumRate) = LibTokenomics
(uint256 _feeBase, uint256 _premiumRate) = LibL1Tokenomics
.getTimeAdjustedFee(
feeConfig,
feeBase,
2 changes: 1 addition & 1 deletion packages/protocol/test2/TaikoL2.t.sol
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import "forge-std/Test.sol";
import "forge-std/console2.sol";
import "../contracts/L2/TaikoL2.sol";

contract ReadBlockhashVsCalldata is Test {
contract TestTaikoL2 is Test {
TaikoL2 public L2;

function setUp() public {
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ title: TaikoData
```solidity
struct FeeConfig {
uint16 avgTimeMAF;
uint16 startBips;
uint16 dampingFactorBips;
}
```

@@ -27,7 +27,6 @@ struct Config {
uint256 maxBytesPerTxList;
uint256 minTxGasLimit;
uint256 slotSmoothingFactor;
uint256 anchorTxGasLimit;
uint256 rewardBurnBips;
uint256 proposerDepositPctg;
uint256 feeBaseMAF;
@@ -107,7 +106,6 @@ struct BlockEvidence {
bytes32 blockHash;
bytes32 signalRoot;
address prover;
uint32 gasUsed;
}
```

Original file line number Diff line number Diff line change
@@ -16,12 +16,6 @@ error L1_ALREADY_PROVEN()
error L1_BLOCK_ID()
```

### L1_CONFLICT_PROOF

```solidity
error L1_CONFLICT_PROOF()
```

### L1_CONTRACT_NOT_ALLOWED

```solidity
Original file line number Diff line number Diff line change
@@ -16,6 +16,12 @@ event BlockProposed(uint256 id, struct TaikoData.BlockMetadata meta, bool txList
event BlockProven(uint256 id, bytes32 parentHash, bytes32 blockHash, bytes32 signalRoot, address prover)
```

### ConflictingProof

```solidity
event ConflictingProof(uint64 blockId, bytes32 parentHash, bytes32 conflictingBlockHash, bytes32 conflictingSignalRoot, bytes32 blockHash, bytes32 signalRoot)
```

### BlockVerified

```solidity
Original file line number Diff line number Diff line change
@@ -98,12 +98,6 @@ error TOKENVAULT_INVALID_TO()
error TOKENVAULT_INVALID_VALUE()
```

### TOKENVAULT_INVALID_CALL_VALUE

```solidity
error TOKENVAULT_INVALID_CALL_VALUE()
```

### TOKENVAULT_INVALID_TOKEN

```solidity
@@ -161,6 +155,9 @@ function sendEther(uint256 destChainId, address to, uint256 gasLimit, uint256 pr
Receives Ether and constructs a Bridge message. Sends the Ether and
message along to the Bridge.

_This function doesn't' seem to belong here as it has nothing to
do with ERC20 tokens. It's added here only for convenience._

#### Parameters

| Name | Type | Description |