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): add more protocol/tokenomics tests #12988

Merged
merged 66 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
bd967bf
wip
cyberhorsey Jan 19, 2023
fcf37e7
merge main
cyberhorsey Jan 19, 2023
fcca784
Merge branch 'main' into prover_tests
cyberhorsey Jan 20, 2023
9dba09f
wip
cyberhorsey Jan 20, 2023
f5c9a96
wip: verification largely working
cyberhorsey Jan 21, 2023
44d5371
Merge branch 'main' into prover_tests
cyberhorsey Jan 21, 2023
197ac8e
test to make sure _rewardProvers issues 1 wei when owner has no tko b…
cyberhorsey Jan 21, 2023
f64d08f
send TKO to the prover for tests
cyberhorsey Jan 21, 2023
6873409
Merge branch 'prover_tests' of github.com:taikochain/taiko-mono into …
cyberhorsey Jan 21, 2023
c763aed
Merge branch 'main' into prover_tests
dantaik Jan 24, 2023
b9e9176
wip
cyberhorsey Jan 24, 2023
f6b0a2d
Merge branch 'prover_tests' of github.com:taikochain/taiko-mono into …
cyberhorsey Jan 24, 2023
098df43
tests pass. need refactor + addtl coverage but commit, propose, prove…
cyberhorsey Jan 24, 2023
61f5efb
rm getblockprovers
cyberhorsey Jan 24, 2023
e929e80
add sleep delay utils method, rename some variables
cyberhorsey Jan 24, 2023
1b6383c
helpers
cyberhorsey Jan 24, 2023
def8ae0
clean up tests
cyberhorsey Jan 24, 2023
3f17e2e
rm +1
cyberhorsey Jan 24, 2023
38e9a77
wip
cyberhorsey Jan 24, 2023
365288b
lower blocks so test runs faster, disable auto verification, comment …
cyberhorsey Jan 25, 2023
04792f1
remove async event nature of tests
cyberhorsey Jan 25, 2023
5942f88
Merge branch 'main' into prover_tests
cyberhorsey Jan 25, 2023
cf12914
add multiple proposer/prover test, addtl utils methods
cyberhorsey Jan 26, 2023
4422317
Merge branch 'prover_tests' of github.com:taikochain/taiko-mono into …
cyberhorsey Jan 26, 2023
2036417
merge main
cyberhorsey Jan 26, 2023
59072c0
Update protocol.yml
RogerLamTd Jan 26, 2023
fed052f
Update packages/protocol/test/tokenomics/proofReward.test.ts
cyberhorsey Jan 26, 2023
1730126
test names
cyberhorsey Jan 26, 2023
55787ce
Merge branch 'prover_tests' of github.com:taikochain/taiko-mono into …
cyberhorsey Jan 26, 2023
29bb42c
switch to event emitters
cyberhorsey Jan 26, 2023
ee8cf23
refactor listeners to utils methods
cyberhorsey Jan 26, 2023
6fa8eae
bubble up errors from eventhandlers to main thread
cyberhorsey Jan 26, 2023
07173db
refactor tests to root utils folder so we can reuse this code for Tai…
cyberhorsey Jan 27, 2023
a5dcb69
add taikol1 integration tests and begin refactorign them for more reu…
cyberhorsey Jan 27, 2023
33c8c28
Update packages/protocol/test/tokenomics/proofReward.test.ts
dantaik Jan 30, 2023
0e7ad12
Update packages/protocol/test/tokenomics/blockFee.test.ts
dantaik Jan 30, 2023
01e92d3
Merge branch 'main' into prover_tests
cyberhorsey Jan 30, 2023
1e54971
Merge branch 'main' into prover_tests
cyberhorsey Jan 30, 2023
829ffb9
Merge branch 'prover_tests' of github.com:taikochain/taiko-mono into …
cyberhorsey Jan 30, 2023
b849452
add circuits in to evidence
cyberhorsey Jan 30, 2023
3553849
.
cyberhorsey Jan 30, 2023
9f90310
change logging
cyberhorsey Jan 31, 2023
8fd36e5
forkchoice tests
cyberhorsey Jan 31, 2023
b3f6e51
small change
cyberhorsey Jan 31, 2023
bf3d85f
add channels, much cleaner than events i think?
cyberhorsey Jan 31, 2023
f301a44
simplify tests and refactor to use channels
cyberhorsey Jan 31, 2023
925a1de
Merge branch 'main' into prover_tests
cyberhorsey Jan 31, 2023
5c90d63
fix taikoL1 test for uncle delay
cyberhorsey Jan 31, 2023
fbd23fa
Merge branch 'prover_tests' of github.com:taikochain/taiko-mono into …
cyberhorsey Jan 31, 2023
729d21b
resolve merge conflicts
cyberhorsey Jan 31, 2023
69fc388
Merge branch 'main' into prover_tests
cyberhorsey Feb 1, 2023
0c85966
blockfee uses channel too
cyberhorsey Feb 1, 2023
bc2ff33
libproving + blockfee
cyberhorsey Feb 1, 2023
c4dafbc
Merge branch 'prover_tests' of github.com:taikochain/taiko-mono into …
cyberhorsey Feb 1, 2023
e607137
Merge branch 'main' into prover_tests
cyberhorsey Feb 2, 2023
ab92e88
Merge branch 'main' into prover_tests
dantaik Feb 2, 2023
c3a56e6
comments
cyberhorsey Feb 2, 2023
88aa015
try finally in proposer
cyberhorsey Feb 2, 2023
005d5f5
Merge branch 'prover_tests' of github.com:taikochain/taiko-mono into …
cyberhorsey Feb 2, 2023
08ef465
reusable integration fixture, test for latestSyncedHeader bug regress…
cyberhorsey Feb 2, 2023
de2b215
add test:all script so all tests can be run before pushing to verify …
cyberhorsey Feb 2, 2023
ba94085
propose/verify halt tests, refactor, halt utils method
cyberhorsey Feb 2, 2023
cdc70d8
chan/config to integrations fixture
cyberhorsey Feb 2, 2023
6de3a2c
add proposer/prover to fixture for re-use
cyberhorsey Feb 2, 2023
a064c56
test fix
cyberhorsey Feb 3, 2023
b965a57
test check maxnum
cyberhorsey Feb 3, 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
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;
dantaik marked this conversation as resolved.
Show resolved Hide resolved
}

