Skip to content

feat(protocol): optimize ProverMarket gas cost #19319

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

Merged
merged 4 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions packages/protocol/contracts/layer1/based/TaikoInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,23 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, IProposeBatch, I
uint256 proverFee;
(meta_.prover, proverFee) = proverMarket.getCurrentProver();
require(meta_.prover != address(0), NoProverAvailable());

if (info_.proposer == meta_.prover) {
// proposer is the same as the prover, no need to pay the prover fee.
_debitBond(meta_.prover, config.livenessBondBase);
} else {
// proposer pay the prover fee.
_debitBond(info_.proposer, proverFee);

if (proverFee < config.livenessBondBase) {
_debitBond(meta_.prover, config.livenessBondBase - proverFee);
} else {
_creditBond(meta_.prover, proverFee - config.livenessBondBase);
}
// if bondDelta is negative (proverFee < livenessBondBase), deduct the diff
// if not then add the diff to the bond balance
int256 bondDelta = int256(proverFee) - int256(uint256(config.livenessBondBase));
bondDelta < 0
? _debitBond(meta_.prover, uint256(-bondDelta))
: _creditBond(meta_.prover, uint256(bondDelta));

proverMarket.onProverAssigned(meta_.prover, proverFee, meta_.batchId);
}
} else {
// proposer is the same as the prover, no need to pay the prover fee.
_debitBond(meta_.prover, config.livenessBondBase);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,12 @@ contract ProverMarket is EssentialContract, IProverMarket {
{
emit ProverAssigned(msg.sender, _fee, _batchId);

if (assignmentCount > FEE_CHANGE_THRESHOLD) {
// No need to update assignmentCount nor avgFee
return;
}

if (++assignmentCount <= FEE_CHANGE_THRESHOLD) {
if (assignmentCount < FEE_CHANGE_THRESHOLD) {
uint64 _avgFeeInGwei = avgFeeInGwei;
uint64 _feeInGwei = uint64(_fee / GWEI);

unchecked {
assignmentCount++;
avgFeeInGwei = _avgFeeInGwei == 0
? _feeInGwei
: uint64(((FEE_CHANGE_FACTOR - 1) * _avgFeeInGwei + _feeInGwei) / FEE_CHANGE_FACTOR);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
See `test_inbox_with_provermarket_diff_prover_and_proposer_measure_gas_used` in InboxTest_ProposeAndProve.t.sol

Gas per proposing: 189605
Gas per proposing: 189306
Gas per proving + verification: 158541
Total: 348146
Total: 347847
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
See `test_inbox_with_provermarket_diff_prover_and_proposer_fee_above_liveness_measure_gas_used` in InboxTest_ProposeAndProve.t.sol

Gas per proposing: 189454
Gas per proposing: 189172
Gas per proving + verification: 158547
Total: 348001
Total: 347719
26 changes: 13 additions & 13 deletions packages/protocol/gas-reports/layer1-contracts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,26 @@ InboxTest_ProposeAndProve:test_inbox_reprove_by_transition_with_same_parent_hash
InboxTest_ProposeAndProve:test_inbox_reprove_by_transition_with_same_parent_hash_but_different_block_hash_will_pause_inbox() (gas: 7823621)
InboxTest_ProposeAndProve:test_inbox_reprove_the_same_batch_with_same_transition_will_do_nothing() (gas: 1223576)
InboxTest_ProposeAndProve:test_inbox_ring_buffer_will_be_reused() (gas: 15112348)
InboxTest_ProposeAndProve:test_inbox_with_provermarket_diff_prover_and_proposer_fee_above_liveness_measure_gas_used() (gas: 9458460)
InboxTest_ProposeAndProve:test_inbox_with_provermarket_diff_prover_and_proposer_measure_gas_used() (gas: 9458507)
InboxTest_ProposeAndProve:test_inbox_with_provermarket_same_prover_as_proposer_measure_gas_used() (gas: 9372313)
InboxTest_ProposeAndProve:test_inbox_with_provermarket_diff_prover_and_proposer_fee_above_liveness_measure_gas_used() (gas: 9458184)
InboxTest_ProposeAndProve:test_inbox_with_provermarket_diff_prover_and_proposer_measure_gas_used() (gas: 9458214)
InboxTest_ProposeAndProve:test_inbox_with_provermarket_same_prover_as_proposer_measure_gas_used() (gas: 9372319)
InboxTest_StopBatch:test_inbox_num_batches_verified() (gas: 8375381)
PreconfRouterTest:test_preconfRouter_proposeBatch() (gas: 375143)
PreconfRouterTest:test_preconfRouter_proposeBatch_notOperator() (gas: 325702)
PreconfRouterTest:test_preconfRouter_proposeBatch_proposerNotSender() (gas: 373818)
ProverMarketTest:test_FeeLargerThanAllowed_reverts() (gas: 116105)
ProverMarketTest:test_averageFeeCalculation() (gas: 155249)
ProverMarketTest:test_bid() (gas: 90169)
ProverMarketTest:test_FeeLargerThanAllowed_reverts() (gas: 116111)
ProverMarketTest:test_averageFeeCalculation() (gas: 152585)
ProverMarketTest:test_bid() (gas: 90175)
ProverMarketTest:test_bid_with_insufficientBondBalance() (gas: 40622)
ProverMarketTest:test_cannotFitToUint64_reverts() (gas: 37213)
ProverMarketTest:test_feeLargerThanMax_reverts() (gas: 179645)
ProverMarketTest:test_feeLargerThanMax_reverts() (gas: 176981)
ProverMarketTest:test_feeNotDivisibleByUnit_reverts() (gas: 37008)
ProverMarketTest:test_getMaxFee() (gas: 155506)
ProverMarketTest:test_invalidThresholds_reverts() (gas: 63631)
ProverMarketTest:test_outbidWithHigherBond() (gas: 150911)
ProverMarketTest:test_outbidWithLowerBond() (gas: 144589)
ProverMarketTest:test_outbidWithSameBond() (gas: 144610)
ProverMarketTest:test_requestExit() (gas: 95451)
ProverMarketTest:test_getMaxFee() (gas: 152842)
ProverMarketTest:test_invalidThresholds_reverts() (gas: 63613)
ProverMarketTest:test_outbidWithHigherBond() (gas: 150923)
ProverMarketTest:test_outbidWithLowerBond() (gas: 144601)
ProverMarketTest:test_outbidWithSameBond() (gas: 144622)
ProverMarketTest:test_requestExit() (gas: 95457)
SendMessageToDelegateOwner:testAddress1() (gas: 2391)
TestAutomataDcapV3Attestation:testAttestation() (gas: 4848498)
TestAutomataDcapV3Attestation:testParsedCustomQuoteBinAttestation() (gas: 4553350)
Expand Down