Skip to content

Commit e76c5b7

Browse files
authored
chore: update proving cost changes (#13833)
Fixes #13600. Accompanying update tohe engineering design in AztecProtocol/engineering-designs#59 The diff looks very large, but is mostly because we generated a new fixture structure.
1 parent d0753cb commit e76c5b7

File tree

12 files changed

+12300
-13597
lines changed

12 files changed

+12300
-13597
lines changed

l1-contracts/src/core/libraries/rollup/EpochProofLib.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ library EpochProofLib {
296296
t.totalBurn += burn;
297297

298298
// Compute the proving fee in the fee asset
299-
v.proverFee = Math.min(v.manaUsed * feeHeader.getProvingCost(), fee - burn);
299+
v.proverFee = Math.min(v.manaUsed * feeHeader.getProverCost(), fee - burn);
300300
$er.rewards += v.proverFee;
301301

302302
v.sequencerFee = fee - burn - v.proverFee;

l1-contracts/src/core/libraries/rollup/FeeLib.sol

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,16 @@ struct OracleInput {
3838
struct ManaBaseFeeComponents {
3939
uint256 congestionCost;
4040
uint256 congestionMultiplier;
41-
uint256 dataCost;
42-
uint256 gasCost;
43-
uint256 provingCost;
41+
uint256 sequencerCost;
42+
uint256 proverCost;
4443
}
4544

4645
struct FeeHeader {
4746
uint256 excessMana;
4847
uint256 manaUsed;
4948
uint256 feeAssetPriceNumerator;
5049
uint256 congestionCost;
51-
uint256 provingCost;
50+
uint256 proverCost;
5251
}
5352

5453
struct L1FeeData {
@@ -113,7 +112,7 @@ library PriceLib {
113112

114113
struct CompressedFeeHeader {
115114
uint64 congestionCost;
116-
uint64 provingCost;
115+
uint64 proverCost;
117116
uint48 feeAssetPriceNumerator;
118117
uint48 excessMana;
119118
uint32 manaUsed;
@@ -138,12 +137,12 @@ library FeeHeaderLib {
138137
return _compressedFeeHeader.congestionCost;
139138
}
140139

141-
function getProvingCost(CompressedFeeHeader storage _compressedFeeHeader)
140+
function getProverCost(CompressedFeeHeader storage _compressedFeeHeader)
142141
internal
143142
view
144143
returns (uint256)
145144
{
146-
return _compressedFeeHeader.provingCost;
145+
return _compressedFeeHeader.proverCost;
147146
}
148147

149148
function compress(FeeHeader memory _feeHeader) internal pure returns (CompressedFeeHeader memory) {
@@ -152,7 +151,7 @@ library FeeHeaderLib {
152151
manaUsed: _feeHeader.manaUsed.toUint32(),
153152
feeAssetPriceNumerator: _feeHeader.feeAssetPriceNumerator.toUint48(),
154153
congestionCost: _feeHeader.congestionCost.toUint64(),
155-
provingCost: _feeHeader.provingCost.toUint64()
154+
proverCost: _feeHeader.proverCost.toUint64()
156155
});
157156
}
158157

@@ -166,7 +165,7 @@ library FeeHeaderLib {
166165
manaUsed: _compressedFeeHeader.manaUsed,
167166
feeAssetPriceNumerator: _compressedFeeHeader.feeAssetPriceNumerator,
168167
congestionCost: _compressedFeeHeader.congestionCost,
169-
provingCost: _compressedFeeHeader.provingCost
168+
proverCost: _compressedFeeHeader.proverCost
170169
});
171170
}
172171
}
@@ -209,7 +208,7 @@ library FeeLib {
209208
feeAssetPriceNumerator: 0,
210209
manaUsed: 0,
211210
congestionCost: 0,
212-
provingCost: 0
211+
proverCost: 0
213212
}).compress();
214213

215214
feeStore.l1GasOracleValues = L1GasOracleValues({
@@ -231,7 +230,7 @@ library FeeLib {
231230
int256 _feeAssetPriceModifier,
232231
uint256 _manaUsed,
233232
uint256 _congestionCost,
234-
uint256 _provingCost
233+
uint256 _proverCost
235234
) internal {
236235
require(
237236
SignedMath.abs(_feeAssetPriceModifier) <= MAX_FEE_ASSET_PRICE_MODIFIER,
@@ -246,7 +245,7 @@ library FeeLib {
246245
),
247246
manaUsed: _manaUsed,
248247
congestionCost: _congestionCost,
249-
provingCost: _provingCost
248+
proverCost: _proverCost
250249
}).compress();
251250
}
252251

@@ -285,30 +284,49 @@ library FeeLib {
285284

286285
if (manaTarget == 0) {
287286
return ManaBaseFeeComponents({
288-
dataCost: 0,
289-
gasCost: 0,
290-
provingCost: 0,
287+
sequencerCost: 0,
288+
proverCost: 0,
291289
congestionCost: 0,
292290
congestionMultiplier: 0
293291
});
294292
}
295293

296-
EthValue gasCostPerMana;
297-
EthValue dataCostPerMana;
294+
EthValue sequencerCostPerMana;
295+
EthValue proverCostPerMana;
298296
EthValue total;
299-
{
300-
uint256 gasUsed = L1_GAS_PER_BLOCK_PROPOSED + BLOBS_PER_BLOCK * GAS_PER_BLOB_POINT_EVALUATION
301-
+ L1_GAS_PER_EPOCH_VERIFIED / TimeLib.getStorage().epochDuration;
302297

298+
{
303299
L1FeeData memory fees = FeeLib.getL1FeesAt(_timestamp);
304-
gasCostPerMana =
305-
EthValue.wrap(Math.mulDiv(gasUsed, fees.baseFee, manaTarget, Math.Rounding.Ceil));
306-
dataCostPerMana = EthValue.wrap(
307-
Math.mulDiv(
308-
BLOBS_PER_BLOCK * BLOB_GAS_PER_BLOB, fees.blobFee, manaTarget, Math.Rounding.Ceil
309-
)
310-
);
311-
total = dataCostPerMana + gasCostPerMana + feeStore.provingCostPerMana;
300+
301+
// Sequencer cost per mana
302+
{
303+
uint256 gasUsed =
304+
L1_GAS_PER_BLOCK_PROPOSED + BLOBS_PER_BLOCK * GAS_PER_BLOB_POINT_EVALUATION;
305+
uint256 ethUsed = gasUsed * fees.baseFee;
306+
ethUsed += (BLOBS_PER_BLOCK * BLOB_GAS_PER_BLOB * fees.blobFee);
307+
308+
sequencerCostPerMana =
309+
EthValue.wrap(Math.mulDiv(ethUsed, 1, manaTarget, Math.Rounding.Ceil));
310+
}
311+
312+
// Prover cost per mana
313+
{
314+
proverCostPerMana = EthValue.wrap(
315+
Math.mulDiv(
316+
Math.mulDiv(
317+
L1_GAS_PER_EPOCH_VERIFIED,
318+
fees.baseFee,
319+
TimeLib.getStorage().epochDuration,
320+
Math.Rounding.Ceil
321+
),
322+
1,
323+
manaTarget,
324+
Math.Rounding.Ceil
325+
)
326+
) + feeStore.provingCostPerMana;
327+
}
328+
329+
total = sequencerCostPerMana + proverCostPerMana;
312330
}
313331

314332
CompressedFeeHeader storage parentFeeHeader = feeStore.feeHeaders[_blockOfInterest];
@@ -329,9 +347,8 @@ library FeeLib {
329347
_inFeeAsset ? FeeLib.getFeeAssetPerEthAtBlock(_blockOfInterest) : FeeAssetPerEthE9.wrap(1e9);
330348

331349
return ManaBaseFeeComponents({
332-
dataCost: FeeAssetValue.unwrap(dataCostPerMana.toFeeAsset(feeAssetPrice)),
333-
gasCost: FeeAssetValue.unwrap(gasCostPerMana.toFeeAsset(feeAssetPrice)),
334-
provingCost: FeeAssetValue.unwrap(feeStore.provingCostPerMana.toFeeAsset(feeAssetPrice)),
350+
sequencerCost: FeeAssetValue.unwrap(sequencerCostPerMana.toFeeAsset(feeAssetPrice)),
351+
proverCost: FeeAssetValue.unwrap(proverCostPerMana.toFeeAsset(feeAssetPrice)),
335352
congestionCost: FeeAssetValue.unwrap(congestionCost.toFeeAsset(feeAssetPrice)),
336353
congestionMultiplier: congestionMultiplier_
337354
});
@@ -369,8 +386,7 @@ library FeeLib {
369386
}
370387

371388
function summedBaseFee(ManaBaseFeeComponents memory _components) internal pure returns (uint256) {
372-
return _components.dataCost + _components.gasCost + _components.provingCost
373-
+ _components.congestionCost;
389+
return _components.sequencerCost + _components.proverCost + _components.congestionCost;
374390
}
375391

376392
function getStorage() internal pure returns (FeeStore storage storageStruct) {

l1-contracts/src/core/libraries/rollup/ProposeLib.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ library ProposeLib {
138138
_args.oracleInput.feeAssetPriceModifier,
139139
header.totalManaUsed,
140140
components.congestionCost,
141-
components.provingCost
141+
components.proverCost
142142
);
143143

144144
rollupStore.blobPublicInputsHashes[blockNumber] = v.blobPublicInputsHash;

l1-contracts/test/Rollup.t.sol

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {IERC20} from "@oz/token/ERC20/IERC20.sol";
3838
import {
3939
Timestamp, Slot, Epoch, SlotLib, EpochLib, TimeLib
4040
} from "@aztec/core/libraries/TimeLib.sol";
41+
import {FeeLib, L1_GAS_PER_EPOCH_VERIFIED} from "@aztec/core/libraries/rollup/FeeLib.sol";
4142

4243
import {RollupBase, IInstance} from "./base/RollupBase.sol";
4344
import {stdStorage, StdStorage} from "forge-std/StdStorage.sol";
@@ -357,8 +358,38 @@ contract RollupTest is RollupBase {
357358
_proveBlocks("mixed_block_", 1, 2, address(this));
358359

359360
// 1e6 mana at 1000 and 2000 cost per manage multiplied by 10 for the price conversion to fee asset.
360-
uint256 provingFees = 1e6 * (1000 + 2000) * 10;
361-
uint256 expectedProverRewards = rewardDistributor.BLOCK_REWARD() / 2 * 2 + provingFees;
361+
uint256 proverFees = 1e6 * (1000 + 2000);
362+
// Then we also need the component that is for covering the gas
363+
proverFees += (
364+
Math.mulDiv(
365+
Math.mulDiv(
366+
L1_GAS_PER_EPOCH_VERIFIED,
367+
rollup.getL1FeesAt(rollup.getTimestampForSlot(Slot.wrap(1))).baseFee,
368+
rollup.getEpochDuration(),
369+
Math.Rounding.Ceil
370+
),
371+
1,
372+
rollup.getManaTarget(),
373+
Math.Rounding.Ceil
374+
) * 1e6
375+
);
376+
377+
proverFees += (
378+
Math.mulDiv(
379+
Math.mulDiv(
380+
L1_GAS_PER_EPOCH_VERIFIED,
381+
rollup.getL1FeesAt(rollup.getTimestampForSlot(Slot.wrap(2))).baseFee,
382+
rollup.getEpochDuration(),
383+
Math.Rounding.Ceil
384+
),
385+
1,
386+
rollup.getManaTarget(),
387+
Math.Rounding.Ceil
388+
) * 1e6
389+
);
390+
proverFees *= 10; // the price conversion
391+
392+
uint256 expectedProverRewards = rewardDistributor.BLOCK_REWARD() / 2 * 2 + proverFees;
362393

363394
assertEq(
364395
rollup.getCollectiveProverRewardsForEpoch(Epoch.wrap(0)),

l1-contracts/test/benchmark/happy.t.sol

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ contract BenchmarkRollupTest is FeeModelTestPoints, DecoderBase {
155155
slashingQuorum: TestConstants.AZTEC_SLASHING_QUORUM,
156156
slashingRoundSize: TestConstants.AZTEC_SLASHING_ROUND_SIZE,
157157
manaTarget: MANA_TARGET,
158-
provingCostPerMana: TestConstants.AZTEC_PROVING_COST_PER_MANA
158+
provingCostPerMana: provingCost
159159
})
160160
);
161161
fakeCanonical.setCanonicalRollup(address(rollup));
@@ -306,10 +306,6 @@ contract BenchmarkRollupTest is FeeModelTestPoints, DecoderBase {
306306
Slot nextSlot = Slot.wrap(EPOCH_DURATION + 1);
307307
Epoch nextEpoch = Epoch.wrap(2);
308308

309-
rollup.setProvingCostPerMana(
310-
EthValue.wrap(points[0].outputs.mana_base_fee_components_in_wei.proving_cost)
311-
);
312-
313309
// Loop through all of the L1 metadata
314310
for (uint256 i = 0; i < l1Metadata.length; i++) {
315311
if (rollup.getPendingBlockNumber() >= 100) {
@@ -323,9 +319,6 @@ contract BenchmarkRollupTest is FeeModelTestPoints, DecoderBase {
323319
// will be accepted as a proposal so very useful for testing a long range of blocks.
324320
if (rollup.getCurrentSlot() == nextSlot) {
325321
TestPoint memory point = points[nextSlot.unwrap() - 1];
326-
rollup.setProvingCostPerMana(
327-
EthValue.wrap(point.outputs.mana_base_fee_components_in_wei.proving_cost)
328-
);
329322

330323
Block memory b = getBlock();
331324
address proposer = rollup.getCurrentProposer();

l1-contracts/test/fees/FeeModelTestPoints.t.sol

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {TestBase} from "../base/Base.sol";
77
import {OracleInput} from "@aztec/core/libraries/rollup/FeeLib.sol";
88
import {
99
MAX_FEE_ASSET_PRICE_MODIFIER,
10-
MINIMUM_CONGESTION_MULTIPLIER
10+
MINIMUM_CONGESTION_MULTIPLIER,
11+
EthValue
1112
} from "@aztec/core/libraries/rollup/FeeLib.sol";
1213
import {Math} from "@oz/utils/math/Math.sol";
1314

@@ -47,9 +48,8 @@ struct L1GasOracleValuesModel {
4748
struct ManaBaseFeeComponentsModel {
4849
uint256 congestion_cost;
4950
uint256 congestion_multiplier;
50-
uint256 data_cost;
51-
uint256 gas_cost;
52-
uint256 proving_cost;
51+
uint256 prover_cost;
52+
uint256 sequencer_cost;
5353
}
5454

5555
struct BlockHeaderModel {
@@ -81,11 +81,13 @@ struct TestPoint {
8181
struct FullFeeData {
8282
L1Metadata[] l1_metadata;
8383
TestPoint[] points;
84+
uint256 proving_cost;
8485
}
8586

8687
contract FeeModelTestPoints is TestBase {
8788
L1Metadata[] public l1Metadata;
8889
TestPoint[] public points;
90+
EthValue public provingCost;
8991

9092
constructor() {
9193
string memory root = vm.projectRoot();
@@ -101,6 +103,8 @@ contract FeeModelTestPoints is TestBase {
101103
for (uint256 i = 0; i < data.points.length; i++) {
102104
points.push(data.points[i]);
103105
}
106+
107+
provingCost = EthValue.wrap(data.proving_cost);
104108
}
105109

106110
function assertEq(L1FeesModel memory a, L1FeesModel memory b) internal pure {
@@ -149,8 +153,9 @@ contract FeeModelTestPoints is TestBase {
149153
b.congestion_multiplier,
150154
string.concat(_message, " congestion_multiplier mismatch")
151155
);
152-
assertEq(a.data_cost, b.data_cost, string.concat(_message, " data_cost mismatch"));
153-
assertEq(a.gas_cost, b.gas_cost, string.concat(_message, " gas_cost mismatch"));
154-
assertEq(a.proving_cost, b.proving_cost, string.concat(_message, " proving_cost mismatch"));
156+
assertEq(a.prover_cost, b.prover_cost, string.concat(_message, " prover_cost mismatch"));
157+
assertEq(
158+
a.sequencer_cost, b.sequencer_cost, string.concat(_message, " sequencer_cost mismatch")
159+
);
155160
}
156161
}

0 commit comments

Comments
 (0)