Skip to content

Commit

Permalink
feat(protocol): add more protocol/tokenomics tests (#12988)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Wang <[email protected]>
Co-authored-by: Roger <[email protected]>
Co-authored-by: David <[email protected]>
  • Loading branch information
4 people authored Feb 6, 2023
1 parent ed5a748 commit 3a7523f
Show file tree
Hide file tree
Showing 38 changed files with 1,620 additions and 627 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
working-directory: ./packages/protocol
run: pnpm test:integration

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

- name: protocol - Test Coverage
working-directory: ./packages/protocol
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ library TaikoData {
uint64 initialUncleDelay;
bool enableTokenomics;
bool enablePublicInputsCheck;
bool enableProofValidation;
bool enableOracleProver;
}

Expand Down
19 changes: 16 additions & 3 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {
return LibAnchorSignature.signTransaction(hash, k);
}

function getBlockProvers(
function getForkChoice(
uint256 id,
bytes32 parentHash
) public view returns (address[] memory) {
return state.forkChoices[id][parentHash].provers;
) public view returns (TaikoData.ForkChoice memory) {
return state.forkChoices[id][parentHash];
}

function getUncleProofDelay(uint256 blockId) public view returns (uint64) {
Expand All @@ -293,4 +293,17 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {
function getConfig() public pure virtual returns (TaikoData.Config memory) {
return LibSharedConfig.getConfig();
}

function isBlockVerifiable(
uint256 blockId,
bytes32 parentHash
) public view returns (bool) {
return
LibVerifying.isVerifiable({
state: state,
config: getConfig(),
fc: state.forkChoices[blockId][parentHash],
blockId: blockId
});
}
}
1 change: 1 addition & 0 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ library LibProposing {
meta.txListHash == txList.hashTxList(),
"L1:txList"
);

require(
state.nextBlockId <
state.latestVerifiedId + config.maxNumBlocks,
Expand Down
58 changes: 29 additions & 29 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ library LibProving {
"L1:circuits:size"
);

{
IProofVerifier proofVerifier = IProofVerifier(
resolver.resolve("proof_verifier", false)
);

if (config.enableProofValidation) {
// Check anchor tx is valid
LibTxDecoder.Tx memory _tx = LibTxDecoder.decodeTx(
config.chainId,
Expand Down Expand Up @@ -109,38 +113,34 @@ library LibProving {
),
"L1:anchor:calldata"
);
}

IProofVerifier proofVerifier = IProofVerifier(
resolver.resolve("proof_verifier", false)
);

// Check anchor tx is the 1st tx in the block
require(
proofVerifier.verifyMKP({
key: LibRLPWriter.writeUint(0),
value: anchorTx,
proof: evidence.proofs[zkProofsPerBlock],
root: evidence.header.transactionsRoot
}),
"L1:tx:proof"
);
// Check anchor tx is the 1st tx in the block
require(
proofVerifier.verifyMKP({
key: LibRLPWriter.writeUint(0),
value: anchorTx,
proof: evidence.proofs[zkProofsPerBlock],
root: evidence.header.transactionsRoot
}),
"L1:tx:proof"
);

// Check anchor tx does not throw
// Check anchor tx does not throw

LibReceiptDecoder.Receipt memory receipt = LibReceiptDecoder
.decodeReceipt(anchorReceipt);
LibReceiptDecoder.Receipt memory receipt = LibReceiptDecoder
.decodeReceipt(anchorReceipt);

require(receipt.status == 1, "L1:receipt:status");
require(
proofVerifier.verifyMKP({
key: LibRLPWriter.writeUint(0),
value: anchorReceipt,
proof: evidence.proofs[zkProofsPerBlock + 1],
root: evidence.header.receiptsRoot
}),
"L1:receipt:proof"
);
require(receipt.status == 1, "L1:receipt:status");
require(
proofVerifier.verifyMKP({
key: LibRLPWriter.writeUint(0),
value: anchorReceipt,
proof: evidence.proofs[zkProofsPerBlock + 1],
root: evidence.header.receiptsRoot
}),
"L1:receipt:proof"
);
}

// ZK-prove block and mark block proven to be valid.
_proveBlock({
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ library LibVerifying {

// Uncle proof can not take more than 2x time the first proof did.
if (
!_isVerifiable({
!isVerifiable({
state: state,
config: config,
fc: fc,
Expand Down Expand Up @@ -247,12 +247,12 @@ library LibVerifying {
delete fc.provers;
}

function _isVerifiable(
function isVerifiable(
TaikoData.State storage state,
TaikoData.Config memory config,
TaikoData.ForkChoice storage fc,
uint256 blockId
) private view returns (bool) {
) public view returns (bool) {
return
// TODO(daniel): remove the next line.
(!config.enableOracleProver || fc.provers.length > 1) &&
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/contracts/libs/LibSharedConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ library LibSharedConfig {
proofTimeCap: 60 minutes,
bootstrapDiscountHalvingPeriod: 180 days,
initialUncleDelay: 60 minutes,
enableTokenomics: true,
enableTokenomics: false,
enablePublicInputsCheck: true,
enableProofValidation: false,
enableOracleProver: true
});
}
Expand Down
8 changes: 4 additions & 4 deletions packages/protocol/contracts/test/L1/TestTaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract TestTaikoL1 is TaikoL1, IProofVerifier {
// 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.maxVerificationsPerTx = 0;
config.commitConfirmations = 1;
config.maxProofsPerForkChoice = 5;
config.blockMaxGasLimit = 30000000; // TODO
Expand All @@ -44,11 +44,11 @@ contract TestTaikoL1 is TaikoL1, IProofVerifier {
config.feeGracePeriodPctg = 125; // 125%
config.feeMaxPeriodPctg = 375; // 375%
config.blockTimeCap = 48 seconds;
config.proofTimeCap = 60 minutes;
config.proofTimeCap = 4 seconds;
config.bootstrapDiscountHalvingPeriod = 180 days;
config.initialUncleDelay = 1 minutes;
config.initialUncleDelay = 1 seconds;
config.enableTokenomics = false;
config.enablePublicInputsCheck = true;
config.enablePublicInputsCheck = false;
config.enableOracleProver = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ contract TestTaikoL1EnableTokenomics is TaikoL1, IProofVerifier {
{
config.chainId = 167;
// up to 2048 pending blocks
config.maxNumBlocks = 2048;
config.blockHashHistory = 3;
config.maxNumBlocks = 6;
config.blockHashHistory = 10;
// 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.maxVerificationsPerTx = 0; // dont verify blocks automatically
config.commitConfirmations = 1;
config.maxProofsPerForkChoice = 5;
config.blockMaxGasLimit = 30000000; // TODO
Expand All @@ -49,6 +49,7 @@ contract TestTaikoL1EnableTokenomics is TaikoL1, IProofVerifier {
config.initialUncleDelay = 1 seconds;
config.enableTokenomics = true;
config.enablePublicInputsCheck = false;
config.enableProofValidation = false;
config.enableOracleProver = false;
}

Expand Down
1 change: 1 addition & 0 deletions packages/protocol/contracts/test/L1/TestTaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ contract TestTaikoL2 is TaikoL2 {
config.initialUncleDelay = 1 minutes;
config.enableTokenomics = true;
config.enablePublicInputsCheck = false;
config.enableProofValidation = false;
config.enableOracleProver = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ contract TestTaikoL2EnablePublicInputsCheck is TaikoL2 {
config.initialUncleDelay = 1 minutes;
config.enableTokenomics = true;
config.enablePublicInputsCheck = true;
config.enableProofValidation = true;
config.enableOracleProver = false;
}
}
Loading

0 comments on commit 3a7523f

Please sign in to comment.