Skip to content

Commit bf5d93a

Browse files
authored
chore: packed EpochRewards (#15268)
Fixes #14939.
1 parent 3aaa83a commit bf5d93a

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

l1-contracts/gas_benchmark.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ setupEpoch | Median | 39702 (3.45) | 39702 (3.45)
1212
setupEpoch | Max | 106360 (9.23) | 599988 (52.08) | 493628 (42.85) | 464.11%
1313
setupEpoch | # Calls | 100 | 100 | 0 | 0.00%
1414
-------------------------+---------+------------------------+-------------------------+------------------------+-----------------
15-
submitEpochRootProof | Min | 591086 (51.31) | 591086 (51.31) | 0 (0.00) | 0.00%
16-
submitEpochRootProof | Avg | 611355 (53.07) | 611355 (53.07) | 0 (0.00) | 0.00%
17-
submitEpochRootProof | Median | 591182 (51.32) | 591182 (51.32) | 0 (0.00) | 0.00%
18-
submitEpochRootProof | Max | 651799 (56.58) | 651799 (56.58) | 0 (0.00) | 0.00%
15+
submitEpochRootProof | Min | 581497 (50.48) | 581497 (50.48) | 0 (0.00) | 0.00%
16+
submitEpochRootProof | Avg | 601645 (52.23) | 601645 (52.23) | 0 (0.00) | 0.00%
17+
submitEpochRootProof | Median | 581593 (50.49) | 581593 (50.49) | 0 (0.00) | 0.00%
18+
submitEpochRootProof | Max | 641845 (55.72) | 641845 (55.72) | 0 (0.00) | 0.00%
1919
submitEpochRootProof | # Calls | 3 | 3 | 0 | 0.00%
2020
-------------------------+---------+------------------------+-------------------------+------------------------+-----------------
2121
aggregate3 | Min | 0 (0.00) | 501159 (1392.11) | 501159 (1392.11) | 0.00%

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {IRewardDistributor} from "@aztec/governance/interfaces/IRewardDistributo
1717
import {IERC20} from "@oz/token/ERC20/IERC20.sol";
1818
import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol";
1919
import {Math} from "@oz/utils/math/Math.sol";
20+
import {SafeCast} from "@oz/utils/math/SafeCast.sol";
2021
import {BitMaps} from "@oz/utils/structs/BitMaps.sol";
2122

2223
type Bps is uint32;
@@ -33,8 +34,8 @@ struct SubEpochRewards {
3334
}
3435

3536
struct EpochRewards {
36-
uint256 longestProvenLength;
37-
uint256 rewards;
37+
uint128 longestProvenLength;
38+
uint128 rewards;
3839
mapping(uint256 length => SubEpochRewards) subEpoch;
3940
}
4041

@@ -71,6 +72,7 @@ library RewardLib {
7172
using TimeLib for Timestamp;
7273
using TimeLib for Epoch;
7374
using FeeHeaderLib for CompressedFeeHeader;
75+
using SafeCast for uint256;
7476

7577
bytes32 private constant REWARD_STORAGE_POSITION = keccak256("aztec.reward.storage");
7678

@@ -166,7 +168,7 @@ library RewardLib {
166168
BpsLib.mul(blockRewardsAvailable, rewardStorage.config.sequencerBps);
167169
v.sequencerBlockReward = sequencerShare / added;
168170

169-
$er.rewards += (blockRewardsAvailable - sequencerShare);
171+
$er.rewards += (blockRewardsAvailable - sequencerShare).toUint128();
170172
}
171173

172174
FeeStore storage feeStore = FeeLib.getStorage();
@@ -184,7 +186,7 @@ library RewardLib {
184186

185187
// Compute the proving fee in the fee asset
186188
v.proverFee = Math.min(v.manaUsed * feeHeader.getProverCost(), fee - burn);
187-
$er.rewards += v.proverFee;
189+
$er.rewards += v.proverFee.toUint128();
188190

189191
v.sequencerFee = fee - burn - v.proverFee;
190192

@@ -194,7 +196,7 @@ library RewardLib {
194196
}
195197
}
196198

197-
$er.longestProvenLength = length;
199+
$er.longestProvenLength = length.toUint128();
198200

199201
if (t.feesToClaim > 0) {
200202
rollupStore.config.feeAssetPortal.distributeFees(address(this), t.feesToClaim);

0 commit comments

Comments
 (0)