Skip to content

Commit 6a7bf31

Browse files
committed
fix
1 parent 0cccc1a commit 6a7bf31

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

l1-contracts/gas_benchmark.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
| src/core/Rollup.sol:Rollup contract | | | | | |
22
|-------------------------------------|-----------------|----------|----------|----------|---------|
33
| Deployment Cost | Deployment Size | | | | |
4-
| 8134336 | 39726 | | | | |
4+
| 8154934 | 39929 | | | | |
55
| Function Name | min | avg | median | max | # calls |
6-
| cheat__InitialiseValidatorSet | 15870313 | 15870313 | 15870313 | 15870313 | 1 |
6+
| cheat__InitialiseValidatorSet | 15884661 | 15884661 | 15884661 | 15884661 | 1 |
77
| getBlock | 1230 | 1230 | 1230 | 1230 | 12 |
88
| getBurnAddress | 369 | 369 | 369 | 369 | 1 |
99
| getCurrentEpoch | 979 | 979 | 979 | 979 | 397 |
10-
| getCurrentProposer | 135981 | 143439 | 136210 | 379571 | 200 |
10+
| getCurrentProposer | 135981 | 143548 | 136210 | 383219 | 200 |
1111
| getCurrentSlot | 735 | 740 | 735 | 2735 | 397 |
12-
| getEpochCommittee | 135880 | 143181 | 135892 | 379027 | 100 |
12+
| getEpochCommittee | 135880 | 143291 | 135892 | 382675 | 100 |
1313
| getEpochForBlock | 1065 | 1065 | 1065 | 1065 | 196 |
1414
| getFeeHeader | 1457 | 1457 | 1457 | 1457 | 95 |
1515
| getManaBaseFeeAt | 20381 | 26792 | 27121 | 32242 | 195 |
@@ -23,4 +23,4 @@
2323
| Deployment Cost | Deployment Size | | | | |
2424
| 358690 | 1553 | | | | |
2525
| Function Name | min | avg | median | max | # calls |
26-
| forward | 630841 | 685327 | 641834 | 2054339 | 100 |
26+
| forward | 630841 | 685437 | 641834 | 2057987 | 100 |

l1-contracts/src/core/libraries/TimeLib.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@ pragma solidity >=0.8.27;
55
// solhint-disable-next-line no-unused-import
66
import {Timestamp, Slot, Epoch, SlotLib, EpochLib} from "@aztec/core/libraries/TimeMath.sol";
77

8+
import {SafeCast} from "@oz/utils/math/SafeCast.sol";
9+
810
struct TimeStorage {
911
uint128 genesisTime;
1012
uint32 slotDuration; // Number of seconds in a slot
1113
uint32 epochDuration; // Number of slots in an epoch
1214
}
1315

1416
library TimeLib {
17+
using SafeCast for uint256;
18+
1519
bytes32 private constant TIME_STORAGE_POSITION = keccak256("aztec.time.storage");
1620

1721
function initialize(uint256 _genesisTime, uint256 _slotDuration, uint256 _epochDuration) internal {
1822
TimeStorage storage store = getStorage();
19-
store.genesisTime = uint128(_genesisTime);
20-
store.slotDuration = uint32(_slotDuration);
21-
store.epochDuration = uint32(_epochDuration);
23+
store.genesisTime = _genesisTime.toUint128();
24+
store.slotDuration = _slotDuration.toUint32();
25+
store.epochDuration = _epochDuration.toUint32();
2226
}
2327

2428
function toTimestamp(Slot _a) internal view returns (Timestamp) {

l1-contracts/src/core/libraries/staking/AddressSnapshotLib.sol

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity >=0.8.27;
44

55
import {Errors} from "@aztec/core/libraries/Errors.sol";
66
import {Timestamp, Epoch, TimeLib} from "@aztec/core/libraries/TimeLib.sol";
7+
import {SafeCast} from "@oz/utils/math/SafeCast.sol";
78

89
/**
910
* @notice Structure to store a set of addresses with their historical snapshots
@@ -35,6 +36,8 @@ struct AddressSnapshot {
3536
* and allows querying the state of addresses at any point in time
3637
*/
3738
library AddressSnapshotLib {
39+
using SafeCast for uint256;
40+
3841
/**
3942
* @notice Bit mask used to indicate presence of a validator in the set
4043
*/
@@ -61,7 +64,7 @@ library AddressSnapshotLib {
6164

6265
_self.validatorToIndex[_validator] = indexWithBit;
6366
_self.checkpoints[index].push(
64-
AddressSnapshot({addr: _validator, epochNumber: uint96(Epoch.unwrap(_epochNumber))})
67+
AddressSnapshot({addr: _validator, epochNumber: Epoch.unwrap(_epochNumber).toUint96()})
6568
);
6669
_self.size += 1;
6770
return true;
@@ -83,20 +86,19 @@ library AddressSnapshotLib {
8386
AddressSnapshot memory lastSnapshot = _self.checkpoints[lastIndex][lastSnapshotLength - 1];
8487

8588
address lastValidator = lastSnapshot.addr;
86-
uint256 newLocationWithMask = _index | PRESENCE_BIT;
87-
88-
_self.validatorToIndex[lastValidator] = newLocationWithMask; // Remove the last validator from the index
89+
uint256 newLocation = _index | PRESENCE_BIT;
8990

9091
// If we are removing the last item, we cannot swap it with anything
9192
// so we append a new address of zero for this epoch
93+
// And since we are removing it, we set the location to 0
9294
if (lastIndex == _index) {
9395
lastSnapshot.addr = address(0);
94-
95-
// TODO: reuse value above, only insert once
96-
_self.validatorToIndex[lastValidator] = 0;
96+
newLocation = 0;
9797
}
9898

99-
lastSnapshot.epochNumber = uint96(epochNow);
99+
_self.validatorToIndex[lastValidator] = 0;
100+
101+
lastSnapshot.epochNumber = epochNow.toUint96();
100102
// Check if there's already a checkpoint for this index in the current epoch
101103
uint256 checkpointCount = _self.checkpoints[_index].length;
102104
if (
@@ -164,7 +166,7 @@ library AddressSnapshotLib {
164166
Epoch _epoch
165167
) internal view returns (address) {
166168
uint256 numCheckpoints = _self.checkpoints[_index].length;
167-
uint96 epoch = uint96(Epoch.unwrap(_epoch));
169+
uint96 epoch = Epoch.unwrap(_epoch).toUint96();
168170

169171
if (numCheckpoints == 0) {
170172
return address(0);

0 commit comments

Comments
 (0)