Skip to content
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
3 changes: 3 additions & 0 deletions l1-contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ serve/

gas_report.new.*
gas_report.diff

gas_benchmark.new.*
gas_benchmark.diff
27 changes: 27 additions & 0 deletions l1-contracts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,29 @@ function gas_report {
mv gas_report.new.md gas_report.md
}


function gas_benchmark {
check=${1:-"no"}
echo_header "Benchmarking gas"
forge --version

FORGE_GAS_REPORT=true forge test \
--match-contract "BenchmarkRollupTest" \
--fuzz-seed 42 \
--isolate \
> gas_benchmark.new.tmp
grep "^|" gas_benchmark.new.tmp > gas_benchmark.new.md
rm gas_benchmark.new.tmp
diff gas_benchmark.new.md gas_benchmark.md > gas_benchmark.diff || true

if [ -s gas_benchmark.diff -a "$check" = "check" ]; then
cat gas_benchmark.diff
echo "Gas benchmark has changed. Please check the diffs above, then run './bootstrap.sh gas_benchmark' to update the gas benchmark."
exit 1
fi
mv gas_benchmark.new.md gas_benchmark.md
}

# First argument is a branch name (e.g. master, or the latest version e.g. 1.2.3) to push to the head of.
# Second argument is the tag name (e.g. v1.2.3, or commit-<hash>).
# Third argument is the semver for package.json (e.g. 1.2.3 or 1.2.3-commit.<hash>)
Expand Down Expand Up @@ -216,6 +239,10 @@ case "$cmd" in
shift
gas_report "$@"
;;
"gas_benchmark")
shift
gas_benchmark "$@"
;;
test|test_cmds|inspect|release)
$cmd
;;
Expand Down
26 changes: 26 additions & 0 deletions l1-contracts/gas_benchmark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
| src/core/Rollup.sol:Rollup contract | | | | | |
|-------------------------------------|-----------------|----------|----------|----------|---------|
| Deployment Cost | Deployment Size | | | | |
| 7944840 | 38653 | | | | |
| Function Name | min | avg | median | max | # calls |
| cheat__InitialiseValidatorSet | 13524835 | 13524835 | 13524835 | 13524835 | 1 |
| getBlock | 1230 | 1230 | 1230 | 1230 | 12 |
| getBurnAddress | 369 | 369 | 369 | 369 | 1 |
| getCurrentEpoch | 1017 | 1017 | 1017 | 1017 | 397 |
| getCurrentProposer | 139908 | 143780 | 140137 | 263958 | 200 |
| getCurrentSlot | 823 | 833 | 823 | 4823 | 397 |
| getEpochCommittee | 135768 | 139483 | 135780 | 259358 | 100 |
| getEpochForBlock | 1016 | 1016 | 1016 | 1016 | 196 |
| getFeeHeader | 1457 | 1457 | 1457 | 1457 | 95 |
| getManaBaseFeeAt | 20442 | 26863 | 27182 | 34313 | 195 |
| getPendingBlockNumber | 507 | 511 | 507 | 2507 | 401 |
| getProvenBlockNumber | 490 | 490 | 490 | 490 | 3 |
| getTimestampForSlot | 887 | 887 | 887 | 887 | 195 |
| setProvingCostPerMana | 25915 | 25942 | 25915 | 28715 | 101 |
| submitEpochRootProof | 771062 | 783900 | 771086 | 809552 | 3 |
| src/periphery/Forwarder.sol:Forwarder contract | | | | | |
|------------------------------------------------|-----------------|--------|--------|---------|---------|
| Deployment Cost | Deployment Size | | | | |
| 358690 | 1553 | | | | |
| Function Name | min | avg | median | max | # calls |
| forward | 634788 | 685012 | 645781 | 1916159 | 100 |
35 changes: 17 additions & 18 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ contract Rollup is IStaking, IValidatorSelection, IRollup, RollupCore {
return ValidatorSelectionLib.getCommitteeAt(StakingLib.getStorage(), getCurrentEpoch());
}

/**
* @notice Get the validator set for a given epoch
*
* @dev Consider removing this to replace with a `size` and individual getter.
*
* @param _epoch The epoch number to get the validator set for
*
* @return The validator set for the given epoch
*/
function getEpochCommittee(Epoch _epoch)
external
override(IValidatorSelection)
returns (address[] memory)
{
return ValidatorSelectionLib.getCommitteeAt(StakingLib.getStorage(), _epoch);
}

/**
* @notice Get the committee for a given timestamp
*
Expand Down Expand Up @@ -394,24 +411,6 @@ contract Rollup is IStaking, IValidatorSelection, IRollup, RollupCore {
OperatorInfo({proposer: StakingLib.getStorage().info[attester].proposer, attester: attester});
}

/**
* @notice Get the validator set for a given epoch
*
* @dev Consider removing this to replace with a `size` and individual getter.
*
* @param _epoch The epoch number to get the validator set for
*
* @return The validator set for the given epoch
*/
function getEpochCommittee(Epoch _epoch)
external
view
override(IValidatorSelection)
returns (address[] memory)
{
return ValidatorSelectionLib.getStorage().epochs[_epoch].committee;
}

/**
* @notice Get the sample seed for a given timestamp
*
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/src/core/interfaces/IValidatorSelection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface IValidatorSelection is IValidatorSelectionCore {
// Non view as uses transient storage
function getCurrentEpochCommittee() external returns (address[] memory);
function getCommitteeAt(Timestamp _ts) external returns (address[] memory);
function getEpochCommittee(Epoch _epoch) external returns (address[] memory);

// Stable
function getCurrentEpoch() external view returns (Epoch);
Expand All @@ -46,7 +47,6 @@ interface IValidatorSelection is IValidatorSelectionCore {

// Likely removal of these to replace with a size and indiviual getter
// Get the current epoch committee
function getEpochCommittee(Epoch _epoch) external view returns (address[] memory);
function getAttesters() external view returns (address[] memory);

function getSampleSeedAt(Timestamp _ts) external view returns (uint256);
Expand Down
8 changes: 7 additions & 1 deletion l1-contracts/src/periphery/SlashPayload.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ contract SlashPayload is IPayload {
IValidatorSelection public immutable VALIDATOR_SELECTION;
uint256 public immutable AMOUNT;

address[] public attesters;

constructor(Epoch _epoch, IValidatorSelection _validatorSelection, uint256 _amount) {
EPOCH = _epoch;
VALIDATOR_SELECTION = _validatorSelection;
AMOUNT = _amount;

address[] memory attesters_ = IValidatorSelection(VALIDATOR_SELECTION).getEpochCommittee(EPOCH);
for (uint256 i = 0; i < attesters_.length; i++) {
attesters.push(attesters_[i]);
}
}

function getActions() external view override(IPayload) returns (IPayload.Action[] memory) {
address[] memory attesters = IValidatorSelection(VALIDATOR_SELECTION).getEpochCommittee(EPOCH);
IPayload.Action[] memory actions = new IPayload.Action[](attesters.length);

for (uint256 i = 0; i < attesters.length; i++) {
Expand Down
Loading
Loading