struct BlockMetadata {
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) {
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
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) {
dantaik marked this conversation as resolved.
Show resolved Hide resolved
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
72 changes: 37 additions & 35 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ library LibProving {
"L1:proof:size"
);

{
IProofVerifier proofVerifier = IProofVerifier(
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -102,38 +106,34 @@ library LibProving {
),
"L1:anchor:calldata"
);
}

IProofVerifier proofVerifier = IProofVerifier(
dantaik marked this conversation as resolved.
Show resolved Hide resolved
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 Expand Up @@ -234,12 +234,14 @@ library LibProving {
require(evidence.meta.id == target.id, "L1:height");
require(evidence.prover != address(0), "L1:prover");

_checkMetadata({state: state, config: config, meta: target});
_validateHeaderForMetadata({
config: config,
header: evidence.header,
meta: evidence.meta
});
if (config.enableProofValidation) {
dantaik marked this conversation as resolved.
Show resolved Hide resolved
_checkMetadata({state: state, config: config, meta: target});
_validateHeaderForMetadata({
config: config,
header: evidence.header,
meta: evidence.meta
});
}

bytes32 blockHash = evidence.header.hashBlockHeader();

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 @@ -234,12 +234,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
fc.blockHash != 0 &&
block.timestamp >
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 @@ -42,7 +42,8 @@ library LibSharedConfig {
bootstrapDiscountHalvingPeriod: 180 days,
initialUncleDelay: 60 minutes,
enableTokenomics: false,
enablePublicInputsCheck: true
enablePublicInputsCheck: true,
enableProofValidation: true
});
}
}
1 change: 1 addition & 0 deletions packages/protocol/contracts/test/L1/TestTaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ contract TestTaikoL1 is TaikoL1, IProofVerifier {
config.initialUncleDelay = 1 minutes;
config.enableTokenomics = false;
config.enablePublicInputsCheck = true;
config.enableProofValidation = true;
}

function verifyZKP(
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;
}

function verifyZKP(
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,5 +50,6 @@ contract TestTaikoL2 is TaikoL2 {
config.initialUncleDelay = 1 minutes;
config.enableTokenomics = true;
config.enablePublicInputsCheck = false;
config.enableProofValidation = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ contract TestTaikoL2EnablePublicInputsCheck is TaikoL2 {
config.initialUncleDelay = 1 minutes;
config.enableTokenomics = true;
config.enablePublicInputsCheck = true;
config.enableProofValidation = true;
}
}
11 changes: 0 additions & 11 deletions packages/protocol/test/L1/TaikoL1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ describe("TaikoL1", function () {
});
});

describe("getBlockProvers()", async function () {
it("should return empty list when there is no proof for that block", async function () {
const provers = await taikoL1.getBlockProvers(
Math.ceil(Math.random() * 1024),
randomBytes32()
);

expect(provers).to.be.empty;
});
});

describe("halt()", async function () {
it("should revert called by nonOwner", async function () {
const initiallyHalted = await taikoL1.isHalted();
Expand Down
Loading