Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
297 changes: 297 additions & 0 deletions l1-contracts/.gas-snapshot

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion l1-contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Alternatively you can use docker instead, it will handle installations and run t

The `src` folder contain contracts that is to be used by the local developer testnet. It is grouped into 3 categories:

- `core` contains the required contracts, the bare minimum
- `core` contains the required contracts, the bare minimum.
- `governance` contains the contracts for the governance system.
- `mock` contains stubs, for now an always true verifier.
- `periphery` stuff that is nice to have, convenience contracts and functions belong in here.

Expand All @@ -31,6 +32,16 @@ We use `forge fmt` to format. But follow a few general guidelines beyond the sta
- Do `function transfer(address _to, uint256 _amount);`
- use `_` prefix for `internal` and `private` functions.

## Gas snapshots and CI

CI will run `forge snapshot --check`. This means that as you develop, you should run `./bootstrap.sh snapshot --diff` to make sure you understand the gas cost of your changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure how much I would care about the gas spent on tests, but more the gas spent on the functions in the contracts. e.g., a test spending 15M gas is not super important for me, but if it is a function that we use that is spending 15M gas that is something that is important


Note: the only reason `forge snapshot` is wrapped in the bootstrap script is to standardize the output, or any future filtering.

When your PR is ready for review, run `./bootstrap.sh snapshot` to update the snapshot, then `./bootstrap.sh test` to make sure you're good.

You can also run `./bootstrap.sh gas_report` to get a gas report for the current state.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it would be fine to mention the FORGE_GAS_REPORT here. Also we should just have a general note that a bunch of the blob logic is skipped in the gas reports so they are not exact


## Contracts:

The contracts are in a very early stage, and don't worry about gas costs right now. Instead they prioritize development velocity.
Expand Down
19 changes: 18 additions & 1 deletion l1-contracts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function build {
function test_cmds {
echo "$hash cd l1-contracts && solhint --config ./.solhint.json \"src/**/*.sol\""
echo "$hash cd l1-contracts && forge fmt --check"
echo "$hash cd l1-contracts && forge test --no-match-contract UniswapPortalTest"
echo "$hash cd l1-contracts && ./bootstrap.sh snapshot --check --tolerance 1"
}

function test {
Expand Down Expand Up @@ -100,6 +100,16 @@ function inspect {
done
}

function gas_report {
echo_header "l1-contracts gas report"
FORGE_GAS_REPORT=true forge test --no-match-contract "(FeeRollupTest)|(MinimalFeeModelTest)" --no-match-test "(testInvalidBlobHash)|(testInvalidBlobProof)"
}

function snapshot {
echo_header "l1-contracts gas snapshot"
forge snapshot --desc "$@"
}

# 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 @@ -195,6 +205,13 @@ case "$cmd" in
"inspect")
inspect
;;
"gas_report")
gas_report
;;
"snapshot")
shift
snapshot "$@"
;;
test_cmds|release)
$cmd
;;
Expand Down
6 changes: 5 additions & 1 deletion l1-contracts/test/MultiProof.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import {Rollup} from "@aztec/core/Rollup.sol";
import {Strings} from "@oz/utils/Strings.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";

import {RollupBase, IInstance} from "./base/RollupBase.sol";

// solhint-disable comprehensive-interface
Expand Down Expand Up @@ -90,6 +89,11 @@ contract MultiProofTest is RollupBase {
)
)
);
// skip blob check if forge gas report is true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the rollup.t.sol are both pulling from the rollup base. We could instead have a value that is written in the constructor or so to set it up neatly across all of them and not having multiple places needing to go look for env vars? Could also mean that this value is just set in that one place and not even needed in the others which seems nice

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra reason for this is that it would be inherited 👀 so we would avoid an issue as just encountered hehe where the ignition ones are using the blobs so it fails because not updated.

// https://github.com/foundry-rs/foundry/issues/10074
if (vm.envOr("FORGE_GAS_REPORT", false)) {
skipBlobCheck(address(rollup));
}

registry.upgrade(address(rollup));

Expand Down
5 changes: 5 additions & 0 deletions l1-contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ contract RollupTest is RollupBase {
)
)
);
// skip blob check if forge gas report is true
// https://github.com/foundry-rs/foundry/issues/10074
if (vm.envOr("FORGE_GAS_REPORT", false)) {
skipBlobCheck(address(rollup));
}
inbox = Inbox(address(rollup.getInbox()));
outbox = Outbox(address(rollup.getOutbox()));
registry.upgrade(address(rollup));
Expand Down
6 changes: 5 additions & 1 deletion l1-contracts/test/base/RollupBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ contract RollupBase is DecoderBase {
blobHash := mload(add(blobInputs, 0x21))
}
blobHashes[0] = blobHash;
vm.blobhashes(blobHashes);
// don't add blob hashes if forge gas report is true
// https://github.com/foundry-rs/foundry/issues/10074
if (!vm.envOr("FORGE_GAS_REPORT", false)) {
vm.blobhashes(blobHashes);
}
}

ProposeArgs memory args = ProposeArgs({
Expand Down