Skip to content

Commit

Permalink
fix(tests): cleanup tests to prepare for tokenomics testing (#11316)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Jan 14, 2023
1 parent 9837fa3 commit d63fae3
Show file tree
Hide file tree
Showing 55 changed files with 2,198 additions and 1,447 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/solidity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
working-directory: ./packages/protocol
run: pnpm test:integration

- name: protocol - Tokenomics Tests
working-directory: ./packages/protocol
run: pnpm test:tokenomics

- name: protocol - Test Coverage
working-directory: ./packages/protocol
run: pnpm test:coverage
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ library TaikoData {
uint64 feeMaxPeriodPctg;
uint64 blockTimeCap;
uint64 proofTimeCap;
uint64 boostrapDiscountHalvingPeriod;
uint64 bootstrapDiscountHalvingPeriod;
uint64 initialUncleDelay;
bool enableTokenomics;
bool enablePublicInputsCheck;
}

struct BlockMetadata {
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ library LibUtils {
uint256 feeBase
) internal view returns (uint256) {
uint256 halves = uint256(block.timestamp - state.genesisTimestamp) /
config.boostrapDiscountHalvingPeriod;
config.bootstrapDiscountHalvingPeriod;
uint256 gamma = 1024 - (1024 >> halves);
return (feeBase * gamma) / 1024;
}
Expand Down
13 changes: 10 additions & 3 deletions packages/protocol/contracts/L2/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ contract TaikoL2 is AddressResolver, ReentrancyGuard, IHeaderSync {
* @param l1Hash The latest L1 block hash when this block was proposed.
*/
function anchor(uint256 l1Height, bytes32 l1Hash) external {
_checkPublicInputs();
TaikoData.Config memory config = getConfig();
if (config.enablePublicInputsCheck) {
_checkPublicInputs();
}

l1Hashes[l1Height] = l1Hash;
latestSyncedHeader = l1Hash;
Expand All @@ -102,15 +105,18 @@ contract TaikoL2 is AddressResolver, ReentrancyGuard, IHeaderSync {
);
require(tx.gasprice == 0, "L2:gasPrice");

TaikoData.Config memory config = getConfig();
LibInvalidTxList.Reason reason = LibInvalidTxList.isTxListInvalid({
config: getConfig(),
config: config,
encoded: txList,
hint: hint,
txIdx: txIdx
});
require(reason != LibInvalidTxList.Reason.OK, "L2:reason");

_checkPublicInputs();
if (config.enablePublicInputsCheck) {
_checkPublicInputs();
}

emit BlockInvalidated(txList.hashTxList());
}
Expand Down Expand Up @@ -159,6 +165,7 @@ contract TaikoL2 is AddressResolver, ReentrancyGuard, IHeaderSync {
uint256 number = block.number;
uint256 chainId = block.chainid;

// from 2 to 256, while nnumber is greater than that number
for (uint256 i = 2; i <= 256 && number >= i; ++i) {
ancestors[(number - i) % 255] = blockhash(number - i);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/bridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Let's go deeper into the steps that occur when bridging ETH from srcChain to des
User initiates a bridge transaction with `sendMessage` on the source chain which includes:

- `depositValue`, `callValue`, and `processingFee` -- these must sum to `msg.value`.
- The destination chain's ID (must be enabled via `Bridge.enableDestChain()`).
- The destination chain's ID (must be enabled via setting `addressResolver` for `${chainID}.bridge`).

Inside the `sendMessage` call, the `msg.value` amount of Ether is sent to the srcChain `EtherVault` contract. Next, a `signal` is created from the message, and a `key` is stored on the srcChain bridge contract address. The `key` is a hash of the `signal` and the srcChain bridge contract address. The `key` is stored on the `Bridge` contract with a value of `1`, and a `MessageSent` event is emitted for the relayer to pick up.

Expand Down
5 changes: 3 additions & 2 deletions packages/protocol/contracts/libs/LibSharedConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ library LibSharedConfig {
feeMaxPeriodPctg: 375, // 375%
blockTimeCap: 48 seconds,
proofTimeCap: 60 minutes,
boostrapDiscountHalvingPeriod: 180 days,
bootstrapDiscountHalvingPeriod: 180 days,
initialUncleDelay: 60 minutes,
enableTokenomics: false
enableTokenomics: false,
enablePublicInputsCheck: true
});
}
}
3 changes: 2 additions & 1 deletion packages/protocol/contracts/test/L1/TestTaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ contract TestTaikoL1 is TaikoL1, IProofVerifier {
config.feeMaxPeriodPctg = 375; // 375%
config.blockTimeCap = 48 seconds;
config.proofTimeCap = 60 minutes;
config.boostrapDiscountHalvingPeriod = 180 days;
config.bootstrapDiscountHalvingPeriod = 180 days;
config.initialUncleDelay = 1 minutes;
config.enableTokenomics = false;
config.enablePublicInputsCheck = true;
}

function verifyZKP(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: MIT
//
// ╭━━━━╮╱╱╭╮╱╱╱╱╱╭╮╱╱╱╱╱╭╮
// ┃╭╮╭╮┃╱╱┃┃╱╱╱╱╱┃┃╱╱╱╱╱┃┃
// ╰╯┃┃┣┻━┳┫┃╭┳━━╮┃┃╱╱╭━━┫╰━┳━━╮
// ╱╱┃┃┃╭╮┣┫╰╯┫╭╮┃┃┃╱╭┫╭╮┃╭╮┃━━┫
// ╱╱┃┃┃╭╮┃┃╭╮┫╰╯┃┃╰━╯┃╭╮┃╰╯┣━━┃
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯
pragma solidity ^0.8.9;

import {IProofVerifier} from "../../L1/ProofVerifier.sol";
import "../../L1/TaikoL1.sol";

contract TestTaikoL1EnableTokenomics is TaikoL1, IProofVerifier {
function getConfig()
public
pure
override
returns (TaikoData.Config memory config)
{
config.chainId = 167;
// up to 2048 pending blocks
config.maxNumBlocks = 2048;
config.blockHashHistory = 3;
// This number is calculated from maxNumBlocks to make
// the 'the maximum value of the multiplier' close to 20.0
config.zkProofsPerBlock = 1;
config.maxVerificationsPerTx = 2;
config.commitConfirmations = 1;
config.maxProofsPerForkChoice = 5;
config.blockMaxGasLimit = 30000000; // TODO
config.maxTransactionsPerBlock = 20; // TODO
config.maxBytesPerTxList = 10240; // TODO
config.minTxGasLimit = 21000; // TODO
config.anchorTxGasLimit = 250000;
config.feePremiumLamda = 590;
config.rewardBurnBips = 100; // 100 basis points or 1%
config.proposerDepositPctg = 25; // 25%

// Moving average factors
config.feeBaseMAF = 1024;
config.blockTimeMAF = 64;
config.proofTimeMAF = 64;

config.rewardMultiplierPctg = 400; // 400%
config.feeGracePeriodPctg = 125; // 125%
config.feeMaxPeriodPctg = 375; // 375%
config.blockTimeCap = 48 seconds;
config.proofTimeCap = 5 seconds;
config.bootstrapDiscountHalvingPeriod = 1 seconds;
config.initialUncleDelay = 1 seconds;
config.enableTokenomics = true;
config.enablePublicInputsCheck = false;
}

function verifyZKP(
bytes memory /*verificationKey*/,
bytes calldata /*zkproof*/,
bytes32 /*blockHash*/,
address /*prover*/,
bytes32 /*txListHash*/
) public pure override returns (bool) {
return true;
}

function verifyMKP(
bytes memory /*key*/,
bytes memory /*value*/,
bytes memory /*proof*/,
bytes32 /*root*/
) public pure override returns (bool) {
return true;
}
}
56 changes: 56 additions & 0 deletions packages/protocol/contracts/test/L1/TestTaikoL2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: MIT
//
// ╭━━━━╮╱╱╭╮╱╱╱╱╱╭╮╱╱╱╱╱╭╮
// ┃╭╮╭╮┃╱╱┃┃╱╱╱╱╱┃┃╱╱╱╱╱┃┃
// ╰╯┃┃┣┻━┳┫┃╭┳━━╮┃┃╱╱╭━━┫╰━┳━━╮
// ╱╱┃┃┃╭╮┣┫╰╯┫╭╮┃┃┃╱╭┫╭╮┃╭╮┃━━┫
// ╱╱┃┃┃╭╮┃┃╭╮┫╰╯┃┃╰━╯┃╭╮┃╰╯┣━━┃
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯
pragma solidity ^0.8.9;

import "../../L2/TaikoL2.sol";

contract TestTaikoL2 is TaikoL2 {
constructor(address _addressManager) TaikoL2(_addressManager) {}

function getConfig()
public
pure
override
returns (TaikoData.Config memory config)
{
config.chainId = 167;
// up to 2048 pending blocks
config.maxNumBlocks = 4;
config.blockHashHistory = 3;
// This number is calculated from maxNumBlocks to make
// the 'the maximum value of the multiplier' close to 20.0
config.zkProofsPerBlock = 1;
config.maxVerificationsPerTx = 2;
config.commitConfirmations = 1;
config.maxProofsPerForkChoice = 5;
config.blockMaxGasLimit = 30000000; // TODO
config.maxTransactionsPerBlock = 20; // TODO
config.maxBytesPerTxList = 10240; // TODO
config.minTxGasLimit = 21000; // TODO
config.anchorTxGasLimit = 250000;
config.feePremiumLamda = 590;
config.rewardBurnBips = 100; // 100 basis points or 1%
config.proposerDepositPctg = 25; // 25%

// Moving average factors
config.feeBaseMAF = 1024;
config.blockTimeMAF = 64;
config.proofTimeMAF = 64;

config.rewardMultiplierPctg = 400; // 400%
config.feeGracePeriodPctg = 125; // 125%
config.feeMaxPeriodPctg = 375; // 375%
config.blockTimeCap = 48 seconds;
config.proofTimeCap = 60 minutes;
config.bootstrapDiscountHalvingPeriod = 180 days;
config.initialUncleDelay = 1 minutes;
config.enableTokenomics = true;
config.enablePublicInputsCheck = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: MIT
//
// ╭━━━━╮╱╱╭╮╱╱╱╱╱╭╮╱╱╱╱╱╭╮
// ┃╭╮╭╮┃╱╱┃┃╱╱╱╱╱┃┃╱╱╱╱╱┃┃
// ╰╯┃┃┣┻━┳┫┃╭┳━━╮┃┃╱╱╭━━┫╰━┳━━╮
// ╱╱┃┃┃╭╮┣┫╰╯┫╭╮┃┃┃╱╭┫╭╮┃╭╮┃━━┫
// ╱╱┃┃┃╭╮┃┃╭╮┫╰╯┃┃╰━╯┃╭╮┃╰╯┣━━┃
// ╱╱╰╯╰╯╰┻┻╯╰┻━━╯╰━━━┻╯╰┻━━┻━━╯
pragma solidity ^0.8.9;

import "../../L2/TaikoL2.sol";

contract TestTaikoL2EnablePublicInputsCheck is TaikoL2 {
constructor(address _addressManager) TaikoL2(_addressManager) {}

function getConfig()
public
pure
override
returns (TaikoData.Config memory config)
{
config.chainId = 167;
// up to 2048 pending blocks
config.maxNumBlocks = 4;
config.blockHashHistory = 3;
// This number is calculated from maxNumBlocks to make
// the 'the maximum value of the multiplier' close to 20.0
config.zkProofsPerBlock = 1;
config.maxVerificationsPerTx = 2;
config.commitConfirmations = 1;
config.maxProofsPerForkChoice = 5;
config.blockMaxGasLimit = 30000000; // TODO
config.maxTransactionsPerBlock = 20; // TODO
config.maxBytesPerTxList = 10240; // TODO
config.minTxGasLimit = 21000; // TODO
config.anchorTxGasLimit = 250000;
config.feePremiumLamda = 590;
config.rewardBurnBips = 100; // 100 basis points or 1%
config.proposerDepositPctg = 25; // 25%

// Moving average factors
config.feeBaseMAF = 1024;
config.blockTimeMAF = 64;
config.proofTimeMAF = 64;

config.rewardMultiplierPctg = 400; // 400%
config.feeGracePeriodPctg = 125; // 125%
config.feeMaxPeriodPctg = 375; // 375%
config.blockTimeCap = 48 seconds;
config.proofTimeCap = 60 minutes;
config.bootstrapDiscountHalvingPeriod = 180 days;
config.initialUncleDelay = 1 minutes;
config.enableTokenomics = true;
config.enablePublicInputsCheck = true;
}
}
9 changes: 9 additions & 0 deletions packages/protocol/contracts/test/thirdparty/TestTKOToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "../../L1/TkoToken.sol";

contract TestTkoToken is TkoToken {
function mintAnyone(address account, uint256 amount) public {
_mint(account, amount);
}
}
3 changes: 2 additions & 1 deletion packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"test:coverage": "pnpm coverage",
"generate:genesis": "ts-node ./utils/generate_genesis/main.ts",
"test:genesis": "./test/genesis/generate_genesis.test.sh",
"test:integration": "./test/test_integration.sh",
"test:integration": "TEST_TYPE=integration ./test/test_integration.sh",
"test:tokenomics": "TEST_TYPE=tokenomics ./test/test_integration.sh",
"deploy:hardhat": "LOG_LEVEL=debug pnpm hardhat deploy_L1 --network hardhat --dao-vault 0xdf08f82de32b8d460adbe8d72043e3a7e25a3b39 --team-vault 0xdf08f82de32b8d460adbe8d72043e3a7e25a3b39 --l2-genesis-block-hash 0xee1950562d42f0da28bd4550d88886bc90894c77c9c9eaefef775d4c8223f259 --bridge-funder-private-key ddbf12f72c946bb1e6de5eaf580c51db51828ba198d9b0dba9c7d48ec748dc04 --bridge-fund 0xff --confirmations 1",
"lint-staged": "lint-staged --allow-empty"
},
Expand Down
Loading

0 comments on commit d63fae3

Please sign in to comment.