mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-12 07:28:08 -05:00
Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90e3dddf91 | ||
|
|
c6cc51bcfd | ||
|
|
0b0b84a513 | ||
|
|
83c8071123 | ||
|
|
e35de74495 | ||
|
|
33089b829f | ||
|
|
8e27052b36 | ||
|
|
25b956f9b5 | ||
|
|
f4663fd249 | ||
|
|
c71fa5a5fc | ||
|
|
4af3834e36 | ||
|
|
9983585bdd | ||
|
|
d288b34536 | ||
|
|
a2fe246551 | ||
|
|
8699a22fa3 | ||
|
|
d668180e9a | ||
|
|
d3c2e34650 | ||
|
|
38551c4eeb | ||
|
|
82330621ce | ||
|
|
237d048ce6 | ||
|
|
38b440b1fa | ||
|
|
0ed3d68fc3 | ||
|
|
2847d02498 | ||
|
|
a7d9bf3488 | ||
|
|
255eb5f307 | ||
|
|
0955382aec | ||
|
|
07961f751e | ||
|
|
bbd5a5a9c2 | ||
|
|
2e1f42fcb6 | ||
|
|
bcdbe1f119 | ||
|
|
6034c43bb1 | ||
|
|
f9da81d587 | ||
|
|
38f64e70b7 | ||
|
|
44b924170a | ||
|
|
227f09a2cf | ||
|
|
112e82a4ef | ||
|
|
82e6d28e82 | ||
|
|
8daa5d5496 | ||
|
|
3958e8bd86 | ||
|
|
f553a70d20 | ||
|
|
2dc5ceb44c | ||
|
|
ff03924d76 | ||
|
|
f6894bb82f | ||
|
|
e990e02391 | ||
|
|
f8d48a6326 | ||
|
|
dba097e03d | ||
|
|
30ad0bfe78 |
2
.github/pull_request_template.md
vendored
2
.github/pull_request_template.md
vendored
@@ -20,7 +20,7 @@ Your PR title must follow [conventional commits](https://www.conventionalcommits
|
||||
|
||||
### Deployment tag versioning
|
||||
|
||||
Has `tag` in `common/version.go` been updated?
|
||||
Has `tag` in `common/version.go` been updated or have you added `bump-version` label to this PR?
|
||||
|
||||
- [ ] No, this PR doesn't involve a new deployment, git tag, docker image tag
|
||||
- [ ] Yes
|
||||
|
||||
4
.github/workflows/bump_version.yml
vendored
4
.github/workflows/bump_version.yml
vendored
@@ -2,15 +2,17 @@ name: Bump Version
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [develop]
|
||||
branches: [ develop ]
|
||||
types:
|
||||
- opened
|
||||
- reopened
|
||||
- synchronize
|
||||
- ready_for_review
|
||||
- labeled
|
||||
|
||||
jobs:
|
||||
try-to-bump:
|
||||
if: contains(github.event.pull_request.labels.*.name, 'bump-version')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
|
||||
2
.github/workflows/common.yml
vendored
2
.github/workflows/common.yml
vendored
@@ -9,6 +9,7 @@ on:
|
||||
- alpha
|
||||
paths:
|
||||
- 'common/**'
|
||||
- '!common/version/version.go'
|
||||
- '.github/workflows/common.yml'
|
||||
pull_request:
|
||||
types:
|
||||
@@ -18,6 +19,7 @@ on:
|
||||
- ready_for_review
|
||||
paths:
|
||||
- 'common/**'
|
||||
- '!common/version/version.go'
|
||||
- '.github/workflows/common.yml'
|
||||
|
||||
jobs:
|
||||
|
||||
2
.github/workflows/coordinator.yml
vendored
2
.github/workflows/coordinator.yml
vendored
@@ -10,6 +10,7 @@ on:
|
||||
paths:
|
||||
- 'coordinator/**'
|
||||
- 'common/**'
|
||||
- '!common/version/version.go'
|
||||
- 'database/**'
|
||||
- '.github/workflows/coordinator.yml'
|
||||
pull_request:
|
||||
@@ -21,6 +22,7 @@ on:
|
||||
paths:
|
||||
- 'coordinator/**'
|
||||
- 'common/**'
|
||||
- '!common/version/version.go'
|
||||
- 'database/**'
|
||||
- '.github/workflows/coordinator.yml'
|
||||
|
||||
|
||||
2
.github/workflows/database.yml
vendored
2
.github/workflows/database.yml
vendored
@@ -10,6 +10,7 @@ on:
|
||||
paths:
|
||||
- 'database/**'
|
||||
- 'common/**'
|
||||
- '!common/version/version.go'
|
||||
- '.github/workflows/database.yml'
|
||||
pull_request:
|
||||
types:
|
||||
@@ -20,6 +21,7 @@ on:
|
||||
paths:
|
||||
- 'database/**'
|
||||
- 'common/**'
|
||||
- '!common/version/version.go'
|
||||
- '.github/workflows/database.yml'
|
||||
|
||||
jobs:
|
||||
|
||||
@@ -48,27 +48,6 @@ jobs:
|
||||
tags: scrolltech/gas-oracle:${{github.ref_name}}
|
||||
# cache-from: type=gha,scope=${{ github.workflow }}
|
||||
# cache-to: type=gha,scope=${{ github.workflow }}
|
||||
msg_relayer:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push msg_relayer docker
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./build/dockerfiles/msg_relayer.Dockerfile
|
||||
push: true
|
||||
tags: scrolltech/msg-relayer:${{github.ref_name}}
|
||||
# cache-from: type=gha,scope=${{ github.workflow }}
|
||||
# cache-to: type=gha,scope=${{ github.workflow }}
|
||||
rollup_relayer:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
- name: Build prerequisites
|
||||
run: |
|
||||
make dev_docker
|
||||
make -C bridge mock_abi
|
||||
make -C rollup mock_abi
|
||||
make -C common/bytecode all
|
||||
- name: Run integration tests
|
||||
run: |
|
||||
@@ -1,4 +1,4 @@
|
||||
name: Bridge
|
||||
name: Rollup
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -8,10 +8,11 @@ on:
|
||||
- develop
|
||||
- alpha
|
||||
paths:
|
||||
- 'bridge/**'
|
||||
- 'rollup/**'
|
||||
- 'common/**'
|
||||
- '!common/version/version.go'
|
||||
- 'database/**'
|
||||
- '.github/workflows/bridge.yml'
|
||||
- '.github/workflows/rollup.yml'
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
@@ -19,10 +20,11 @@ on:
|
||||
- synchronize
|
||||
- ready_for_review
|
||||
paths:
|
||||
- 'bridge/**'
|
||||
- 'rollup/**'
|
||||
- 'common/**'
|
||||
- '!common/version/version.go'
|
||||
- 'database/**'
|
||||
- '.github/workflows/bridge.yml'
|
||||
- '.github/workflows/rollup.yml'
|
||||
|
||||
jobs:
|
||||
check:
|
||||
@@ -44,7 +46,7 @@ jobs:
|
||||
- name: Install Geth Tools
|
||||
uses: gacts/install-geth-tools@v1
|
||||
- name: Lint
|
||||
working-directory: 'bridge'
|
||||
working-directory: 'rollup'
|
||||
run: |
|
||||
rm -rf $HOME/.cache/golangci-lint
|
||||
make mock_abi
|
||||
@@ -62,14 +64,14 @@ jobs:
|
||||
- name: Install goimports
|
||||
run: go install golang.org/x/tools/cmd/goimports
|
||||
- name: Run goimports lint
|
||||
run: goimports -local scroll-tech/bridge/ -w .
|
||||
working-directory: 'bridge'
|
||||
run: goimports -local scroll-tech/rollup/ -w .
|
||||
working-directory: 'rollup'
|
||||
- name: Run go mod tidy
|
||||
run: go mod tidy
|
||||
working-directory: 'bridge'
|
||||
working-directory: 'rollup'
|
||||
# If there are any diffs from goimports or go mod tidy, fail.
|
||||
- name: Verify no changes from goimports and go mod tidy
|
||||
working-directory: 'bridge'
|
||||
working-directory: 'rollup'
|
||||
run: |
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
exit 1
|
||||
@@ -95,13 +97,13 @@ jobs:
|
||||
- name: Build prerequisites
|
||||
run: |
|
||||
make dev_docker
|
||||
make -C bridge mock_abi
|
||||
- name: Build bridge binaries
|
||||
working-directory: 'bridge'
|
||||
make -C rollup mock_abi
|
||||
- name: Build rollup binaries
|
||||
working-directory: 'rollup'
|
||||
run: |
|
||||
make bridge_bins
|
||||
- name: Test bridge packages
|
||||
working-directory: 'bridge'
|
||||
make rollup_bins
|
||||
- name: Test rollup packages
|
||||
working-directory: 'rollup'
|
||||
run: |
|
||||
go test -v -race -gcflags="-l" -ldflags="-s=false" -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
- name: Upload coverage reports to Codecov
|
||||
@@ -109,7 +111,7 @@ jobs:
|
||||
env:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
with:
|
||||
flags: bridge
|
||||
flags: rollup
|
||||
# docker-build:
|
||||
# if: github.event.pull_request.draft == false
|
||||
# runs-on: ubuntu-latest
|
||||
17
.gitignore
vendored
17
.gitignore
vendored
@@ -1,9 +1,22 @@
|
||||
.idea
|
||||
# Asset files
|
||||
assets/params*
|
||||
assets/seed
|
||||
coverage.txt
|
||||
|
||||
# Built binaries
|
||||
build/bin
|
||||
|
||||
coverage.txt
|
||||
*.integration.txt
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
|
||||
# IntelliJ
|
||||
.idea
|
||||
|
||||
# MacOS
|
||||
.DS_Store
|
||||
|
||||
# misc
|
||||
sftp-config.json
|
||||
*~
|
||||
|
||||
128
CODE_OF_CONDUCT.md
Normal file
128
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,128 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
contributor@scroll.io.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
||||
42
CONTRIBUTING.md
Normal file
42
CONTRIBUTING.md
Normal file
@@ -0,0 +1,42 @@
|
||||
## Contributing
|
||||
|
||||
[fork]: /fork
|
||||
[pr]: /compare
|
||||
[style]: https://standardjs.com/
|
||||
[code-of-conduct]: CODE_OF_CONDUCT.md
|
||||
|
||||
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
|
||||
|
||||
Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.
|
||||
|
||||
## Contribute to Scroll
|
||||
|
||||
Did you know there are many ways of contributing to Scroll? If you are looking to contribute to by adding Scroll to existing Dev Tools or by doing integrations please go to the [Contribute to Scroll](https://github.com/scroll-tech/contribute-to-scroll) repo instead. If you are looking to contribute to Scroll's Halo2 zkEVM circuits please refer to the [zkEVM circuits](https://github.com/scroll-tech/zkevm-circuits) repo. This repository covers the Scroll infrastructure and smart contracts, if you want to contribute to these areas continue reading this document.
|
||||
|
||||
## Issues and PRs
|
||||
|
||||
If you have suggestions for how this project could be improved, or want to report a bug, open an issue! We'd love all and any contributions. If you have questions, too, we'd love to hear them.
|
||||
|
||||
We'd also love PRs. If you're thinking of a large PR, we advise opening up an issue first to talk about it, though! Look at the links below if you're not sure how to open a PR.
|
||||
|
||||
## Submitting a pull request
|
||||
|
||||
1. [Fork][fork] and clone the repository.
|
||||
1. Create a new branch: `git checkout -b my-branch-name`.
|
||||
1. Make your change, add tests, and make sure the tests still pass.
|
||||
1. Push to your fork and [submit a pull request][pr].
|
||||
1. Pat yourself on the back and wait for your pull request to be reviewed and merged.
|
||||
|
||||
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
|
||||
|
||||
- Write and update tests.
|
||||
- Keep your changes as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
|
||||
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
|
||||
|
||||
Work in Progress pull requests are also welcome to get feedback early on, or if there is something that blocked you.
|
||||
|
||||
## Resources
|
||||
|
||||
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
|
||||
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
|
||||
- [GitHub Help](https://help.github.com)
|
||||
8
Makefile
8
Makefile
@@ -1,6 +1,6 @@
|
||||
.PHONY: check update dev_docker build_test_docker run_test_docker clean
|
||||
|
||||
L2GETH_TAG=scroll-v4.3.34
|
||||
L2GETH_TAG=scroll-v4.3.55
|
||||
|
||||
help: ## Display this help message
|
||||
@grep -h \
|
||||
@@ -8,7 +8,7 @@ help: ## Display this help message
|
||||
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
||||
|
||||
lint: ## The code's format and security checks.
|
||||
make -C bridge lint
|
||||
make -C rollup lint
|
||||
make -C common lint
|
||||
make -C coordinator lint
|
||||
make -C database lint
|
||||
@@ -17,7 +17,7 @@ lint: ## The code's format and security checks.
|
||||
|
||||
update: ## update dependencies
|
||||
go work sync
|
||||
cd $(PWD)/bridge/ && go get -u github.com/scroll-tech/go-ethereum@${L2GETH_TAG} && go mod tidy
|
||||
cd $(PWD)/rollup/ && go get -u github.com/scroll-tech/go-ethereum@${L2GETH_TAG} && go mod tidy
|
||||
cd $(PWD)/bridge-history-api/ && go get -u github.com/ethereum/go-ethereum@latest && go mod tidy
|
||||
cd $(PWD)/common/ && go get -u github.com/scroll-tech/go-ethereum@${L2GETH_TAG} && go mod tidy
|
||||
cd $(PWD)/coordinator/ && go get -u github.com/scroll-tech/go-ethereum@${L2GETH_TAG} && go mod tidy
|
||||
@@ -25,7 +25,7 @@ update: ## update dependencies
|
||||
cd $(PWD)/prover/ && go get -u github.com/scroll-tech/go-ethereum@${L2GETH_TAG} && go mod tidy
|
||||
cd $(PWD)/prover-stats-api/ && go get -u github.com/scroll-tech/go-ethereum@${L2GETH_TAG} && go mod tidy
|
||||
cd $(PWD)/tests/integration-test/ && go get -u github.com/scroll-tech/go-ethereum@${L2GETH_TAG} && go mod tidy
|
||||
goimports -local $(PWD)/bridge/ -w .
|
||||
goimports -local $(PWD)/rollup/ -w .
|
||||
goimports -local $(PWD)/bridge-history-api/ -w .
|
||||
goimports -local $(PWD)/common/ -w .
|
||||
goimports -local $(PWD)/coordinator/ -w .
|
||||
|
||||
41
README.md
41
README.md
@@ -1,7 +1,34 @@
|
||||
# Scroll Monorepo
|
||||
|
||||
[](https://github.com/scroll-tech/scroll/actions/workflows/rollup.yml)
|
||||
[](https://github.com/scroll-tech/scroll/actions/workflows/contracts.yml)
|
||||
[](https://github.com/scroll-tech/scroll/actions/workflows/bridge_history_api.yml)
|
||||
[](https://github.com/scroll-tech/scroll/actions/workflows/coordinator.yml)
|
||||
[](https://github.com/scroll-tech/scroll/actions/workflows/prover.yml)
|
||||
[](https://github.com/scroll-tech/scroll/actions/workflows/integration.yml)
|
||||
[](https://codecov.io/gh/scroll-tech/scroll)
|
||||
|
||||
<a href="https://scroll.io">Scroll</a> is a zkRollup Layer 2 dedicated to enhance Ethereum scalability through a bytecode-equivalent [zkEVM](https://github.com/scroll-tech/zkevm-circuits) circuit. This monorepo encompasses essential infrastructure components of the Scroll protocol. It contains the L1 and L2 contracts, the rollup node, the prover client, and the prover coordinator.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
<pre>
|
||||
├── <a href="./bridge-history-api/">bridge-history-api</a>: Bridge history service that collects deposit and withdraw events from both L1 and L2 chain and generates withdrawal proofs
|
||||
├── <a href="./common/">common</a>: Common libraries and types
|
||||
├── <a href="./coordinator/">coordinator</a>: Prover coordinator service that dispatches proving tasks to provers
|
||||
├── <a href="./database">database</a>: Database client and schema definition
|
||||
├── <a href="./src">l2geth</a>: Scroll execution node
|
||||
├── <a href="./prover">prover</a>: Prover client that runs proof generation for zkEVM circuit and aggregation circuit
|
||||
├── <a href="./prover-stats-api">prover-stats-api</a>: Collect and show prover statistics
|
||||
├── <a href="./rollup">rollup</a>: Rollup-related services
|
||||
├── <a href="./rpc-gateway">rpc-gateway</a>: RPC gateway external repo
|
||||
└── <a href="./tests">tests</a>: Integration tests
|
||||
</pre>
|
||||
|
||||
## Contributing
|
||||
|
||||
We welcome community contributions to this repository. Before you submit any issues or PRs, please read the [Code of Conduct](CODE_OF_CONDUCT.md) and the [Contribution Guideline](CONTRIBUTING.md).
|
||||
|
||||
## Prerequisites
|
||||
+ Go 1.19
|
||||
+ Rust (for version, see [rust-toolchain](./common/libzkp/impl/rust-toolchain))
|
||||
@@ -15,14 +42,14 @@ docker pull postgres
|
||||
make dev_docker
|
||||
```
|
||||
|
||||
## Testing Bridge & Coordinator
|
||||
## Testing Rollup & Coordinator
|
||||
|
||||
### For Non-Apple Silicon (M1/M2) Macs
|
||||
|
||||
Run the tests using the following commands:
|
||||
|
||||
```bash
|
||||
go test -v -race -covermode=atomic scroll-tech/bridge/...
|
||||
go test -v -race -covermode=atomic scroll-tech/rollup/...
|
||||
go test -tags="mock_verifier" -v -race -covermode=atomic scroll-tech/coordinator/...
|
||||
go test -v -race -covermode=atomic scroll-tech/database/...
|
||||
go test -v -race -covermode=atomic scroll-tech/common/...
|
||||
@@ -55,7 +82,7 @@ This command runs a Docker container named `scroll_test_container` from the `scr
|
||||
Once the Docker container is running, execute the tests using the following commands:
|
||||
|
||||
```bash
|
||||
go test -v -race -covermode=atomic scroll-tech/bridge/...
|
||||
go test -v -race -covermode=atomic scroll-tech/rollup/...
|
||||
go test -tags="mock_verifier" -v -race -covermode=atomic scroll-tech/coordinator/...
|
||||
go test -v -race -covermode=atomic scroll-tech/database/...
|
||||
go test -v -race -covermode=atomic scroll-tech/common/...
|
||||
@@ -63,6 +90,10 @@ go test -v -race -covermode=atomic scroll-tech/common/...
|
||||
|
||||
## Testing Contracts
|
||||
|
||||
You can find the unit tests in [`<REPO_DIR>/contracts/src/test/`](/contracts/src/test/), and integration tests in [`<REPO_DIR>/contracts/integration-test/`](/contracts/integration-test/).
|
||||
You can find the unit tests in [`contracts/src/test/`](/contracts/src/test/), and integration tests in [`contracts/integration-test/`](/contracts/integration-test/).
|
||||
|
||||
For more details on contracts, see [`/contracts`](/contracts).
|
||||
See [`contracts`](/contracts) for more details on the contracts.
|
||||
|
||||
## License
|
||||
|
||||
Scroll Monorepo is licensed under the [MIT](./LICENSE) license.
|
||||
|
||||
@@ -89,9 +89,6 @@ var (
|
||||
// L2FailedRelayedMessageEventSignature = keccak256("FailedRelayedMessage(bytes32)")
|
||||
L2FailedRelayedMessageEventSignature common.Hash
|
||||
|
||||
// L2ImportBlockEventSignature = keccak256("ImportBlock(bytes32,uint256,uint256,uint256,bytes32)")
|
||||
L2ImportBlockEventSignature common.Hash
|
||||
|
||||
// L2AppendMessageEventSignature = keccak256("AppendMessage(uint256,bytes32)")
|
||||
L2AppendMessageEventSignature common.Hash
|
||||
)
|
||||
@@ -153,8 +150,6 @@ func init() {
|
||||
L2RelayedMessageEventSignature = L2ScrollMessengerABI.Events["RelayedMessage"].ID
|
||||
L2FailedRelayedMessageEventSignature = L2ScrollMessengerABI.Events["FailedRelayedMessage"].ID
|
||||
|
||||
L2ImportBlockEventSignature = L1BlockContainerABI.Events["ImportBlock"].ID
|
||||
|
||||
L2AppendMessageEventSignature = L2MessageQueueABI.Events["AppendMessage"].ID
|
||||
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ require (
|
||||
golang.org/x/arch v0.4.0 // indirect
|
||||
golang.org/x/crypto v0.12.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad // indirect
|
||||
golang.org/x/net v0.12.0 // indirect
|
||||
golang.org/x/net v0.14.0 // indirect
|
||||
golang.org/x/sync v0.3.0 // indirect
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
golang.org/x/text v0.12.0 // indirect
|
||||
|
||||
@@ -531,8 +531,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
|
||||
golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
|
||||
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
|
||||
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
|
||||
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
# Bridge
|
||||
|
||||
This repo contains the Scroll bridge.
|
||||
|
||||
In addition, launching the bridge will launch a separate instance of l2geth, and sets up a communication channel
|
||||
between the two, over JSON-RPC sockets.
|
||||
|
||||
Something we should pay attention is that all private keys inside sender instance cannot be duplicated.
|
||||
|
||||
## Dependency
|
||||
|
||||
+ install `abigen`
|
||||
|
||||
``` bash
|
||||
go install -v github.com/scroll-tech/go-ethereum/cmd/abigen
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
make clean
|
||||
make bridge
|
||||
```
|
||||
|
||||
## Start
|
||||
* use default ports and config.json
|
||||
|
||||
```bash
|
||||
./build/bin/bridge --http
|
||||
```
|
||||
|
||||
* use specified ports and config.json
|
||||
|
||||
```bash
|
||||
./build/bin/bridge --config ./config.json --http --http.addr localhost --http.port 8290
|
||||
```
|
||||
@@ -1,7 +0,0 @@
|
||||
package main
|
||||
|
||||
import "scroll-tech/bridge/cmd/event_watcher/app"
|
||||
|
||||
func main() {
|
||||
app.Run()
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package main
|
||||
|
||||
import "scroll-tech/bridge/cmd/gas_oracle/app"
|
||||
|
||||
func main() {
|
||||
app.Run()
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/scroll-tech/go-ethereum/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
"scroll-tech/common/metrics"
|
||||
"scroll-tech/common/utils"
|
||||
"scroll-tech/common/version"
|
||||
|
||||
"scroll-tech/bridge/internal/config"
|
||||
"scroll-tech/bridge/internal/controller/relayer"
|
||||
)
|
||||
|
||||
var app *cli.App
|
||||
|
||||
func init() {
|
||||
// Set up message-relayer app info.
|
||||
app = cli.NewApp()
|
||||
app.Action = action
|
||||
app.Name = "message-relayer"
|
||||
app.Usage = "The Scroll Message Relayer"
|
||||
app.Description = "Message Relayer contains two main service: 1) relay l1 message to l2. 2) relay l2 message to l1."
|
||||
app.Version = version.Version
|
||||
app.Flags = append(app.Flags, utils.CommonFlags...)
|
||||
app.Commands = []*cli.Command{}
|
||||
app.Before = func(ctx *cli.Context) error {
|
||||
return utils.LogSetup(ctx)
|
||||
}
|
||||
// Register `message-relayer-test` app for integration-test.
|
||||
utils.RegisterSimulation(app, utils.MessageRelayerApp)
|
||||
}
|
||||
|
||||
func action(ctx *cli.Context) error {
|
||||
// Load config file.
|
||||
cfgFile := ctx.String(utils.ConfigFileFlag.Name)
|
||||
cfg, err := config.NewConfig(cfgFile)
|
||||
if err != nil {
|
||||
log.Crit("failed to load config file", "config file", cfgFile, "error", err)
|
||||
}
|
||||
|
||||
subCtx, cancel := context.WithCancel(ctx.Context)
|
||||
// Init db connection
|
||||
db, err := database.InitDB(cfg.DBConfig)
|
||||
if err != nil {
|
||||
log.Crit("failed to init db connection", "err", err)
|
||||
}
|
||||
defer func() {
|
||||
cancel()
|
||||
if err = database.CloseDB(db); err != nil {
|
||||
log.Error("can not close ormFactory", "error", err)
|
||||
}
|
||||
}()
|
||||
|
||||
registry := prometheus.DefaultRegisterer
|
||||
metrics.Server(ctx, registry.(*prometheus.Registry))
|
||||
|
||||
l1relayer, err := relayer.NewLayer1Relayer(ctx.Context, db, cfg.L1Config.RelayerConfig, registry)
|
||||
if err != nil {
|
||||
log.Error("failed to create new l1 relayer", "config file", cfgFile, "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Start l1relayer process
|
||||
go utils.Loop(subCtx, 10*time.Second, l1relayer.ProcessSavedEvents)
|
||||
|
||||
// Finish start all message relayer functions
|
||||
log.Info("Start message-relayer successfully")
|
||||
|
||||
// Catch CTRL-C to ensure a graceful shutdown.
|
||||
interrupt := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt, os.Interrupt)
|
||||
|
||||
// Wait until the interrupt signal is received from an OS signal.
|
||||
<-interrupt
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run message_relayer cmd instance.
|
||||
func Run() {
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package main
|
||||
|
||||
import "scroll-tech/bridge/cmd/msg_relayer/app"
|
||||
|
||||
func main() {
|
||||
app.Run()
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package main
|
||||
|
||||
import "scroll-tech/bridge/cmd/rollup_relayer/app"
|
||||
|
||||
func main() {
|
||||
app.Run()
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package relayer
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
type l1RelayerMetrics struct {
|
||||
bridgeL1RelayedMsgsTotal prometheus.Counter
|
||||
bridgeL1RelayedMsgsFailureTotal prometheus.Counter
|
||||
bridgeL1RelayerGasPriceOraclerRunTotal prometheus.Counter
|
||||
bridgeL1RelayerLastGasPrice prometheus.Gauge
|
||||
bridgeL1MsgsRelayedConfirmedTotal prometheus.Counter
|
||||
bridgeL1GasOraclerConfirmedTotal prometheus.Counter
|
||||
}
|
||||
|
||||
var (
|
||||
initL1RelayerMetricOnce sync.Once
|
||||
l1RelayerMetric *l1RelayerMetrics
|
||||
)
|
||||
|
||||
func initL1RelayerMetrics(reg prometheus.Registerer) *l1RelayerMetrics {
|
||||
initL1RelayerMetricOnce.Do(func() {
|
||||
l1RelayerMetric = &l1RelayerMetrics{
|
||||
bridgeL1RelayedMsgsTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer1_msg_relayed_total",
|
||||
Help: "The total number of the l1 relayed message.",
|
||||
}),
|
||||
bridgeL1RelayedMsgsFailureTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer1_msg_relayed_failure_total",
|
||||
Help: "The total number of the l1 relayed failure message.",
|
||||
}),
|
||||
bridgeL1MsgsRelayedConfirmedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer1_relayed_confirmed_total",
|
||||
Help: "The total number of layer1 relayed confirmed",
|
||||
}),
|
||||
bridgeL1RelayerGasPriceOraclerRunTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer1_gas_price_oracler_total",
|
||||
Help: "The total number of layer1 gas price oracler run total",
|
||||
}),
|
||||
bridgeL1RelayerLastGasPrice: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
|
||||
Name: "bridge_layer1_gas_price_latest_gas_price",
|
||||
Help: "The latest gas price of bridge relayer l1",
|
||||
}),
|
||||
bridgeL1GasOraclerConfirmedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer1_gas_oracler_confirmed_total",
|
||||
Help: "The total number of layer1 relayed confirmed",
|
||||
}),
|
||||
}
|
||||
})
|
||||
return l1RelayerMetric
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package relayer
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
type l2RelayerMetrics struct {
|
||||
bridgeL2RelayerProcessPendingBatchTotal prometheus.Counter
|
||||
bridgeL2RelayerProcessPendingBatchSuccessTotal prometheus.Counter
|
||||
bridgeL2RelayerGasPriceOraclerRunTotal prometheus.Counter
|
||||
bridgeL2RelayerLastGasPrice prometheus.Gauge
|
||||
bridgeL2RelayerProcessCommittedBatchesTotal prometheus.Counter
|
||||
bridgeL2RelayerProcessCommittedBatchesFinalizedTotal prometheus.Counter
|
||||
bridgeL2RelayerProcessCommittedBatchesFinalizedSuccessTotal prometheus.Counter
|
||||
bridgeL2BatchesCommittedConfirmedTotal prometheus.Counter
|
||||
bridgeL2BatchesFinalizedConfirmedTotal prometheus.Counter
|
||||
bridgeL2BatchesGasOraclerConfirmedTotal prometheus.Counter
|
||||
}
|
||||
|
||||
var (
|
||||
initL2RelayerMetricOnce sync.Once
|
||||
l2RelayerMetric *l2RelayerMetrics
|
||||
)
|
||||
|
||||
func initL2RelayerMetrics(reg prometheus.Registerer) *l2RelayerMetrics {
|
||||
initL2RelayerMetricOnce.Do(func() {
|
||||
l2RelayerMetric = &l2RelayerMetrics{
|
||||
bridgeL2RelayerProcessPendingBatchTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer2_process_pending_batch_total",
|
||||
Help: "The total number of layer2 process pending batch",
|
||||
}),
|
||||
bridgeL2RelayerProcessPendingBatchSuccessTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer2_process_pending_batch_success_total",
|
||||
Help: "The total number of layer2 process pending success batch",
|
||||
}),
|
||||
bridgeL2RelayerGasPriceOraclerRunTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer2_gas_price_oracler_total",
|
||||
Help: "The total number of layer2 gas price oracler run total",
|
||||
}),
|
||||
bridgeL2RelayerLastGasPrice: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
|
||||
Name: "bridge_layer2_gas_price_latest_gas_price",
|
||||
Help: "The latest gas price of bridge relayer l2",
|
||||
}),
|
||||
bridgeL2RelayerProcessCommittedBatchesTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer2_process_committed_batches_total",
|
||||
Help: "The total number of layer2 process committed batches run total",
|
||||
}),
|
||||
bridgeL2RelayerProcessCommittedBatchesFinalizedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer2_process_committed_batches_finalized_total",
|
||||
Help: "The total number of layer2 process committed batches finalized total",
|
||||
}),
|
||||
bridgeL2RelayerProcessCommittedBatchesFinalizedSuccessTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer2_process_committed_batches_finalized_success_total",
|
||||
Help: "The total number of layer2 process committed batches finalized success total",
|
||||
}),
|
||||
bridgeL2BatchesCommittedConfirmedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer2_process_committed_batches_confirmed_total",
|
||||
Help: "The total number of layer2 process committed batches confirmed total",
|
||||
}),
|
||||
bridgeL2BatchesFinalizedConfirmedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer2_process_finalized_batches_confirmed_total",
|
||||
Help: "The total number of layer2 process finalized batches confirmed total",
|
||||
}),
|
||||
bridgeL2BatchesGasOraclerConfirmedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||
Name: "bridge_layer2_process_gras_oracler_confirmed_total",
|
||||
Help: "The total number of layer2 process finalized batches confirmed total",
|
||||
}),
|
||||
}
|
||||
})
|
||||
return l2RelayerMetric
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/scroll-tech/go-ethereum/accounts/abi/bind"
|
||||
"github.com/scroll-tech/go-ethereum/common"
|
||||
geth_types "github.com/scroll-tech/go-ethereum/core/types"
|
||||
"github.com/scroll-tech/go-ethereum/rpc"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"scroll-tech/common/database"
|
||||
"scroll-tech/common/types"
|
||||
|
||||
"scroll-tech/bridge/internal/controller/relayer"
|
||||
"scroll-tech/bridge/internal/controller/watcher"
|
||||
"scroll-tech/bridge/internal/orm"
|
||||
)
|
||||
|
||||
func testRelayL1MessageSucceed(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer database.CloseDB(db)
|
||||
|
||||
prepareContracts(t)
|
||||
|
||||
l1Cfg := bridgeApp.Config.L1Config
|
||||
l2Cfg := bridgeApp.Config.L2Config
|
||||
|
||||
// Create L1Relayer
|
||||
l1Relayer, err := relayer.NewLayer1Relayer(context.Background(), db, l1Cfg.RelayerConfig, nil)
|
||||
assert.NoError(t, err)
|
||||
// Create L1Watcher
|
||||
confirmations := rpc.LatestBlockNumber
|
||||
l1Watcher := watcher.NewL1WatcherClient(context.Background(), l1Client, 0, confirmations, l1Cfg.L1MessengerAddress,
|
||||
l1Cfg.L1MessageQueueAddress, l1Cfg.ScrollChainContractAddress, db, nil)
|
||||
|
||||
// Create L2Watcher
|
||||
l2Watcher := watcher.NewL2WatcherClient(context.Background(), l2Client, confirmations, l2Cfg.L2MessengerAddress,
|
||||
l2Cfg.L2MessageQueueAddress, l2Cfg.WithdrawTrieRootSlot, db, nil)
|
||||
|
||||
// send message through l1 messenger contract
|
||||
nonce, err := l1MessengerInstance.MessageNonce(&bind.CallOpts{})
|
||||
assert.NoError(t, err)
|
||||
sendTx, err := l1MessengerInstance.SendMessage(l1Auth, l2Auth.From, big.NewInt(0), common.Hex2Bytes("00112233"), big.NewInt(0))
|
||||
assert.NoError(t, err)
|
||||
sendReceipt, err := bind.WaitMined(context.Background(), l1Client, sendTx)
|
||||
assert.NoError(t, err)
|
||||
if sendReceipt.Status != geth_types.ReceiptStatusSuccessful || err != nil {
|
||||
t.Fatalf("Call failed")
|
||||
}
|
||||
|
||||
// l1 watch process events
|
||||
l1Watcher.FetchContractEvent()
|
||||
|
||||
l1MessageOrm := orm.NewL1Message(db)
|
||||
// check db status
|
||||
msg, err := l1MessageOrm.GetL1MessageByQueueIndex(nonce.Uint64())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, types.MsgStatus(msg.Status), types.MsgPending)
|
||||
assert.Equal(t, msg.Target, l2Auth.From.String())
|
||||
|
||||
// process l1 messages
|
||||
l1Relayer.ProcessSavedEvents()
|
||||
|
||||
l1Message, err := l1MessageOrm.GetL1MessageByQueueIndex(nonce.Uint64())
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, l1Message.Layer2Hash)
|
||||
assert.Equal(t, types.MsgStatus(l1Message.Status), types.MsgSubmitted)
|
||||
|
||||
relayTx, _, err := l2Client.TransactionByHash(context.Background(), common.HexToHash(l1Message.Layer2Hash))
|
||||
assert.NoError(t, err)
|
||||
relayTxReceipt, err := bind.WaitMined(context.Background(), l2Client, relayTx)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, len(relayTxReceipt.Logs), 1)
|
||||
|
||||
// fetch message relayed events
|
||||
l2Watcher.FetchContractEvent()
|
||||
msg, err = l1MessageOrm.GetL1MessageByQueueIndex(nonce.Uint64())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, types.MsgStatus(msg.Status), types.MsgConfirmed)
|
||||
}
|
||||
@@ -20,7 +20,7 @@ RUN find ./ | grep libzktrie.so | xargs -I{} cp {} /app/target/release/
|
||||
FROM scrolltech/go-rust-builder:go-1.19-rust-nightly-2022-12-10 as base
|
||||
WORKDIR /src
|
||||
COPY go.work* ./
|
||||
COPY ./bridge/go.* ./bridge/
|
||||
COPY ./rollup/go.* ./rollup/
|
||||
COPY ./common/go.* ./common/
|
||||
COPY ./coordinator/go.* ./coordinator/
|
||||
COPY ./database/go.* ./database/
|
||||
|
||||
@@ -3,7 +3,7 @@ FROM scrolltech/go-alpine-builder:1.19 as base
|
||||
|
||||
WORKDIR /src
|
||||
COPY go.work* ./
|
||||
COPY ./bridge/go.* ./bridge/
|
||||
COPY ./rollup/go.* ./rollup/
|
||||
COPY ./common/go.* ./common/
|
||||
COPY ./coordinator/go.* ./coordinator/
|
||||
COPY ./database/go.* ./database/
|
||||
|
||||
@@ -3,7 +3,7 @@ FROM scrolltech/go-alpine-builder:1.19 as base
|
||||
|
||||
WORKDIR /src
|
||||
COPY go.work* ./
|
||||
COPY ./bridge/go.* ./bridge/
|
||||
COPY ./rollup/go.* ./rollup/
|
||||
COPY ./common/go.* ./common/
|
||||
COPY ./coordinator/go.* ./coordinator/
|
||||
COPY ./database/go.* ./database/
|
||||
@@ -18,7 +18,7 @@ FROM base as builder
|
||||
|
||||
RUN --mount=target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
cd /src/bridge/cmd/event_watcher/ && go build -v -p 4 -o /bin/event_watcher
|
||||
cd /src/rollup/cmd/event_watcher/ && go build -v -p 4 -o /bin/event_watcher
|
||||
|
||||
# Pull event_watcher into a second stage deploy alpine container
|
||||
FROM alpine:latest
|
||||
|
||||
@@ -3,7 +3,7 @@ FROM scrolltech/go-alpine-builder:1.19 as base
|
||||
|
||||
WORKDIR /src
|
||||
COPY go.work* ./
|
||||
COPY ./bridge/go.* ./bridge/
|
||||
COPY ./rollup/go.* ./rollup/
|
||||
COPY ./common/go.* ./common/
|
||||
COPY ./coordinator/go.* ./coordinator/
|
||||
COPY ./database/go.* ./database/
|
||||
@@ -18,7 +18,7 @@ FROM base as builder
|
||||
|
||||
RUN --mount=target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
cd /src/bridge/cmd/gas_oracle/ && go build -v -p 4 -o /bin/gas_oracle
|
||||
cd /src/rollup/cmd/gas_oracle/ && go build -v -p 4 -o /bin/gas_oracle
|
||||
|
||||
# Pull gas_oracle into a second stage deploy alpine container
|
||||
FROM alpine:latest
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
# Download Go dependencies
|
||||
FROM scrolltech/go-alpine-builder:1.19 as base
|
||||
|
||||
WORKDIR /src
|
||||
COPY go.work* ./
|
||||
COPY ./bridge/go.* ./bridge/
|
||||
COPY ./common/go.* ./common/
|
||||
COPY ./coordinator/go.* ./coordinator/
|
||||
COPY ./database/go.* ./database/
|
||||
COPY ./prover-stats-api/go.* ./prover-stats-api/
|
||||
COPY ./prover/go.* ./prover/
|
||||
COPY ./tests/integration-test/go.* ./tests/integration-test/
|
||||
COPY ./bridge-history-api/go.* ./bridge-history-api/
|
||||
RUN go mod download -x
|
||||
|
||||
# Build msg_relayer
|
||||
FROM base as builder
|
||||
|
||||
RUN --mount=target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
cd /src/bridge/cmd/msg_relayer/ && go build -v -p 4 -o /bin/msg_relayer
|
||||
|
||||
# Pull msg_relayer into a second stage deploy alpine container
|
||||
FROM alpine:latest
|
||||
|
||||
COPY --from=builder /bin/msg_relayer /bin/
|
||||
|
||||
ENTRYPOINT ["msg_relayer"]
|
||||
@@ -1,5 +0,0 @@
|
||||
assets/
|
||||
docs/
|
||||
l2geth/
|
||||
rpc-gateway/
|
||||
*target/*
|
||||
@@ -3,7 +3,7 @@ FROM scrolltech/go-alpine-builder:1.19 as base
|
||||
|
||||
WORKDIR /src
|
||||
COPY go.work* ./
|
||||
COPY ./bridge/go.* ./bridge/
|
||||
COPY ./rollup/go.* ./rollup/
|
||||
COPY ./common/go.* ./common/
|
||||
COPY ./coordinator/go.* ./coordinator/
|
||||
COPY ./database/go.* ./database/
|
||||
|
||||
@@ -3,7 +3,7 @@ FROM scrolltech/go-alpine-builder:1.19 as base
|
||||
|
||||
WORKDIR /src
|
||||
COPY go.work* ./
|
||||
COPY ./bridge/go.* ./bridge/
|
||||
COPY ./rollup/go.* ./rollup/
|
||||
COPY ./common/go.* ./common/
|
||||
COPY ./coordinator/go.* ./coordinator/
|
||||
COPY ./database/go.* ./database/
|
||||
@@ -18,7 +18,7 @@ FROM base as builder
|
||||
|
||||
RUN --mount=target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
cd /src/bridge/cmd/rollup_relayer/ && go build -v -p 4 -o /bin/rollup_relayer
|
||||
cd /src/rollup/cmd/rollup_relayer/ && go build -v -p 4 -o /bin/rollup_relayer
|
||||
|
||||
# Pull rollup_relayer into a second stage deploy alpine container
|
||||
FROM alpine:latest
|
||||
|
||||
@@ -3,7 +3,7 @@ set -uex
|
||||
|
||||
profile_name=$1
|
||||
|
||||
exclude_dirs=("scroll-tech/bridge/cmd" "scroll-tech/bridge/tests" "scroll-tech/bridge/mock_bridge" "scroll-tech/coordinator/cmd" "scroll-tech/coordinator/internal/logic/verifier")
|
||||
exclude_dirs=("scroll-tech/rollup/cmd" "scroll-tech/rollup/tests" "scroll-tech/rollup/mock_bridge" "scroll-tech/coordinator/cmd" "scroll-tech/coordinator/internal/logic/verifier")
|
||||
|
||||
all_packages=$(go list ./... | grep -v "^scroll-tech/${profile_name}$")
|
||||
coverpkg="scroll-tech/${profile_name}"
|
||||
|
||||
@@ -6,7 +6,7 @@ flag_management:
|
||||
default_rules:
|
||||
carryforward: true
|
||||
individual_flags:
|
||||
- name: bridge
|
||||
- name: rollup
|
||||
statuses:
|
||||
- type: project
|
||||
target: auto
|
||||
|
||||
@@ -5,8 +5,9 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/docker/docker/pkg/reexec"
|
||||
cmap "github.com/orcaman/concurrent-map"
|
||||
)
|
||||
|
||||
@@ -26,8 +27,9 @@ type Cmd struct {
|
||||
name string
|
||||
args []string
|
||||
|
||||
mu sync.Mutex
|
||||
cmd *exec.Cmd
|
||||
isRunning uint64
|
||||
cmd *exec.Cmd
|
||||
app *exec.Cmd
|
||||
|
||||
checkFuncs cmap.ConcurrentMap //map[string]checkFunc
|
||||
|
||||
@@ -38,13 +40,23 @@ type Cmd struct {
|
||||
}
|
||||
|
||||
// NewCmd create Cmd instance.
|
||||
func NewCmd(name string, args ...string) *Cmd {
|
||||
return &Cmd{
|
||||
func NewCmd(name string, params ...string) *Cmd {
|
||||
cmd := &Cmd{
|
||||
checkFuncs: cmap.New(),
|
||||
name: name,
|
||||
args: args,
|
||||
args: params,
|
||||
ErrChan: make(chan error, 10),
|
||||
cmd: exec.Command(name, params...),
|
||||
app: &exec.Cmd{
|
||||
Path: reexec.Self(),
|
||||
Args: append([]string{name}, params...),
|
||||
},
|
||||
}
|
||||
cmd.cmd.Stdout = cmd
|
||||
cmd.cmd.Stderr = cmd
|
||||
cmd.app.Stdout = cmd
|
||||
cmd.app.Stderr = cmd
|
||||
return cmd
|
||||
}
|
||||
|
||||
// RegistFunc register check func
|
||||
@@ -58,15 +70,14 @@ func (c *Cmd) UnRegistFunc(key string) {
|
||||
}
|
||||
|
||||
func (c *Cmd) runCmd() {
|
||||
cmd := exec.Command(c.args[0], c.args[1:]...) //nolint:gosec
|
||||
cmd.Stdout = c
|
||||
cmd.Stderr = c
|
||||
c.ErrChan <- cmd.Run()
|
||||
fmt.Println("cmd:", append([]string{c.name}, c.args...))
|
||||
if atomic.CompareAndSwapUint64(&c.isRunning, 0, 1) {
|
||||
c.ErrChan <- c.cmd.Run()
|
||||
}
|
||||
}
|
||||
|
||||
// RunCmd parallel running when parallel is true.
|
||||
func (c *Cmd) RunCmd(parallel bool) {
|
||||
fmt.Println("cmd:", c.args)
|
||||
if parallel {
|
||||
go c.runCmd()
|
||||
} else {
|
||||
|
||||
@@ -3,41 +3,45 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/reexec"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// IsRunning 1 started, 0 not started.
|
||||
func (c *Cmd) IsRunning() bool {
|
||||
return atomic.LoadUint64(&c.isRunning) == 1
|
||||
}
|
||||
|
||||
func (c *Cmd) runApp() {
|
||||
fmt.Println("cmd:", append([]string{c.name}, c.args...))
|
||||
if atomic.CompareAndSwapUint64(&c.isRunning, 0, 1) {
|
||||
c.ErrChan <- c.app.Run()
|
||||
}
|
||||
}
|
||||
|
||||
// RunApp exec's the current binary using name as argv[0] which will trigger the
|
||||
// reexec init function for that name (e.g. "geth-test" in cmd/geth/run_test.go)
|
||||
func (c *Cmd) RunApp(waitResult func() bool) {
|
||||
fmt.Println("cmd: ", append([]string{c.name}, c.args...))
|
||||
cmd := &exec.Cmd{
|
||||
Path: reexec.Self(),
|
||||
Args: append([]string{c.name}, c.args...),
|
||||
Stderr: c,
|
||||
Stdout: c,
|
||||
}
|
||||
if waitResult != nil {
|
||||
go func() {
|
||||
_ = cmd.Run()
|
||||
c.runApp()
|
||||
}()
|
||||
waitResult()
|
||||
} else {
|
||||
_ = cmd.Run()
|
||||
c.runApp()
|
||||
}
|
||||
|
||||
c.mu.Lock()
|
||||
c.cmd = cmd
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
// WaitExit wait util process exit.
|
||||
func (c *Cmd) WaitExit() {
|
||||
if atomic.LoadUint64(&c.isRunning) == 0 {
|
||||
return
|
||||
}
|
||||
// Wait all the check functions are finished, interrupt loop when appear error.
|
||||
var err error
|
||||
for err == nil && !c.checkFuncs.IsEmpty() {
|
||||
@@ -52,20 +56,18 @@ func (c *Cmd) WaitExit() {
|
||||
}
|
||||
|
||||
// Send interrupt signal.
|
||||
c.mu.Lock()
|
||||
_ = c.cmd.Process.Signal(os.Interrupt)
|
||||
// should use `_ = c.cmd.Process.Wait()` here, but we have some bugs in coordinator's graceful exit,
|
||||
_ = c.app.Process.Signal(os.Interrupt)
|
||||
// should use `_ = c.app.Process.Wait()` here, but we have some bugs in coordinator's graceful exit,
|
||||
// so we use `Kill` as a temp workaround. And since `WaitExit` is only used in integration tests, so
|
||||
// it won't really affect our functionalities.
|
||||
_ = c.cmd.Process.Kill()
|
||||
c.mu.Unlock()
|
||||
if err = c.app.Process.Signal(syscall.SIGTERM); err != nil {
|
||||
_ = c.app.Process.Kill()
|
||||
}
|
||||
}
|
||||
|
||||
// Interrupt send interrupt signal.
|
||||
func (c *Cmd) Interrupt() {
|
||||
c.mu.Lock()
|
||||
c.ErrChan <- c.cmd.Process.Signal(os.Interrupt)
|
||||
c.mu.Unlock()
|
||||
c.ErrChan <- c.app.Process.Signal(os.Interrupt)
|
||||
}
|
||||
|
||||
// WaitResult return true when get the keyword during timeout.
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCmd(t *testing.T) {
|
||||
app := cmd.NewCmd("curTime", "date", "+%Y-%m-%d")
|
||||
app := cmd.NewCmd("date", "+%Y-%m-%d")
|
||||
|
||||
tm := time.Now()
|
||||
curTime := fmt.Sprintf("%d-%02d-%02d", tm.Year(), tm.Month(), tm.Day())
|
||||
|
||||
@@ -27,6 +27,7 @@ var (
|
||||
|
||||
// AppAPI app interface.
|
||||
type AppAPI interface {
|
||||
IsRunning() bool
|
||||
WaitResult(t *testing.T, timeout time.Duration, keyword string) bool
|
||||
RunApp(waitResult func() bool)
|
||||
WaitExit()
|
||||
|
||||
@@ -36,7 +36,7 @@ func NewImgDB(image, password, dbName string, port int) ImgInstance {
|
||||
dbName: dbName,
|
||||
port: port,
|
||||
}
|
||||
img.cmd = cmd.NewCmd(img.name, img.prepare()...)
|
||||
img.cmd = cmd.NewCmd("docker", img.prepare()...)
|
||||
return img
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func (i *ImgDB) IsRunning() bool {
|
||||
}
|
||||
|
||||
func (i *ImgDB) prepare() []string {
|
||||
cmd := []string{"docker", "run", "--rm", "--name", i.name, "-p", fmt.Sprintf("%d:5432", i.port)}
|
||||
cmd := []string{"run", "--rm", "--name", i.name, "-p", fmt.Sprintf("%d:5432", i.port)}
|
||||
envs := []string{
|
||||
"-e", "POSTGRES_PASSWORD=" + i.password,
|
||||
"-e", fmt.Sprintf("POSTGRES_DB=%s", i.dbName),
|
||||
|
||||
@@ -42,7 +42,7 @@ func NewImgGeth(image, volume, ipc string, hPort, wPort int) GethImgInstance {
|
||||
httpPort: hPort,
|
||||
wsPort: wPort,
|
||||
}
|
||||
img.cmd = cmd.NewCmd(img.name, img.prepare()...)
|
||||
img.cmd = cmd.NewCmd("docker", img.params()...)
|
||||
return img
|
||||
}
|
||||
|
||||
@@ -149,8 +149,8 @@ func (i *ImgGeth) Stop() error {
|
||||
return cli.ContainerRemove(ctx, i.id, types.ContainerRemoveOptions{})
|
||||
}
|
||||
|
||||
func (i *ImgGeth) prepare() []string {
|
||||
cmds := []string{"docker", "run", "--rm", "--name", i.name}
|
||||
func (i *ImgGeth) params() []string {
|
||||
cmds := []string{"run", "--rm", "--name", i.name}
|
||||
var ports []string
|
||||
if i.httpPort != 0 {
|
||||
ports = append(ports, []string{"-p", strconv.Itoa(i.httpPort) + ":8545"}...)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM scrolltech/l2geth:scroll-v4.3.34
|
||||
FROM scrolltech/l2geth:scroll-v4.3.55
|
||||
|
||||
RUN mkdir -p /l2geth/keystore
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ require (
|
||||
github.com/modern-go/reflect2 v1.0.2
|
||||
github.com/orcaman/concurrent-map v1.0.0
|
||||
github.com/prometheus/client_golang v1.14.0
|
||||
github.com/scroll-tech/go-ethereum v1.10.14-0.20230812030736-25fe3ba69a28
|
||||
github.com/scroll-tech/go-ethereum v1.10.14-0.20230829000527-f883dcdc21fc
|
||||
github.com/stretchr/testify v1.8.3
|
||||
github.com/urfave/cli/v2 v2.25.7
|
||||
gorm.io/driver/postgres v1.5.0
|
||||
@@ -117,7 +117,7 @@ require (
|
||||
golang.org/x/arch v0.4.0 // indirect
|
||||
golang.org/x/crypto v0.12.0 // indirect
|
||||
golang.org/x/mod v0.12.0 // indirect
|
||||
golang.org/x/net v0.12.0 // indirect
|
||||
golang.org/x/net v0.14.0 // indirect
|
||||
golang.org/x/sync v0.3.0 // indirect
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
golang.org/x/text v0.12.0 // indirect
|
||||
|
||||
@@ -434,8 +434,8 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
|
||||
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/scroll-tech/go-ethereum v1.10.14-0.20230812030736-25fe3ba69a28 h1:CECBTWhZ5NGAn8lGFB4ooRAYxZns8PXoX8kTR/14c04=
|
||||
github.com/scroll-tech/go-ethereum v1.10.14-0.20230812030736-25fe3ba69a28/go.mod h1:DiN3p2inoXOxGffxSswDKqWjQ7bU+Mp0c9v0XQXKmaA=
|
||||
github.com/scroll-tech/go-ethereum v1.10.14-0.20230829000527-f883dcdc21fc h1:eK3NOpjgm/b2TQ6rYqWx92Zri0kBuxf6gKjjsVxWKr8=
|
||||
github.com/scroll-tech/go-ethereum v1.10.14-0.20230829000527-f883dcdc21fc/go.mod h1:DiN3p2inoXOxGffxSswDKqWjQ7bU+Mp0c9v0XQXKmaA=
|
||||
github.com/scroll-tech/zktrie v0.6.0 h1:xLrMAO31Yo2BiPg1jtYKzcjpEFnXy8acbB7iIsyshPs=
|
||||
github.com/scroll-tech/zktrie v0.6.0/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=
|
||||
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
|
||||
@@ -576,8 +576,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
|
||||
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
|
||||
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
|
||||
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::utils::{c_char_to_str, c_char_to_vec, string_to_c_char, vec_to_c_char, OUTPUT_DIR};
|
||||
use crate::{
|
||||
types::{CheckChunkProofsResponse, ProofResult},
|
||||
utils::{c_char_to_str, c_char_to_vec, string_to_c_char, vec_to_c_char, OUTPUT_DIR},
|
||||
};
|
||||
use libc::c_char;
|
||||
use prover::{
|
||||
aggregator::{Prover, Verifier},
|
||||
@@ -54,13 +57,35 @@ pub unsafe extern "C" fn get_batch_vk() -> *const c_char {
|
||||
|
||||
/// # Safety
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn check_chunk_proofs(chunk_proofs: *const c_char) -> c_char {
|
||||
let chunk_proofs = c_char_to_vec(chunk_proofs);
|
||||
let chunk_proofs = serde_json::from_slice::<Vec<ChunkProof>>(&chunk_proofs).unwrap();
|
||||
assert!(!chunk_proofs.is_empty());
|
||||
pub unsafe extern "C" fn check_chunk_proofs(chunk_proofs: *const c_char) -> *const c_char {
|
||||
let check_result: Result<bool, String> = panic::catch_unwind(|| {
|
||||
let chunk_proofs = c_char_to_vec(chunk_proofs);
|
||||
let chunk_proofs = serde_json::from_slice::<Vec<ChunkProof>>(&chunk_proofs)
|
||||
.map_err(|e| format!("failed to deserialize chunk proofs: {e:?}"))?;
|
||||
|
||||
let valid = panic::catch_unwind(|| PROVER.get().unwrap().check_chunk_proofs(&chunk_proofs));
|
||||
valid.unwrap_or(false) as c_char
|
||||
if chunk_proofs.is_empty() {
|
||||
return Err("provided chunk proofs are empty.".to_string());
|
||||
}
|
||||
|
||||
let prover_ref = PROVER.get().expect("failed to get reference to PROVER.");
|
||||
|
||||
let valid = prover_ref.check_chunk_proofs(&chunk_proofs);
|
||||
Ok(valid)
|
||||
})
|
||||
.unwrap_or_else(|e| Err(format!("unwind error: {e:?}")));
|
||||
|
||||
let r = match check_result {
|
||||
Ok(valid) => CheckChunkProofsResponse {
|
||||
ok: valid,
|
||||
error: None,
|
||||
},
|
||||
Err(err) => CheckChunkProofsResponse {
|
||||
ok: false,
|
||||
error: Some(err),
|
||||
},
|
||||
};
|
||||
|
||||
serde_json::to_vec(&r).map_or(null(), vec_to_c_char)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
@@ -69,28 +94,47 @@ pub unsafe extern "C" fn gen_batch_proof(
|
||||
chunk_hashes: *const c_char,
|
||||
chunk_proofs: *const c_char,
|
||||
) -> *const c_char {
|
||||
let chunk_hashes = c_char_to_vec(chunk_hashes);
|
||||
let chunk_proofs = c_char_to_vec(chunk_proofs);
|
||||
let proof_result: Result<Vec<u8>, String> = panic::catch_unwind(|| {
|
||||
let chunk_hashes = c_char_to_vec(chunk_hashes);
|
||||
let chunk_proofs = c_char_to_vec(chunk_proofs);
|
||||
|
||||
let chunk_hashes = serde_json::from_slice::<Vec<ChunkHash>>(&chunk_hashes).unwrap();
|
||||
let chunk_proofs = serde_json::from_slice::<Vec<ChunkProof>>(&chunk_proofs).unwrap();
|
||||
assert_eq!(chunk_hashes.len(), chunk_proofs.len());
|
||||
let chunk_hashes = serde_json::from_slice::<Vec<ChunkHash>>(&chunk_hashes)
|
||||
.map_err(|e| format!("failed to deserialize chunk hashes: {e:?}"))?;
|
||||
let chunk_proofs = serde_json::from_slice::<Vec<ChunkProof>>(&chunk_proofs)
|
||||
.map_err(|e| format!("failed to deserialize chunk proofs: {e:?}"))?;
|
||||
|
||||
let chunk_hashes_proofs = chunk_hashes
|
||||
.into_iter()
|
||||
.zip(chunk_proofs.into_iter())
|
||||
.collect();
|
||||
if chunk_hashes.len() != chunk_proofs.len() {
|
||||
return Err(format!("chunk hashes and chunk proofs lengths mismatch: chunk_hashes.len() = {}, chunk_proofs.len() = {}",
|
||||
chunk_hashes.len(), chunk_proofs.len()));
|
||||
}
|
||||
|
||||
let chunk_hashes_proofs = chunk_hashes
|
||||
.into_iter()
|
||||
.zip(chunk_proofs.into_iter())
|
||||
.collect();
|
||||
|
||||
let proof_result = panic::catch_unwind(|| {
|
||||
let proof = PROVER
|
||||
.get_mut()
|
||||
.unwrap()
|
||||
.expect("failed to get mutable reference to PROVER.")
|
||||
.gen_agg_evm_proof(chunk_hashes_proofs, None, OUTPUT_DIR.as_deref())
|
||||
.unwrap();
|
||||
.map_err(|e| format!("failed to generate proof: {e:?}"))?;
|
||||
|
||||
serde_json::to_vec(&proof).unwrap()
|
||||
});
|
||||
proof_result.map_or(null(), vec_to_c_char)
|
||||
serde_json::to_vec(&proof).map_err(|e| format!("failed to serialize the proof: {e:?}"))
|
||||
})
|
||||
.unwrap_or_else(|e| Err(format!("unwind error: {e:?}")));
|
||||
|
||||
let r = match proof_result {
|
||||
Ok(proof_bytes) => ProofResult {
|
||||
message: Some(proof_bytes),
|
||||
error: None,
|
||||
},
|
||||
Err(err) => ProofResult {
|
||||
message: None,
|
||||
error: Some(err),
|
||||
},
|
||||
};
|
||||
|
||||
serde_json::to_vec(&r).map_or(null(), vec_to_c_char)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::utils::{c_char_to_str, c_char_to_vec, string_to_c_char, vec_to_c_char, OUTPUT_DIR};
|
||||
use crate::{
|
||||
types::ProofResult,
|
||||
utils::{c_char_to_str, c_char_to_vec, string_to_c_char, vec_to_c_char, OUTPUT_DIR},
|
||||
};
|
||||
use libc::c_char;
|
||||
use prover::{
|
||||
utils::init_env_and_log,
|
||||
@@ -55,20 +58,33 @@ pub unsafe extern "C" fn get_chunk_vk() -> *const c_char {
|
||||
/// # Safety
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn gen_chunk_proof(block_traces: *const c_char) -> *const c_char {
|
||||
let block_traces = c_char_to_vec(block_traces);
|
||||
let block_traces = serde_json::from_slice::<Vec<BlockTrace>>(&block_traces).unwrap();
|
||||
let proof_result: Result<Vec<u8>, String> = panic::catch_unwind(|| {
|
||||
let block_traces = c_char_to_vec(block_traces);
|
||||
let block_traces = serde_json::from_slice::<Vec<BlockTrace>>(&block_traces)
|
||||
.map_err(|e| format!("failed to deserialize block traces: {e:?}"))?;
|
||||
|
||||
let proof_result = panic::catch_unwind(|| {
|
||||
let proof = PROVER
|
||||
.get_mut()
|
||||
.unwrap()
|
||||
.expect("failed to get mutable reference to PROVER.")
|
||||
.gen_chunk_proof(block_traces, None, OUTPUT_DIR.as_deref())
|
||||
.unwrap();
|
||||
.map_err(|e| format!("failed to generate proof: {e:?}"))?;
|
||||
|
||||
serde_json::to_vec(&proof).unwrap()
|
||||
});
|
||||
serde_json::to_vec(&proof).map_err(|e| format!("failed to serialize the proof: {e:?}"))
|
||||
})
|
||||
.unwrap_or_else(|e| Err(format!("unwind error: {e:?}")));
|
||||
|
||||
proof_result.map_or(null(), vec_to_c_char)
|
||||
let r = match proof_result {
|
||||
Ok(proof_bytes) => ProofResult {
|
||||
message: Some(proof_bytes),
|
||||
error: None,
|
||||
},
|
||||
Err(err) => ProofResult {
|
||||
message: None,
|
||||
error: Some(err),
|
||||
},
|
||||
};
|
||||
|
||||
serde_json::to_vec(&r).map_or(null(), vec_to_c_char)
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
|
||||
mod batch;
|
||||
mod chunk;
|
||||
mod types;
|
||||
mod utils;
|
||||
|
||||
22
common/libzkp/impl/src/types.rs
Normal file
22
common/libzkp/impl/src/types.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// Represents the result of a chunk proof checking operation.
|
||||
// `ok` indicates whether the proof checking was successful.
|
||||
// `error` provides additional details in case the check failed.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct CheckChunkProofsResponse {
|
||||
pub ok: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
// Encapsulates the result from generating a proof.
|
||||
// `message` holds the generated proof in byte slice format.
|
||||
// `error` provides additional details in case the proof generation failed.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct ProofResult {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub message: Option<Vec<u8>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error: Option<String>,
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
void init_batch_prover(char* params_dir, char* assets_dir);
|
||||
void init_batch_verifier(char* params_dir, char* assets_dir);
|
||||
char* get_batch_vk();
|
||||
char check_chunk_proofs(char* chunk_proofs);
|
||||
char* check_chunk_proofs(char* chunk_proofs);
|
||||
char* gen_batch_proof(char* chunk_hashes, char* chunk_proofs);
|
||||
char verify_batch_proof(char* proof);
|
||||
|
||||
|
||||
@@ -10,6 +10,16 @@ import (
|
||||
"github.com/scroll-tech/go-ethereum/crypto"
|
||||
)
|
||||
|
||||
// BatchMeta contains metadata of a batch.
|
||||
type BatchMeta struct {
|
||||
StartChunkIndex uint64
|
||||
StartChunkHash string
|
||||
EndChunkIndex uint64
|
||||
EndChunkHash string
|
||||
TotalL1CommitGas uint64
|
||||
TotalL1CommitCalldataSize uint32
|
||||
}
|
||||
|
||||
// BatchHeader contains batch header info to be committed.
|
||||
type BatchHeader struct {
|
||||
// Encoded in BatchHeaderV0Codec
|
||||
|
||||
@@ -98,9 +98,10 @@ func (w *WrappedBlock) EstimateL1CommitCalldataSize() uint64 {
|
||||
if txData.Type == types.L1MessageTxType {
|
||||
continue
|
||||
}
|
||||
size += 64 // 60 bytes BlockContext + 4 bytes payload length
|
||||
size += 4 // 4 bytes payload length
|
||||
size += w.getTxPayloadLength(txData)
|
||||
}
|
||||
size += 60 // 60 bytes BlockContext
|
||||
return size
|
||||
}
|
||||
|
||||
@@ -116,10 +117,13 @@ func (w *WrappedBlock) EstimateL1CommitGas() uint64 {
|
||||
|
||||
txPayloadLength := w.getTxPayloadLength(txData)
|
||||
total += CalldataNonZeroByteGas * txPayloadLength // an over-estimate: treat each byte as non-zero
|
||||
total += CalldataNonZeroByteGas * 64 // 60 bytes BlockContext + 4 bytes payload length
|
||||
total += CalldataNonZeroByteGas * 4 // 4 bytes payload length
|
||||
total += GetKeccak256Gas(txPayloadLength) // l2 tx hash
|
||||
}
|
||||
|
||||
// 60 bytes BlockContext calldata
|
||||
total += CalldataNonZeroByteGas * 60
|
||||
|
||||
// sload
|
||||
total += 2100 * numL1Messages // numL1Messages times cold sload in L1MessageQueue
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestChunkEncode(t *testing.T) {
|
||||
wrappedBlock := &WrappedBlock{}
|
||||
assert.NoError(t, json.Unmarshal(templateBlockTrace, wrappedBlock))
|
||||
assert.Equal(t, uint64(0), wrappedBlock.NumL1Messages(0))
|
||||
assert.Equal(t, uint64(358), wrappedBlock.EstimateL1CommitCalldataSize())
|
||||
assert.Equal(t, uint64(298), wrappedBlock.EstimateL1CommitCalldataSize())
|
||||
assert.Equal(t, uint64(2), wrappedBlock.NumL2Transactions())
|
||||
chunk = &Chunk{
|
||||
Blocks: []*WrappedBlock{
|
||||
@@ -46,7 +46,7 @@ func TestChunkEncode(t *testing.T) {
|
||||
},
|
||||
}
|
||||
assert.Equal(t, uint64(0), chunk.NumL1Messages(0))
|
||||
assert.Equal(t, uint64(6966), chunk.EstimateL1CommitGas())
|
||||
assert.Equal(t, uint64(6006), chunk.EstimateL1CommitGas())
|
||||
bytes, err = chunk.Encode(0)
|
||||
hexString := hex.EncodeToString(bytes)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -103,6 +103,12 @@ const (
|
||||
ProverTaskFailureTypeUndefined ProverTaskFailureType = iota
|
||||
// ProverTaskFailureTypeTimeout prover task failure of timeout
|
||||
ProverTaskFailureTypeTimeout
|
||||
// ProverTaskFailureTypeSubmitStatusNotOk prover task failure of validated failed by coordinator
|
||||
ProverTaskFailureTypeSubmitStatusNotOk
|
||||
// ProverTaskFailureTypeVerifiedFailed prover task failure of verified failed by coordinator
|
||||
ProverTaskFailureTypeVerifiedFailed
|
||||
// ProverTaskFailureTypeServerError collect occur error
|
||||
ProverTaskFailureTypeServerError
|
||||
)
|
||||
|
||||
func (r ProverTaskFailureType) String() string {
|
||||
@@ -111,8 +117,14 @@ func (r ProverTaskFailureType) String() string {
|
||||
return "prover task failure undefined"
|
||||
case ProverTaskFailureTypeTimeout:
|
||||
return "prover task failure timeout"
|
||||
case ProverTaskFailureTypeSubmitStatusNotOk:
|
||||
return "prover task failure validated submit proof status not ok"
|
||||
case ProverTaskFailureTypeVerifiedFailed:
|
||||
return "prover task failure verified failed"
|
||||
case ProverTaskFailureTypeServerError:
|
||||
return "prover task failure server exception"
|
||||
default:
|
||||
return "illegal prover task failure type"
|
||||
return fmt.Sprintf("illegal prover task failure type (%d)", int32(r))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
27
common/utils/http.go
Normal file
27
common/utils/http.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// StartHTTPServer a public http server to be used.
|
||||
func StartHTTPServer(address string, handler http.Handler) (*http.Server, error) {
|
||||
srv := &http.Server{
|
||||
Handler: handler,
|
||||
Addr: address,
|
||||
ReadTimeout: time.Second * 3,
|
||||
WriteTimeout: time.Second * 3,
|
||||
IdleTimeout: time.Second * 12,
|
||||
}
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
errCh <- srv.ListenAndServe()
|
||||
}()
|
||||
select {
|
||||
case err := <-errCh:
|
||||
return nil, err
|
||||
case <-time.After(time.Second):
|
||||
}
|
||||
return srv, nil
|
||||
}
|
||||
@@ -2,6 +2,9 @@ package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"github.com/modern-go/reflect2"
|
||||
@@ -50,3 +53,9 @@ func Loop(ctx context.Context, period time.Duration, f func()) {
|
||||
func IsNil(i interface{}) bool {
|
||||
return i == nil || reflect2.IsNil(i)
|
||||
}
|
||||
|
||||
// RandomURL return a random port endpoint.
|
||||
func RandomURL() string {
|
||||
id, _ := rand.Int(rand.Reader, big.NewInt(5000-1))
|
||||
return fmt.Sprintf("localhost:%d", 10000+2000+id.Int64())
|
||||
}
|
||||
|
||||
55
common/version/prover_version.go
Normal file
55
common/version/prover_version.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CheckScrollProverVersion check the "scroll-prover" version, if it's different from the local one, return false
|
||||
func CheckScrollProverVersion(proverVersion string) bool {
|
||||
// note the the version is in fact in the format of "tag-commit-scroll_prover-halo2",
|
||||
// so split-by-'-' length should be 4
|
||||
remote := strings.Split(proverVersion, "-")
|
||||
if len(remote) != 4 {
|
||||
return false
|
||||
}
|
||||
local := strings.Split(Version, "-")
|
||||
if len(local) != 4 {
|
||||
return false
|
||||
}
|
||||
// compare the `scroll_prover` version
|
||||
return remote[2] == local[2]
|
||||
}
|
||||
|
||||
// CheckScrollProverVersionTag check the "scroll-prover" version's tag, if it's too old, return false
|
||||
func CheckScrollProverVersionTag(proverVersion string) bool {
|
||||
// note the the version is in fact in the format of "tag-commit-scroll_prover-halo2",
|
||||
// so split-by-'-' length should be 4
|
||||
remote := strings.Split(proverVersion, "-")
|
||||
if len(remote) != 4 {
|
||||
return false
|
||||
}
|
||||
remoteTagNums := strings.Split(strings.TrimPrefix(remote[0], "v"), ".")
|
||||
if len(remoteTagNums) != 3 {
|
||||
return false
|
||||
}
|
||||
remoteTagMajor, err := strconv.Atoi(remoteTagNums[0])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
remoteTagMinor, err := strconv.Atoi(remoteTagNums[1])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
remoteTagPatch, err := strconv.Atoi(remoteTagNums[2])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if remoteTagMajor < 4 {
|
||||
return false
|
||||
}
|
||||
if remoteTagMinor == 1 && remoteTagPatch < 98 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -3,11 +3,9 @@ package version
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var tag = "v4.2.0"
|
||||
var tag = "v4.2.23"
|
||||
|
||||
var commit = func() string {
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
@@ -31,55 +29,3 @@ var ZkVersion = "000000-000000"
|
||||
|
||||
// Version denote the version of scroll protocol, including the l2geth, relayer, coordinator, prover, contracts and etc.
|
||||
var Version = fmt.Sprintf("%s-%s-%s", tag, commit, ZkVersion)
|
||||
|
||||
// CheckScrollProverVersion check the "scroll-prover" version, if it's different from the local one, return false
|
||||
func CheckScrollProverVersion(proverVersion string) bool {
|
||||
// note the the version is in fact in the format of "tag-commit-scroll_prover-halo2",
|
||||
// so split-by-'-' length should be 4
|
||||
remote := strings.Split(proverVersion, "-")
|
||||
if len(remote) != 4 {
|
||||
return false
|
||||
}
|
||||
local := strings.Split(Version, "-")
|
||||
if len(local) != 4 {
|
||||
return false
|
||||
}
|
||||
// compare the `scroll_prover` version
|
||||
return remote[2] == local[2]
|
||||
}
|
||||
|
||||
// CheckScrollProverVersionTag check the "scroll-prover" version's tag, if it's too old, return false
|
||||
func CheckScrollProverVersionTag(proverVersion string) bool {
|
||||
// note the the version is in fact in the format of "tag-commit-scroll_prover-halo2",
|
||||
// so split-by-'-' length should be 4
|
||||
remote := strings.Split(proverVersion, "-")
|
||||
if len(remote) != 4 {
|
||||
return false
|
||||
}
|
||||
remoteTagNums := strings.Split(strings.TrimPrefix(remote[0], "v"), ".")
|
||||
if len(remoteTagNums) != 3 {
|
||||
return false
|
||||
}
|
||||
remoteTagMajor, err := strconv.Atoi(remoteTagNums[0])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
remoteTagMinor, err := strconv.Atoi(remoteTagNums[1])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
remoteTagPatch, err := strconv.Atoi(remoteTagNums[2])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if remoteTagMajor != 4 {
|
||||
return false
|
||||
}
|
||||
if remoteTagMinor != 1 {
|
||||
return false
|
||||
}
|
||||
if remoteTagPatch < 98 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
# Scroll Contracts
|
||||
|
||||
Note: For more comprehensive documentation, see [`./docs/`](./docs).
|
||||
This directory contains the solidity code for Scroll L1 bridge and rollup contracts and L2 bridge and pre-deployed contracts. The [`specs`](../specs/) folder describes the overall Scroll protocol including the cross-domain messaging and rollup process. You can also find contract APIs and more details in the [`docs`](./docs) folder.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
integration-test
|
||||
|- xxx.test.ts - "Hardhat integration tests"
|
||||
lib
|
||||
|- forge-std - "foundry dependency"
|
||||
scripts
|
||||
|- deploy_xxx.ts - "hardhat deploy script"
|
||||
|- foundry - "foundry deploy scripts"
|
||||
src
|
||||
|- test
|
||||
| `- xxx.t.sol - "Unit testi in solidity"
|
||||
`- xxx.sol - "solidity contract"
|
||||
.gitmodules - "foundry dependecy modules"
|
||||
foundry.toml - "configure foundry"
|
||||
hardhat.config.ts - "configure hardhat"
|
||||
remappings.txt - "foundry dependency mappings"
|
||||
<pre>
|
||||
├── <a href="./docs/">docs</a>: Documentation for the contracts
|
||||
├── <a href="./integration-test/">integration-test</a>: Hardhat integration tests
|
||||
├── <a href="./lib/">lib</a>: External libraries and testing tools
|
||||
├── <a href="./scripts">scripts</a>: Deployment scripts
|
||||
├── <a href="./src">src</a>
|
||||
│ ├── <a href="./src/gas-swap/">gas-swap</a>: Utility contract that allows gas payment in other tokens
|
||||
│ ├── <a href="./src/interfaces/">interfaces</a>: Common contract interfaces
|
||||
│ ├── <a href="./src/L1/">L1</a>: Contracts deployed on the L1 (Ethereum)
|
||||
│ │ ├── <a href="./src/L1/gateways/">gateways</a>: Gateway router and token gateway contracts
|
||||
│ │ ├── <a href="./src/L1/rollup/">rollup</a>: Rollup contracts for data availability and finalization
|
||||
│ │ ├── <a href="./src/L1/IL1ScrollMessenger.sol">IL1ScrollMessenger.sol</a>: L1 Scroll messenger interface
|
||||
│ │ └── <a href="./src/L1/L1ScrollMessenger.sol">L1ScrollMessenger.sol</a>: L1 Scroll messenger contract
|
||||
│ ├── <a href="./src/L2/">L2</a>: Contracts deployed on the L2 (Scroll)
|
||||
│ │ ├── <a href="./src/L2/gateways/">gateways</a>: Gateway router and token gateway contracts
|
||||
│ │ ├── <a href="./src/L2/predeploys/">predeploys</a>: Pre-deployed contracts on L2
|
||||
│ │ ├── <a href="./src/L2/IL2ScrollMessenger.sol">IL2ScrollMessenger.sol</a>: L2 Scroll messenger interface
|
||||
│ │ └── <a href="./src/L2/L2ScrollMessenger.sol">L2ScrollMessenger.sol</a>: L2 Scroll messenger contract
|
||||
│ ├── <a href="./src/libraries/">libraries</a>: Shared contract libraries
|
||||
│ ├── <a href="./src/misc/">misc</a>: Miscellaneous contracts
|
||||
│ ├── <a href="./src/mocks/">mocks</a>: Mock contracts used in the testing
|
||||
│ ├── <a href="./src/rate-limiter/">rate-limiter</a>: Rater limiter contract
|
||||
│ └── <a href="./src/test/">test</a>: Unit tests in solidity
|
||||
├── <a href="./foundry.toml">foundry.toml</a>: Foundry configuration
|
||||
├── <a href="./hardhat.config.ts">hardhat.config.ts</a>: Hardhat configuration
|
||||
├── <a href="./remappings.txt">remappings.txt</a>: Foundry dependency mappings
|
||||
...
|
||||
```
|
||||
</pre>
|
||||
|
||||
## Dependencies
|
||||
|
||||
### Node.js
|
||||
|
||||
First install [`Node.js`](https://nodejs.org/en) and [`npm`](https://www.npmjs.com/).
|
||||
Run the following command to install [`yarn`](https://classic.yarnpkg.com/en/):
|
||||
|
||||
```bash
|
||||
npm install --global yarn
|
||||
```
|
||||
|
||||
### Foundry
|
||||
|
||||
First run the command below to get foundryup, the Foundry toolchain installer:
|
||||
Install `foundryup`, the Foundry toolchain installer:
|
||||
|
||||
```bash
|
||||
curl -L https://foundry.paradigm.xyz | bash
|
||||
```
|
||||
|
||||
If you do not want to use the redirect, feel free to manually download the foundryup installation script from [here](https://raw.githubusercontent.com/foundry-rs/foundry/master/foundryup/foundryup).
|
||||
If you do not want to use the redirect, feel free to manually download the `foundryup` installation script from [here](https://raw.githubusercontent.com/foundry-rs/foundry/master/foundryup/foundryup).
|
||||
|
||||
Then, run `foundryup` in a new terminal session or after reloading your `PATH`.
|
||||
Then, run `foundryup` in a new terminal session or after reloading `PATH`.
|
||||
|
||||
Other ways to install Foundry can be found [here](https://github.com/foundry-rs/foundry#installation).
|
||||
|
||||
### Hardhat
|
||||
|
||||
Run the following command to install [Hardhat](https://hardhat.org/) and other dependencies.
|
||||
|
||||
```
|
||||
yarn install
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
- Run `git submodule update --init --recursive` to initialise git submodules.
|
||||
- Run `git submodule update --init --recursive` to initialize git submodules.
|
||||
- Run `yarn prettier:solidity` to run linting in fix mode, will auto-format all solidity codes.
|
||||
- Run `yarn prettier` to run linting in fix mode, will auto-format all typescript codes.
|
||||
- Run `yarn prepare` to install the precommit linting hook
|
||||
- Run `yarn prepare` to install the precommit linting hook.
|
||||
- Run `forge build` to compile contracts with foundry.
|
||||
- Run `npx hardhat compile` to compile with hardhat.
|
||||
- Run `forge test -vvv` to run foundry units tests. It will compile all contracts before running the unit tests.
|
||||
- Run `npx hardhat test` to run integration tests. It may not compile all contracts before running, it's better to run `npx hardhat compile` first.
|
||||
|
||||
## TODO
|
||||
|
||||
- [ ] unit tests
|
||||
- [ ] L1 Messenger
|
||||
- [x] L1 Gateways
|
||||
- [x] L1 Gateway Router
|
||||
- [ ] L2 Messenger
|
||||
- [x] L2 Gateways
|
||||
- [x] L2 Gateway Router
|
||||
- [x] ScrollStandardERC20Factory
|
||||
- [x] Whitelist
|
||||
- [ ] SimpleGasOracle
|
||||
- [ ] integration tests
|
||||
- [x] ERC20Gateway
|
||||
- [x] GatewayRouter
|
||||
- [ ] ZKRollup contracts
|
||||
- [x] Gas Oracle contracts for cross chain message call
|
||||
- [ ] ERC721/ERC115 interface design
|
||||
- [ ] add proof verification codes
|
||||
- [ ] security analysis
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
# Cross Domain Messaging
|
||||
|
||||
Like other layer 2 protocol, Scroll allow dapps to communicate between layer 1 and layer 2. More specifically, dapps on layer 1 can trigger contract functions in layer 2, and vice versa.
|
||||
|
||||
## Message Between L1 and L2
|
||||
|
||||
The Scroll protocol implements two core contracts `L1ScrollMessenger` and `L2ScrollMessenger` to enable cross domain messaging. The only entry to send cross domain message is to call the following function:
|
||||
|
||||
```solidity
|
||||
function sendMessage(
|
||||
address _to,
|
||||
bytes memory _message,
|
||||
uint256 _gasLimit
|
||||
) external payable
|
||||
```
|
||||
|
||||
The function is attached in both messenger in layer 1 and layer 2. After that, the Sequencer will handle the rest part for you. We will explain the detailed workflow in the following docs.
|
||||
|
||||
### Send Message from L1 to L2
|
||||
|
||||
As described above, the first step is to call `L1ScrollMessenger.sendMessage` in layer 1. The `L1ScrollMessenger` contract will emit a `SentMessage` event, which will be notified by the Sequencer. The Sequencer will for the confirmation of the function call in layer 1. Normally, the Sequencer will wait for 10-20 blocks. After that, the Sequencer will initiate a transaction in layer 2, calling function `L2ScrollMessenger.relayMessage` and finally, the message is executed in layer 2.
|
||||
|
||||
The execution in layer 2 may be failed due to out of gas problem. In such case, one can call `L1ScrollMessenger.replayMessage` to replace the message with a larger gas limit. And the Sequencer will follow the steps and execute the message again in layer 2.
|
||||
|
||||
### Send Message from L2 to L1
|
||||
|
||||
Similar to sending message from L1 to L2, you should call `L2ScrollMessenger.sendMessage` first in layer 2. The `L2ScrollMessenger` contract will emit a `SentMessage` event, which will be notified by the Sequencer. Unlike above, the Sequencer will first batch submit layer 2 transactions (or block) to `ZKRollup` contract in layer 1. Then the Sequencer will wait the proof generated by prover and submit the proof to `ZKRollup` contract in layer 1 again. Finally, anyone can call `L1ScrollMessenger.relayMessageWithProof` with correct proof to execute the message in layer 1.
|
||||
|
||||
Currently, for the safety reason, we only allow privileged contracts to send cross domain messages. And only privileged accounts can call `L2ScrollMessenger.relayMessage`.
|
||||
|
||||
## Fee For Sending Message
|
||||
|
||||
to be discussed.
|
||||
@@ -1,22 +0,0 @@
|
||||
# Overview
|
||||
|
||||

|
||||
|
||||
The above picture is the overview of the contract design. There are several components both in layer 1 and layer 2: L1/L2 Scroll Messenger, various L1/L2 Gateways and L1/L2 Gateway Router. Besides these, there is a Rollup component only in layer 1.
|
||||
|
||||
The followings are the detailed docs for each component (docs are generated automatically by `@primitivefi/hardhat-dodoc` plugin):
|
||||
|
||||
- [L1 Scroll Messenger](./apis/L1ScrollMessenger.md) and [L2 Scroll Messenger](./apis/L2ScrollMessenger.md): Main entry for sending and relaying cross domain message.
|
||||
- [Rollup](./apis/ZKRollup.md)
|
||||
- [L1 Gateway Router](./apis/L1GatewayRouter.md) and [L2 Gateway Router](./apis/L2GatewayRouter.md): Router contract for depositing/withdrawing Ethers and ERC20 tokens.
|
||||
- L1/L2 Gateways:
|
||||
- [L1 Standard ERC20 Gateway](./apis/L1StandardERC20Gateway.md) and [L2 Standard ERC20 Gateway](./apis/L2StandardERC20Gateway.md)
|
||||
- [L1 WETH Gateway](./apis/L1WETHGateway.md) and [L2 WETH Gateway](./apis/L2WETHGateway.md)
|
||||
- [L1 ERC721 Gateway](./apis/L1ERC721Gateway.md) and [L2 ERC721 Gateway](./apis/L2ERC721Gateway.md)
|
||||
- [L1 ERC1155 Gateway](./apis/L1ERC1155Gateway.md) and [L2 ERC1155 Gateway](./apis/L2ERC1155Gateway.md)
|
||||
- [ScrollStandardERC20Factory](./apis/ScrollStandardERC20Factory.md): The `ScrollStandardERC20` token factory used by `L2StandardERC20Gateway`.
|
||||
|
||||
There are two main applications: Token Bridge and Cross Domain Messaging. You can find the documentations in the links below:
|
||||
|
||||
- [Token Bridge](./TokenBridge.md): moving token from layer 1 to layer 2, or from layer 2 to layer 1.
|
||||
- [Cross Domain Messaging](./CrossDomainMessaging.md): sending data to layer 2 from layer 1, or sending data to layer 2 from layer 1. Basically, it will help to trigger function call cross layer. The token bridge also use cross domain messaging to achieve its functionality.
|
||||
@@ -1,134 +0,0 @@
|
||||
# Bridge Token Between Layer 1 and Layer 2
|
||||
|
||||
The Token Bridge of Scroll Protocol offers a way to move assets from layer 1 to layer 2 and back, including Ether, ERC20 token, ERC-721 token, ERC-1155 token, etc. The asset should be deposited and locked in layer 1 and then in exchange of the same amount of an equivalent token on layer 2. For example, if you deposit 1000 Ether in layer 1, you will get 1000 Ether in layer 2 for return. And if you withdraw 1000 Ether in layer 2, you will get 1000 Ether in layer 1 for return.
|
||||
|
||||
The Ether and ERC20 tokens can be deposited or withdrawn using one single contract `GatewayRouter` (`L1GatewayRouter` in layer 1 and `L2GatewayRouter` in layer 2). The ERC-721 tokens and ERC-1155 tokens can be deposited or withdrawn using the corresponding `ERC1155Gateway` and `ERC721Gateway` in layer 1 or layer 2 (They may be integrated into `GatewayRouter` in the future).
|
||||
|
||||
## Bridge Ether
|
||||
|
||||
To bridge Ether from layer 1 to layer 2, one can use `L1GatewayRouter.depositETH`. This will transfer ethers to the `L1ScrollMessenger` contract on the layer 1 and credits the same amount of ether to you in layer 2 at the specified address.
|
||||
|
||||
```solidity
|
||||
function depositETH(uint256 _gasLimit) external payable;
|
||||
|
||||
function depositETH(address _to, uint256 _gasLimit) external payable;
|
||||
|
||||
```
|
||||
|
||||
In the layer 1, all deposited Ether will be locked in `L1ScrollMessenger` contract. It means your deposited Ether will firstly be transfered to `L1GatewayRouter` contract and then to `L1ScrollMessenger` contract.
|
||||
|
||||
To withdraw Ether from layer 2 to layer 1, one can use `L2GatewayRouter.withdrawETH`.
|
||||
|
||||
```solidity
|
||||
function withdrawETH(uint256 _gasLimit) external payable;
|
||||
|
||||
function withdrawETH(address _to, uint256 _gasLimit) external payable;
|
||||
|
||||
```
|
||||
|
||||
In layer 2, the `L2ScrollMessenger` holds infinite amount of Ether at the beginning. All your withdrawn Ether will be transfered back to `L2ScrollMessenger`, just like the process in layer 1.
|
||||
|
||||
In addition, you can actually call `sendMessage` from the `L1ScrollMessenger` or `L2ScrollMessenger` contract to deposit or withdraw Ether. The `L1GatewayRouter.depositETH` and `L2GatewayRouter.withdrawETH` are just alias for `L1ScrollMessenger/L2ScrollMessenger.sendMessage`.
|
||||
|
||||
## Bridge ERC20 Tokens
|
||||
|
||||
We use the similar design as [Arbitrum protocol](https://developer.offchainlabs.com/docs/bridging_assets#bridging-erc20-tokens) do. Several gateway contracts are used to bridge different kinds of ERC20 tokens, such as Wrapped Ether, standard ERC20 tokens, etc.
|
||||
|
||||
We implement a `StandardERC20Gateway` to deposit and withdraw standard ERC20 tokens. The standard procedure to deposit ERC20 tokens is to call `L1GatewayRouter.depositERC20` in layer 1. The token will be locked in `L1StandardERC20Gateway` contract in layer 1. The the standard procedure to withdraw ERC20 tokens is to call `L2GatewayRouter.withdrawRC20` in layer 2 and the token will be burned in layer 2.
|
||||
|
||||
For many other non-standard ERC20 tokens, we provide a custom ERC20 gateway. Anyone can implement such gateway as long as it implements all required interfaces. We implement the Wrapped Ether gateway as an example. To deposit or withdraw Wrapped Ether, one should first unwrap it to Ether, then transfer the Ether to `ScrollMessenger` just like Ether bridging.
|
||||
|
||||
### Passing data when depositing ERC20 tokens
|
||||
|
||||
The Scroll protocol offer a way to call another contract after depositing the token in layer 2 by calling `L1GatewayRouter.depositERC20AndCall` in layer 1. The ERC20 token in layer 2 implements the [ERC 677 Standard](https://github.com/ethereum/EIPs/issues/677). By using `transferAndCall` function, we can transfer the token to corresponding recipient in layer 2 and then call the recipient with passed data.
|
||||
|
||||
```solidity
|
||||
function depositERC20AndCall(
|
||||
address _token,
|
||||
address _to,
|
||||
uint256 _amount,
|
||||
bytes memory _data,
|
||||
uint256 _gasLimit
|
||||
) external;
|
||||
|
||||
```
|
||||
|
||||
Like Bridging Ether, all above functionality can be achieved by calling corresponding function in ERC20Gateway contract.
|
||||
|
||||
## Bridge ERC-721/ERC-1155 Tokens
|
||||
|
||||
The depositing/withdrawing ERC-721 or ERC-1155 tokens works very similar to ERC20 tokens. One can use the following function to deposit ERC-721/ERC-1155 tokens in layer 1.
|
||||
|
||||
```solidity
|
||||
function depositERC1155(
|
||||
address _token,
|
||||
uint256 _tokenId,
|
||||
uint256 _amount,
|
||||
uint256 _gasLimit
|
||||
) external;
|
||||
|
||||
function depositERC1155(
|
||||
address _token,
|
||||
address _to,
|
||||
uint256 _tokenId,
|
||||
uint256 _amount,
|
||||
uint256 _gasLimit
|
||||
) external;
|
||||
|
||||
function depositERC721(
|
||||
address _token,
|
||||
uint256 _tokenId,
|
||||
uint256 _gasLimit
|
||||
) external;
|
||||
|
||||
function depositERC721(
|
||||
address _token,
|
||||
address _to,
|
||||
uint256 _tokenId,
|
||||
uint256 _gasLimit
|
||||
) external;
|
||||
|
||||
```
|
||||
|
||||
One can use the following function to withdraw ERC-721/ERC-1155 tokens in layer 2.
|
||||
|
||||
```solidity
|
||||
function withdrawERC1155(
|
||||
address _token,
|
||||
uint256 _tokenId,
|
||||
uint256 _amount,
|
||||
uint256 _gasLimit
|
||||
) external;
|
||||
|
||||
function withdrawERC1155(
|
||||
address _token,
|
||||
address _to,
|
||||
uint256 _tokenId,
|
||||
uint256 _amount,
|
||||
uint256 _gasLimit
|
||||
) external;
|
||||
|
||||
function withdrawERC721(
|
||||
address _token,
|
||||
uint256 _tokenId,
|
||||
uint256 _gasLimit
|
||||
) external;
|
||||
|
||||
function withdrawERC721(
|
||||
address _token,
|
||||
address _to,
|
||||
uint256 _tokenId,
|
||||
uint256 _gasLimit
|
||||
) external;
|
||||
|
||||
```
|
||||
|
||||
To save the gas usage, we also provide a batch deposit/withdraw function, such as `batchDepositERC1155` and `batchDepositERC721`, by passing a list of token ids to the function.
|
||||
|
||||
## Drop Depositing/Withdrawing
|
||||
|
||||
Coming soon...
|
||||
|
||||
## Force Exit
|
||||
|
||||
Coming soon...
|
||||
@@ -104,45 +104,6 @@ Mapping from L2 message hash to sent status.
|
||||
|---|---|---|
|
||||
| _0 | bool | undefined |
|
||||
|
||||
### l1MessageFailedTimes
|
||||
|
||||
```solidity
|
||||
function l1MessageFailedTimes(bytes32) external view returns (uint256)
|
||||
```
|
||||
|
||||
Mapping from L1 message hash to the number of failure times.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | bytes32 | undefined |
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | uint256 | undefined |
|
||||
|
||||
### maxFailedExecutionTimes
|
||||
|
||||
```solidity
|
||||
function maxFailedExecutionTimes() external view returns (uint256)
|
||||
```
|
||||
|
||||
The maximum number of times each L1 message can fail on L2.
|
||||
|
||||
|
||||
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | uint256 | undefined |
|
||||
|
||||
### messageQueue
|
||||
|
||||
```solidity
|
||||
@@ -329,22 +290,6 @@ Update fee vault contract.
|
||||
|---|---|---|
|
||||
| _newFeeVault | address | The address of new fee vault contract. |
|
||||
|
||||
### updateMaxFailedExecutionTimes
|
||||
|
||||
```solidity
|
||||
function updateMaxFailedExecutionTimes(uint256 _newMaxFailedExecutionTimes) external nonpayable
|
||||
```
|
||||
|
||||
Update max failed execution times.
|
||||
|
||||
*This function can only called by contract owner.*
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _newMaxFailedExecutionTimes | uint256 | The new max failed execution times. |
|
||||
|
||||
### updateRateLimiter
|
||||
|
||||
```solidity
|
||||
|
||||
571
contracts/docs/apis/ScrollChain.md
Normal file
571
contracts/docs/apis/ScrollChain.md
Normal file
@@ -0,0 +1,571 @@
|
||||
# ScrollChain
|
||||
|
||||
|
||||
|
||||
> ScrollChain
|
||||
|
||||
This contract maintains data for the Scroll rollup.
|
||||
|
||||
|
||||
|
||||
## Methods
|
||||
|
||||
### commitBatch
|
||||
|
||||
```solidity
|
||||
function commitBatch(uint8 _version, bytes _parentBatchHeader, bytes[] _chunks, bytes _skippedL1MessageBitmap) external nonpayable
|
||||
```
|
||||
|
||||
Commit a batch of transactions on layer 1.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _version | uint8 | undefined |
|
||||
| _parentBatchHeader | bytes | undefined |
|
||||
| _chunks | bytes[] | undefined |
|
||||
| _skippedL1MessageBitmap | bytes | undefined |
|
||||
|
||||
### committedBatches
|
||||
|
||||
```solidity
|
||||
function committedBatches(uint256) external view returns (bytes32)
|
||||
```
|
||||
|
||||
Return the batch hash of a committed batch.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | uint256 | undefined |
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | bytes32 | undefined |
|
||||
|
||||
### finalizeBatchWithProof
|
||||
|
||||
```solidity
|
||||
function finalizeBatchWithProof(bytes _batchHeader, bytes32 _prevStateRoot, bytes32 _postStateRoot, bytes32 _withdrawRoot, bytes _aggrProof) external nonpayable
|
||||
```
|
||||
|
||||
Finalize a committed batch on layer 1.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _batchHeader | bytes | undefined |
|
||||
| _prevStateRoot | bytes32 | undefined |
|
||||
| _postStateRoot | bytes32 | undefined |
|
||||
| _withdrawRoot | bytes32 | undefined |
|
||||
| _aggrProof | bytes | undefined |
|
||||
|
||||
### finalizedStateRoots
|
||||
|
||||
```solidity
|
||||
function finalizedStateRoots(uint256) external view returns (bytes32)
|
||||
```
|
||||
|
||||
Return the state root of a committed batch.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | uint256 | undefined |
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | bytes32 | undefined |
|
||||
|
||||
### importGenesisBatch
|
||||
|
||||
```solidity
|
||||
function importGenesisBatch(bytes _batchHeader, bytes32 _stateRoot) external nonpayable
|
||||
```
|
||||
|
||||
Import layer 2 genesis block
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _batchHeader | bytes | undefined |
|
||||
| _stateRoot | bytes32 | undefined |
|
||||
|
||||
### initialize
|
||||
|
||||
```solidity
|
||||
function initialize(address _messageQueue, address _verifier, uint256 _maxNumL2TxInChunk) external nonpayable
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _messageQueue | address | undefined |
|
||||
| _verifier | address | undefined |
|
||||
| _maxNumL2TxInChunk | uint256 | undefined |
|
||||
|
||||
### isBatchFinalized
|
||||
|
||||
```solidity
|
||||
function isBatchFinalized(uint256 _batchIndex) external view returns (bool)
|
||||
```
|
||||
|
||||
Return whether the batch is finalized by batch index.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _batchIndex | uint256 | undefined |
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | bool | undefined |
|
||||
|
||||
### isProver
|
||||
|
||||
```solidity
|
||||
function isProver(address) external view returns (bool)
|
||||
```
|
||||
|
||||
Whether an account is a prover.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | address | undefined |
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | bool | undefined |
|
||||
|
||||
### isSequencer
|
||||
|
||||
```solidity
|
||||
function isSequencer(address) external view returns (bool)
|
||||
```
|
||||
|
||||
Whether an account is a sequencer.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | address | undefined |
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | bool | undefined |
|
||||
|
||||
### lastFinalizedBatchIndex
|
||||
|
||||
```solidity
|
||||
function lastFinalizedBatchIndex() external view returns (uint256)
|
||||
```
|
||||
|
||||
The latest finalized batch index.
|
||||
|
||||
|
||||
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | uint256 | undefined |
|
||||
|
||||
### layer2ChainId
|
||||
|
||||
```solidity
|
||||
function layer2ChainId() external view returns (uint64)
|
||||
```
|
||||
|
||||
The chain id of the corresponding layer 2 chain.
|
||||
|
||||
|
||||
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | uint64 | undefined |
|
||||
|
||||
### maxNumL2TxInChunk
|
||||
|
||||
```solidity
|
||||
function maxNumL2TxInChunk() external view returns (uint256)
|
||||
```
|
||||
|
||||
The maximum number of transactions allowed in each chunk.
|
||||
|
||||
|
||||
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | uint256 | undefined |
|
||||
|
||||
### messageQueue
|
||||
|
||||
```solidity
|
||||
function messageQueue() external view returns (address)
|
||||
```
|
||||
|
||||
The address of L1MessageQueue.
|
||||
|
||||
|
||||
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | address | undefined |
|
||||
|
||||
### owner
|
||||
|
||||
```solidity
|
||||
function owner() external view returns (address)
|
||||
```
|
||||
|
||||
|
||||
|
||||
*Returns the address of the current owner.*
|
||||
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | address | undefined |
|
||||
|
||||
### renounceOwnership
|
||||
|
||||
```solidity
|
||||
function renounceOwnership() external nonpayable
|
||||
```
|
||||
|
||||
|
||||
|
||||
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
|
||||
|
||||
|
||||
### revertBatch
|
||||
|
||||
```solidity
|
||||
function revertBatch(bytes _batchHeader, uint256 _count) external nonpayable
|
||||
```
|
||||
|
||||
Revert a pending batch.
|
||||
|
||||
*one can only revert unfinalized batches.*
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _batchHeader | bytes | undefined |
|
||||
| _count | uint256 | undefined |
|
||||
|
||||
### transferOwnership
|
||||
|
||||
```solidity
|
||||
function transferOwnership(address newOwner) external nonpayable
|
||||
```
|
||||
|
||||
|
||||
|
||||
*Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.*
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| newOwner | address | undefined |
|
||||
|
||||
### updateMaxNumL2TxInChunk
|
||||
|
||||
```solidity
|
||||
function updateMaxNumL2TxInChunk(uint256 _maxNumL2TxInChunk) external nonpayable
|
||||
```
|
||||
|
||||
Update the value of `maxNumL2TxInChunk`.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _maxNumL2TxInChunk | uint256 | The new value of `maxNumL2TxInChunk`. |
|
||||
|
||||
### updateProver
|
||||
|
||||
```solidity
|
||||
function updateProver(address _account, bool _status) external nonpayable
|
||||
```
|
||||
|
||||
Update the status of prover.
|
||||
|
||||
*This function can only called by contract owner.*
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _account | address | The address of account to update. |
|
||||
| _status | bool | The status of the account to update. |
|
||||
|
||||
### updateSequencer
|
||||
|
||||
```solidity
|
||||
function updateSequencer(address _account, bool _status) external nonpayable
|
||||
```
|
||||
|
||||
Update the status of sequencer.
|
||||
|
||||
*This function can only called by contract owner.*
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _account | address | The address of account to update. |
|
||||
| _status | bool | The status of the account to update. |
|
||||
|
||||
### updateVerifier
|
||||
|
||||
```solidity
|
||||
function updateVerifier(address _newVerifier) external nonpayable
|
||||
```
|
||||
|
||||
Update the address verifier contract.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _newVerifier | address | The address of new verifier contract. |
|
||||
|
||||
### verifier
|
||||
|
||||
```solidity
|
||||
function verifier() external view returns (address)
|
||||
```
|
||||
|
||||
The address of RollupVerifier.
|
||||
|
||||
|
||||
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | address | undefined |
|
||||
|
||||
### withdrawRoots
|
||||
|
||||
```solidity
|
||||
function withdrawRoots(uint256) external view returns (bytes32)
|
||||
```
|
||||
|
||||
Return the message root of a committed batch.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | uint256 | undefined |
|
||||
|
||||
#### Returns
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| _0 | bytes32 | undefined |
|
||||
|
||||
|
||||
|
||||
## Events
|
||||
|
||||
### CommitBatch
|
||||
|
||||
```solidity
|
||||
event CommitBatch(bytes32 indexed batchHash)
|
||||
```
|
||||
|
||||
Emitted when a new batch is committed.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| batchHash `indexed` | bytes32 | undefined |
|
||||
|
||||
### FinalizeBatch
|
||||
|
||||
```solidity
|
||||
event FinalizeBatch(bytes32 indexed batchHash, bytes32 stateRoot, bytes32 withdrawRoot)
|
||||
```
|
||||
|
||||
Emitted when a batch is finalized.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| batchHash `indexed` | bytes32 | undefined |
|
||||
| stateRoot | bytes32 | undefined |
|
||||
| withdrawRoot | bytes32 | undefined |
|
||||
|
||||
### OwnershipTransferred
|
||||
|
||||
```solidity
|
||||
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| previousOwner `indexed` | address | undefined |
|
||||
| newOwner `indexed` | address | undefined |
|
||||
|
||||
### RevertBatch
|
||||
|
||||
```solidity
|
||||
event RevertBatch(bytes32 indexed batchHash)
|
||||
```
|
||||
|
||||
revert a pending batch.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| batchHash `indexed` | bytes32 | undefined |
|
||||
|
||||
### UpdateMaxNumL2TxInChunk
|
||||
|
||||
```solidity
|
||||
event UpdateMaxNumL2TxInChunk(uint256 oldMaxNumL2TxInChunk, uint256 newMaxNumL2TxInChunk)
|
||||
```
|
||||
|
||||
Emitted when the value of `maxNumL2TxInChunk` is updated.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| oldMaxNumL2TxInChunk | uint256 | The old value of `maxNumL2TxInChunk`. |
|
||||
| newMaxNumL2TxInChunk | uint256 | The new value of `maxNumL2TxInChunk`. |
|
||||
|
||||
### UpdateProver
|
||||
|
||||
```solidity
|
||||
event UpdateProver(address indexed account, bool status)
|
||||
```
|
||||
|
||||
Emitted when owner updates the status of prover.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| account `indexed` | address | The address of account updated. |
|
||||
| status | bool | The status of the account updated. |
|
||||
|
||||
### UpdateSequencer
|
||||
|
||||
```solidity
|
||||
event UpdateSequencer(address indexed account, bool status)
|
||||
```
|
||||
|
||||
Emitted when owner updates the status of sequencer.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| account `indexed` | address | The address of account updated. |
|
||||
| status | bool | The status of the account updated. |
|
||||
|
||||
### UpdateVerifier
|
||||
|
||||
```solidity
|
||||
event UpdateVerifier(address oldVerifier, address newVerifier)
|
||||
```
|
||||
|
||||
Emitted when the address of rollup verifier is updated.
|
||||
|
||||
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
|---|---|---|
|
||||
| oldVerifier | address | The address of old rollup verifier. |
|
||||
| newVerifier | address | The address of new rollup verifier. |
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 684 KiB |
@@ -84,11 +84,14 @@ const config: HardhatUserConfig = {
|
||||
etherscan: {
|
||||
apiKey: process.env.ETHERSCAN_API_KEY,
|
||||
},
|
||||
mocha: {
|
||||
timeout: 10000000,
|
||||
},
|
||||
dodoc: {
|
||||
runOnCompile: true,
|
||||
keepFileStructure: false,
|
||||
include: [
|
||||
"ZKRollup",
|
||||
"ScrollChain",
|
||||
"L1ScrollMessenger",
|
||||
"L2ScrollMessenger",
|
||||
"L1GatewayRouter",
|
||||
@@ -115,8 +118,9 @@ const config: HardhatUserConfig = {
|
||||
"IL1ERC1155Gateway",
|
||||
"IL2ERC1155Gateway",
|
||||
"IScrollStandardERC20Factory",
|
||||
"IZKRollup",
|
||||
"WrappedEther",
|
||||
"IScrollChain",
|
||||
"ScrollChainCommitmentVerifier",
|
||||
"WETH9",
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable node/no-unpublished-import */
|
||||
/* eslint-disable node/no-missing-import */
|
||||
import { ethers } from "hardhat";
|
||||
import { GasSwap, MinimalForwarder, MockERC20, MockGasSwapTarget } from "../typechain";
|
||||
import { GasSwap, ERC2771Forwarder, MockERC20, MockGasSwapTarget } from "../typechain";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { expect } from "chai";
|
||||
import { BigNumber, constants } from "ethers";
|
||||
@@ -11,7 +11,7 @@ describe("GasSwap.spec", async () => {
|
||||
let deployer: SignerWithAddress;
|
||||
let signer: SignerWithAddress;
|
||||
|
||||
let forwarder: MinimalForwarder;
|
||||
let forwarder: ERC2771Forwarder;
|
||||
let swap: GasSwap;
|
||||
let target: MockGasSwapTarget;
|
||||
let token: MockERC20;
|
||||
@@ -19,8 +19,8 @@ describe("GasSwap.spec", async () => {
|
||||
beforeEach(async () => {
|
||||
[deployer, signer] = await ethers.getSigners();
|
||||
|
||||
const MinimalForwarder = await ethers.getContractFactory("MinimalForwarder", deployer);
|
||||
forwarder = await MinimalForwarder.deploy();
|
||||
const ERC2771Forwarder = await ethers.getContractFactory("ERC2771Forwarder", deployer);
|
||||
forwarder = await ERC2771Forwarder.deploy("ERC2771Forwarder");
|
||||
await forwarder.deployed();
|
||||
|
||||
const GasSwap = await ethers.getContractFactory("GasSwap", deployer);
|
||||
@@ -253,12 +253,13 @@ describe("GasSwap.spec", async () => {
|
||||
await swap.updateFeeRatio(ethers.utils.parseEther(feeRatio).div(100));
|
||||
const fee = amountOut.mul(feeRatio).div(100);
|
||||
|
||||
const req = {
|
||||
const reqWithoutSignature = {
|
||||
from: signer.address,
|
||||
to: swap.address,
|
||||
value: constants.Zero,
|
||||
gas: 1000000,
|
||||
nonce: 0,
|
||||
nonce: await forwarder.nonces(signer.address),
|
||||
deadline: 2000000000,
|
||||
data: swap.interface.encodeFunctionData("swap", [
|
||||
{
|
||||
token: token.address,
|
||||
@@ -278,8 +279,8 @@ describe("GasSwap.spec", async () => {
|
||||
|
||||
const signature = await signer._signTypedData(
|
||||
{
|
||||
name: "MinimalForwarder",
|
||||
version: "0.0.1",
|
||||
name: "ERC2771Forwarder",
|
||||
version: "1",
|
||||
chainId: (await ethers.provider.getNetwork()).chainId,
|
||||
verifyingContract: forwarder.address,
|
||||
},
|
||||
@@ -305,17 +306,29 @@ describe("GasSwap.spec", async () => {
|
||||
name: "nonce",
|
||||
type: "uint256",
|
||||
},
|
||||
{
|
||||
name: "deadline",
|
||||
type: "uint48",
|
||||
},
|
||||
{
|
||||
name: "data",
|
||||
type: "bytes",
|
||||
},
|
||||
],
|
||||
},
|
||||
req
|
||||
reqWithoutSignature
|
||||
);
|
||||
|
||||
const balanceBefore = await signer.getBalance();
|
||||
await forwarder.execute(req, signature);
|
||||
await forwarder.execute({
|
||||
from: reqWithoutSignature.from,
|
||||
to: reqWithoutSignature.to,
|
||||
value: reqWithoutSignature.value,
|
||||
gas: reqWithoutSignature.gas,
|
||||
deadline: reqWithoutSignature.deadline,
|
||||
data: reqWithoutSignature.data,
|
||||
signature,
|
||||
});
|
||||
const balanceAfter = await signer.getBalance();
|
||||
expect(balanceAfter.sub(balanceBefore)).to.eq(amountOut.sub(fee));
|
||||
expect(await token.balanceOf(signer.address)).to.eq(amountIn.mul(refundRatio).div(100));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* eslint-disable node/no-unpublished-import */
|
||||
/* eslint-disable node/no-missing-import */
|
||||
import { concat } from "ethers/lib/utils";
|
||||
import { constants } from "ethers";
|
||||
import { ethers } from "hardhat";
|
||||
import { ScrollChain, L1MessageQueue } from "../typechain";
|
||||
@@ -11,22 +12,27 @@ describe("ScrollChain", async () => {
|
||||
beforeEach(async () => {
|
||||
const [deployer] = await ethers.getSigners();
|
||||
|
||||
const ProxyAdmin = await ethers.getContractFactory("ProxyAdmin", deployer);
|
||||
const admin = await ProxyAdmin.deploy();
|
||||
await admin.deployed();
|
||||
|
||||
const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy", deployer);
|
||||
|
||||
const L1MessageQueue = await ethers.getContractFactory("L1MessageQueue", deployer);
|
||||
queue = await L1MessageQueue.deploy();
|
||||
await queue.deployed();
|
||||
const queueImpl = await L1MessageQueue.deploy();
|
||||
await queueImpl.deployed();
|
||||
const queueProxy = await TransparentUpgradeableProxy.deploy(queueImpl.address, admin.address, "0x");
|
||||
await queueProxy.deployed();
|
||||
queue = await ethers.getContractAt("L1MessageQueue", queueProxy.address, deployer);
|
||||
|
||||
const RollupVerifier = await ethers.getContractFactory("RollupVerifier", deployer);
|
||||
const verifier = await RollupVerifier.deploy();
|
||||
await verifier.deployed();
|
||||
const ScrollChain = await ethers.getContractFactory("ScrollChain", deployer);
|
||||
const chainImpl = await ScrollChain.deploy(0);
|
||||
await chainImpl.deployed();
|
||||
const chainProxy = await TransparentUpgradeableProxy.deploy(chainImpl.address, admin.address, "0x");
|
||||
await chainProxy.deployed();
|
||||
chain = await ethers.getContractAt("ScrollChain", chainProxy.address, deployer);
|
||||
|
||||
const ScrollChain = await ethers.getContractFactory("ScrollChain", {
|
||||
signer: deployer,
|
||||
libraries: { RollupVerifier: verifier.address },
|
||||
});
|
||||
chain = await ScrollChain.deploy(0);
|
||||
await chain.deployed();
|
||||
|
||||
await chain.initialize(queue.address, constants.AddressZero, 44);
|
||||
await chain.initialize(queue.address, constants.AddressZero, 100);
|
||||
await chain.addSequencer(deployer.address);
|
||||
await queue.initialize(
|
||||
constants.AddressZero,
|
||||
@@ -38,79 +44,54 @@ describe("ScrollChain", async () => {
|
||||
});
|
||||
|
||||
// @note skip this benchmark tests
|
||||
/*
|
||||
it("should succeed", async () => {
|
||||
await chain.importGenesisBatch({
|
||||
blocks: [
|
||||
{
|
||||
blockHash: "0x92826bd3aad2ef70d8061dc4e25150b305d1233d9cd7579433a77d6eb01dae1c",
|
||||
parentHash: constants.HashZero,
|
||||
blockNumber: 0,
|
||||
timestamp: 1639724192,
|
||||
baseFee: 1000000000,
|
||||
gasLimit: 940000000,
|
||||
numTransactions: 0,
|
||||
numL1Messages: 0,
|
||||
},
|
||||
],
|
||||
prevStateRoot: constants.HashZero,
|
||||
newStateRoot: "0x1b186a7a90ec3b41a2417062fe44dce8ce82ae76bfbb09eae786a4f1be1895f5",
|
||||
withdrawTrieRoot: constants.HashZero,
|
||||
batchIndex: 0,
|
||||
parentBatchHash: constants.HashZero,
|
||||
l2Transactions: [],
|
||||
});
|
||||
const parentBatchHash = await chain.lastFinalizedBatchHash();
|
||||
it.skip("should succeed", async () => {
|
||||
const batchHeader0 = new Uint8Array(89);
|
||||
batchHeader0[25] = 1;
|
||||
await chain.importGenesisBatch(batchHeader0, "0x0000000000000000000000000000000000000000000000000000000000000001");
|
||||
const parentBatchHash = await chain.committedBatches(0);
|
||||
console.log("genesis batch hash:", parentBatchHash);
|
||||
console.log(`ChunkPerBatch`, `BlockPerChunk`, `TxPerBlock`, `BytesPerTx`, `TotalBytes`, `EstimateGas`);
|
||||
for (let numChunks = 3; numChunks <= 6; ++numChunks) {
|
||||
for (let numBlocks = 1; numBlocks <= 5; ++numBlocks) {
|
||||
for (let numTx = 20; numTx <= Math.min(30, 100 / numBlocks); ++numTx) {
|
||||
for (let txLength = 800; txLength <= 1000; txLength += 100) {
|
||||
const txs: Array<Uint8Array> = [];
|
||||
for (let i = 0; i < numTx; i++) {
|
||||
const tx = new Uint8Array(4 + txLength);
|
||||
let offset = 3;
|
||||
for (let x = txLength; x > 0; x = Math.floor(x / 256)) {
|
||||
tx[offset] = x % 256;
|
||||
offset -= 1;
|
||||
}
|
||||
tx.fill(1, 4);
|
||||
txs.push(tx);
|
||||
}
|
||||
const chunk = new Uint8Array(1 + 60 * numBlocks);
|
||||
chunk[0] = numBlocks;
|
||||
for (let i = 0; i < numBlocks; i++) {
|
||||
chunk[1 + i * 60 + 57] = numTx;
|
||||
}
|
||||
const chunks: Array<Uint8Array> = [];
|
||||
for (let i = 0; i < numChunks; i++) {
|
||||
const txsInChunk: Array<Uint8Array> = [];
|
||||
for (let j = 0; j < numBlocks; j++) {
|
||||
txsInChunk.push(concat(txs));
|
||||
}
|
||||
chunks.push(concat([chunk, concat(txsInChunk)]));
|
||||
}
|
||||
|
||||
for (let numTx = 1; numTx <= 25; ++numTx) {
|
||||
for (let txLength = 100; txLength <= 1000; txLength += 100) {
|
||||
const txs: Array<Uint8Array> = [];
|
||||
for (let i = 0; i < numTx; i++) {
|
||||
const tx = new Uint8Array(4 + txLength);
|
||||
let offset = 3;
|
||||
for (let x = txLength; x > 0; x = Math.floor(x / 256)) {
|
||||
tx[offset] = x % 256;
|
||||
offset -= 1;
|
||||
const estimateGas = await chain.estimateGas.commitBatch(0, batchHeader0, chunks, "0x");
|
||||
console.log(
|
||||
`${numChunks}`,
|
||||
`${numBlocks}`,
|
||||
`${numTx}`,
|
||||
`${txLength}`,
|
||||
`${numChunks * numBlocks * numTx * (txLength + 1)}`,
|
||||
`${estimateGas.toString()}`
|
||||
);
|
||||
}
|
||||
tx.fill(1, 4);
|
||||
txs.push(tx);
|
||||
}
|
||||
const batch = {
|
||||
blocks: [
|
||||
{
|
||||
blockHash: "0xb5baa665b2664c3bfed7eb46e00ebc110ecf2ebd257854a9bf2b9dbc9b2c08f6",
|
||||
parentHash: "0x92826bd3aad2ef70d8061dc4e25150b305d1233d9cd7579433a77d6eb01dae1c",
|
||||
blockNumber: 1,
|
||||
timestamp: numTx * 100000 + txLength,
|
||||
baseFee: 0,
|
||||
gasLimit: 0,
|
||||
numTransactions: 0,
|
||||
numL1Messages: 0,
|
||||
},
|
||||
],
|
||||
prevStateRoot: "0x1b186a7a90ec3b41a2417062fe44dce8ce82ae76bfbb09eae786a4f1be1895f5",
|
||||
newStateRoot: "0xb5baa665b2664c3bfed7eb46e00ebc110ecf2ebd257854a9bf2b9dbc9b2c08f6",
|
||||
withdrawTrieRoot: "0xb5baa665b2664c3bfed7eb46e00ebc110ecf2ebd257854a9bf2b9dbc9b2c08f6",
|
||||
batchIndex: 1,
|
||||
parentBatchHash: parentBatchHash,
|
||||
l2Transactions: concat(txs),
|
||||
};
|
||||
const estimateGas = await chain.estimateGas.commitBatch(batch);
|
||||
const tx = await chain.commitBatch(batch, { gasLimit: estimateGas.mul(12).div(10) });
|
||||
const receipt = await tx.wait();
|
||||
console.log(
|
||||
"Commit batch with l2TransactionsBytes:",
|
||||
numTx * (txLength + 4),
|
||||
"gasLimit:",
|
||||
tx.gasLimit.toString(),
|
||||
"estimateGas:",
|
||||
estimateGas.toString(),
|
||||
"gasUsed:",
|
||||
receipt.gasUsed.toString()
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ contract InitializeL1BridgeContracts is Script {
|
||||
uint256 L1_DEPLOYER_PRIVATE_KEY = vm.envUint("L1_DEPLOYER_PRIVATE_KEY");
|
||||
|
||||
uint256 CHAIN_ID_L2 = vm.envUint("CHAIN_ID_L2");
|
||||
uint256 MAX_L2_TX_IN_CHUNK = vm.envUint("MAX_L2_TX_IN_CHUNK");
|
||||
uint256 MAX_TX_IN_CHUNK = vm.envUint("MAX_TX_IN_CHUNK");
|
||||
uint256 MAX_L1_MESSAGE_GAS_LIMIT = vm.envUint("MAX_L1_MESSAGE_GAS_LIMIT");
|
||||
address L1_COMMIT_SENDER_ADDRESS = vm.envAddress("L1_COMMIT_SENDER_ADDRESS");
|
||||
address L1_FINALIZE_SENDER_ADDRESS = vm.envAddress("L1_FINALIZE_SENDER_ADDRESS");
|
||||
@@ -67,7 +67,7 @@ contract InitializeL1BridgeContracts is Script {
|
||||
ScrollChain(L1_SCROLL_CHAIN_PROXY_ADDR).initialize(
|
||||
L1_MESSAGE_QUEUE_PROXY_ADDR,
|
||||
L1_MULTIPLE_VERSION_ROLLUP_VERIFIER_ADDR,
|
||||
MAX_L2_TX_IN_CHUNK
|
||||
MAX_TX_IN_CHUNK
|
||||
);
|
||||
ScrollChain(L1_SCROLL_CHAIN_PROXY_ADDR).addSequencer(L1_COMMIT_SENDER_ADDRESS);
|
||||
ScrollChain(L1_SCROLL_CHAIN_PROXY_ADDR).addProver(L1_FINALIZE_SENDER_ADDRESS);
|
||||
|
||||
@@ -25,18 +25,18 @@ async function main() {
|
||||
const L2StandardERC20Impl = process.env.L2_SCROLL_STANDARD_ERC20_ADDR!;
|
||||
const L2StandardERC20FactoryAddress = process.env.L2_SCROLL_STANDARD_ERC20_FACTORY_ADDR!;
|
||||
|
||||
// if ((await L1StandardERC20Gateway.counterpart()) === constants.AddressZero) {
|
||||
const tx = await L1StandardERC20Gateway.initialize(
|
||||
L2StandardERC20GatewayAddress,
|
||||
L1GatewayRouterAddress,
|
||||
L1ScrollMessengerAddress,
|
||||
L2StandardERC20Impl,
|
||||
L2StandardERC20FactoryAddress
|
||||
);
|
||||
console.log("initialize L1StandardERC20Gateway, hash:", tx.hash);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`✅ Done, gas used: ${receipt.gasUsed}`);
|
||||
// }
|
||||
if ((await L1StandardERC20Gateway.counterpart()) === constants.AddressZero) {
|
||||
const tx = await L1StandardERC20Gateway.initialize(
|
||||
L2StandardERC20GatewayAddress,
|
||||
L1GatewayRouterAddress,
|
||||
L1ScrollMessengerAddress,
|
||||
L2StandardERC20Impl,
|
||||
L2StandardERC20FactoryAddress
|
||||
);
|
||||
console.log("initialize L1StandardERC20Gateway, hash:", tx.hash);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`✅ Done, gas used: ${receipt.gasUsed}`);
|
||||
}
|
||||
}
|
||||
|
||||
// We recommend this pattern to be able to use async/await everywhere
|
||||
|
||||
@@ -23,16 +23,16 @@ async function main() {
|
||||
const L1ScrollMessengerAddress = addressFile.get("L1ScrollMessenger.proxy");
|
||||
const L2GatewayRouterAddress = process.env.L2_GATEWAY_ROUTER_PROXY_ADDR!;
|
||||
|
||||
// if ((await L1GatewayRouter.counterpart()) === constants.AddressZero) {
|
||||
const tx = await L1GatewayRouter.initialize(
|
||||
L1StandardERC20GatewayAddress,
|
||||
L2GatewayRouterAddress,
|
||||
L1ScrollMessengerAddress
|
||||
);
|
||||
console.log("initialize L1StandardERC20Gateway, hash:", tx.hash);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`✅ Done, gas used: ${receipt.gasUsed}`);
|
||||
// }
|
||||
if ((await L1GatewayRouter.counterpart()) === constants.AddressZero) {
|
||||
const tx = await L1GatewayRouter.initialize(
|
||||
L1StandardERC20GatewayAddress,
|
||||
L2GatewayRouterAddress,
|
||||
L1ScrollMessengerAddress
|
||||
);
|
||||
console.log("initialize L1StandardERC20Gateway, hash:", tx.hash);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`✅ Done, gas used: ${receipt.gasUsed}`);
|
||||
}
|
||||
}
|
||||
|
||||
// We recommend this pattern to be able to use async/await everywhere
|
||||
|
||||
@@ -21,12 +21,12 @@ async function main() {
|
||||
|
||||
const ZKRollupAddress = addressFile.get("ZKRollup.proxy");
|
||||
|
||||
// if ((await L1ScrollMessenger.rollup()) === constants.AddressZero) {
|
||||
const tx = await L1ScrollMessenger.initialize(ZKRollupAddress);
|
||||
console.log("initialize L1StandardERC20Gateway, hash:", tx.hash);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`✅ Done, gas used: ${receipt.gasUsed}`);
|
||||
// }
|
||||
if ((await L1ScrollMessenger.rollup()) === constants.AddressZero) {
|
||||
const tx = await L1ScrollMessenger.initialize(ZKRollupAddress);
|
||||
console.log("initialize L1StandardERC20Gateway, hash:", tx.hash);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`✅ Done, gas used: ${receipt.gasUsed}`);
|
||||
}
|
||||
}
|
||||
|
||||
// We recommend this pattern to be able to use async/await everywhere
|
||||
|
||||
@@ -24,17 +24,17 @@ async function main() {
|
||||
const L2StandardERC20FactoryAddress = addressFile.get("ScrollStandardERC20Factory");
|
||||
const L1StandardERC20GatewayAddress = process.env.L1_STANDARD_ERC20_GATEWAY_PROXY_ADDR!;
|
||||
|
||||
// if ((await L2StandardERC20Gateway.counterpart()) === constants.AddressZero) {
|
||||
const tx = await L2StandardERC20Gateway.initialize(
|
||||
L1StandardERC20GatewayAddress,
|
||||
L2GatewayRouterAddress,
|
||||
L2ScrollMessengerAddress,
|
||||
L2StandardERC20FactoryAddress
|
||||
);
|
||||
console.log("initialize L2StandardERC20Gateway, hash:", tx.hash);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`✅ Done, gas used: ${receipt.gasUsed}`);
|
||||
// }
|
||||
if ((await L2StandardERC20Gateway.counterpart()) === constants.AddressZero) {
|
||||
const tx = await L2StandardERC20Gateway.initialize(
|
||||
L1StandardERC20GatewayAddress,
|
||||
L2GatewayRouterAddress,
|
||||
L2ScrollMessengerAddress,
|
||||
L2StandardERC20FactoryAddress
|
||||
);
|
||||
console.log("initialize L2StandardERC20Gateway, hash:", tx.hash);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`✅ Done, gas used: ${receipt.gasUsed}`);
|
||||
}
|
||||
}
|
||||
|
||||
// We recommend this pattern to be able to use async/await everywhere
|
||||
|
||||
@@ -23,16 +23,16 @@ async function main() {
|
||||
const L2ScrollMessengerAddress = addressFile.get("L2ScrollMessenger");
|
||||
const L1GatewayRouterAddress = process.env.L1_GATEWAY_ROUTER_PROXY_ADDR!;
|
||||
|
||||
// if ((await L2GatewayRouter.counterpart()) === constants.AddressZero) {
|
||||
const tx = await L2GatewayRouter.initialize(
|
||||
L2StandardERC20GatewayAddress,
|
||||
L1GatewayRouterAddress,
|
||||
L2ScrollMessengerAddress
|
||||
);
|
||||
console.log("initialize L1StandardERC20Gateway, hash:", tx.hash);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`✅ Done, gas used: ${receipt.gasUsed}`);
|
||||
// }
|
||||
if ((await L2GatewayRouter.counterpart()) === constants.AddressZero) {
|
||||
const tx = await L2GatewayRouter.initialize(
|
||||
L2StandardERC20GatewayAddress,
|
||||
L1GatewayRouterAddress,
|
||||
L2ScrollMessengerAddress
|
||||
);
|
||||
console.log("initialize L1StandardERC20Gateway, hash:", tx.hash);
|
||||
const receipt = await tx.wait();
|
||||
console.log(`✅ Done, gas used: ${receipt.gasUsed}`);
|
||||
}
|
||||
}
|
||||
|
||||
// We recommend this pattern to be able to use async/await everywhere
|
||||
|
||||
@@ -9,8 +9,6 @@ import {IL1ERC20Gateway} from "./IL1ERC20Gateway.sol";
|
||||
import {IL1GatewayRouter} from "./IL1GatewayRouter.sol";
|
||||
|
||||
import {IL2ERC20Gateway} from "../../L2/gateways/IL2ERC20Gateway.sol";
|
||||
import {IScrollMessenger} from "../../libraries/IScrollMessenger.sol";
|
||||
import {ScrollConstants} from "../../libraries/constants/ScrollConstants.sol";
|
||||
import {ScrollGatewayBase} from "../../libraries/gateway/ScrollGatewayBase.sol";
|
||||
import {IMessageDropCallback} from "../../libraries/callbacks/IMessageDropCallback.sol";
|
||||
|
||||
@@ -66,7 +64,7 @@ abstract contract L1ERC20Gateway is IL1ERC20Gateway, IMessageDropCallback, Scrol
|
||||
address _to,
|
||||
uint256 _amount,
|
||||
bytes calldata _data
|
||||
) external payable override onlyCallByCounterpart nonReentrant {
|
||||
) external payable virtual override onlyCallByCounterpart nonReentrant {
|
||||
_beforeFinalizeWithdrawERC20(_l1Token, _l2Token, _from, _to, _amount, _data);
|
||||
|
||||
// @note can possible trigger reentrant call to this contract or messenger,
|
||||
|
||||
@@ -2,10 +2,173 @@
|
||||
|
||||
pragma solidity =0.8.16;
|
||||
|
||||
import {L1CustomERC20Gateway} from "../L1CustomERC20Gateway.sol";
|
||||
import {IFiatToken} from "../../../interfaces/IFiatToken.sol";
|
||||
import {IUSDCBurnableSourceBridge} from "../../../interfaces/IUSDCBurnableSourceBridge.sol";
|
||||
import {IL2ERC20Gateway} from "../../../L2/gateways/IL2ERC20Gateway.sol";
|
||||
import {IL1ScrollMessenger} from "../../IL1ScrollMessenger.sol";
|
||||
import {IL1ERC20Gateway} from "../IL1ERC20Gateway.sol";
|
||||
|
||||
// solhint-disable no-empty-blocks
|
||||
import {ScrollGatewayBase} from "../../../libraries/gateway/ScrollGatewayBase.sol";
|
||||
import {L1ERC20Gateway} from "../L1ERC20Gateway.sol";
|
||||
|
||||
contract L1USDCGateway is L1CustomERC20Gateway {
|
||||
/// @title L1USDCGateway
|
||||
/// @notice The `L1USDCGateway` contract is used to deposit `USDC` token in layer 1 and
|
||||
/// finalize withdraw `USDC` from layer 2, before USDC become native in layer 2.
|
||||
contract L1USDCGateway is L1ERC20Gateway, IUSDCBurnableSourceBridge {
|
||||
/*************
|
||||
* Constants *
|
||||
*************/
|
||||
|
||||
/// @notice The address of L1 USDC address.
|
||||
// solhint-disable-next-line var-name-mixedcase
|
||||
address public immutable l1USDC;
|
||||
|
||||
/// @notice The address of L2 USDC address.
|
||||
address public immutable l2USDC;
|
||||
|
||||
/*************
|
||||
* Variables *
|
||||
*************/
|
||||
|
||||
/// @notice The address of caller from Circle.
|
||||
address public circleCaller;
|
||||
|
||||
/// @notice The flag indicates whether USDC deposit is paused.
|
||||
bool public depositPaused;
|
||||
|
||||
/// @notice The flag indicates whether USDC withdrawal is paused.
|
||||
/// @dev This is not necessary to be set `true` since we will set `L2USDCGateway.withdrawPaused` first.
|
||||
/// This is kept just in case and will be set after all pending messages are relayed.
|
||||
bool public withdrawPaused;
|
||||
|
||||
/// @notice The total amount of bridged USDC in this contract.
|
||||
/// @dev Only deposited USDC will count. Accidentally transferred USDC will be ignored.
|
||||
uint256 public totalBridgedUSDC;
|
||||
|
||||
/***************
|
||||
* Constructor *
|
||||
***************/
|
||||
|
||||
constructor(address _l1USDC, address _l2USDC) {
|
||||
_disableInitializers();
|
||||
|
||||
l1USDC = _l1USDC;
|
||||
l2USDC = _l2USDC;
|
||||
}
|
||||
|
||||
/// @notice Initialize the storage of L1WETHGateway.
|
||||
/// @param _counterpart The address of L2ETHGateway in L2.
|
||||
/// @param _router The address of L1GatewayRouter.
|
||||
/// @param _messenger The address of L1ScrollMessenger.
|
||||
function initialize(
|
||||
address _counterpart,
|
||||
address _router,
|
||||
address _messenger
|
||||
) external initializer {
|
||||
require(_router != address(0), "zero router address");
|
||||
ScrollGatewayBase._initialize(_counterpart, _router, _messenger);
|
||||
}
|
||||
|
||||
/*************************
|
||||
* Public View Functions *
|
||||
*************************/
|
||||
|
||||
/// @inheritdoc IL1ERC20Gateway
|
||||
function getL2ERC20Address(address) public view override returns (address) {
|
||||
return l2USDC;
|
||||
}
|
||||
|
||||
/*******************************
|
||||
* Public Restricted Functions *
|
||||
*******************************/
|
||||
|
||||
/// @inheritdoc IUSDCBurnableSourceBridge
|
||||
function burnAllLockedUSDC() external override {
|
||||
require(msg.sender == circleCaller, "only circle caller");
|
||||
|
||||
// @note Only bridged USDC will be burned. We may refund the rest if possible.
|
||||
uint256 _balance = totalBridgedUSDC;
|
||||
totalBridgedUSDC = 0;
|
||||
|
||||
IFiatToken(l1USDC).burn(_balance);
|
||||
}
|
||||
|
||||
/// @notice Update the Circle EOA address.
|
||||
/// @param _caller The address to update.
|
||||
function updateCircleCaller(address _caller) external onlyOwner {
|
||||
circleCaller = _caller;
|
||||
}
|
||||
|
||||
/// @notice Change the deposit pause status of this contract.
|
||||
/// @param _paused The new status, `true` means paused and `false` means not paused.
|
||||
function pauseDeposit(bool _paused) external onlyOwner {
|
||||
depositPaused = _paused;
|
||||
}
|
||||
|
||||
/// @notice Change the withdraw pause status of this contract.
|
||||
/// @param _paused The new status, `true` means paused and `false` means not paused.
|
||||
function pauseWithdraw(bool _paused) external onlyOwner {
|
||||
withdrawPaused = _paused;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* Internal Functions *
|
||||
**********************/
|
||||
|
||||
/// @inheritdoc L1ERC20Gateway
|
||||
function _beforeFinalizeWithdrawERC20(
|
||||
address _l1Token,
|
||||
address _l2Token,
|
||||
address,
|
||||
address,
|
||||
uint256 _amount,
|
||||
bytes calldata
|
||||
) internal virtual override {
|
||||
require(msg.value == 0, "nonzero msg.value");
|
||||
require(_l1Token == l1USDC, "l1 token not USDC");
|
||||
require(_l2Token == l2USDC, "l2 token not USDC");
|
||||
require(!withdrawPaused, "withdraw paused");
|
||||
|
||||
totalBridgedUSDC -= _amount;
|
||||
}
|
||||
|
||||
/// @inheritdoc L1ERC20Gateway
|
||||
function _beforeDropMessage(
|
||||
address,
|
||||
address,
|
||||
uint256 _amount
|
||||
) internal virtual override {
|
||||
require(msg.value == 0, "nonzero msg.value");
|
||||
totalBridgedUSDC -= _amount;
|
||||
}
|
||||
|
||||
/// @inheritdoc L1ERC20Gateway
|
||||
function _deposit(
|
||||
address _token,
|
||||
address _to,
|
||||
uint256 _amount,
|
||||
bytes memory _data,
|
||||
uint256 _gasLimit
|
||||
) internal virtual override nonReentrant {
|
||||
require(_amount > 0, "deposit zero amount");
|
||||
require(_token == l1USDC, "only USDC is allowed");
|
||||
require(!depositPaused, "deposit paused");
|
||||
|
||||
// 1. Transfer token into this contract.
|
||||
address _from;
|
||||
(_from, _amount, _data) = _transferERC20In(_token, _amount, _data);
|
||||
require(_data.length == 0, "call is not allowed");
|
||||
totalBridgedUSDC += _amount;
|
||||
|
||||
// 2. Generate message passed to L2USDCGateway.
|
||||
bytes memory _message = abi.encodeCall(
|
||||
IL2ERC20Gateway.finalizeDepositERC20,
|
||||
(_token, l2USDC, _from, _to, _amount, _data)
|
||||
);
|
||||
|
||||
// 3. Send message to L1ScrollMessenger.
|
||||
IL1ScrollMessenger(messenger).sendMessage{value: msg.value}(counterpart, 0, _message, _gasLimit, _from);
|
||||
|
||||
emit DepositERC20(_token, l2USDC, _from, _to, _amount, _data);
|
||||
}
|
||||
}
|
||||
|
||||
180
contracts/src/L1/gateways/usdc/draft-L1USDCGatewayCCTP.sol
Normal file
180
contracts/src/L1/gateways/usdc/draft-L1USDCGatewayCCTP.sol
Normal file
@@ -0,0 +1,180 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity =0.8.16;
|
||||
|
||||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||||
|
||||
import {ITokenMessenger} from "../../../interfaces/ITokenMessenger.sol";
|
||||
import {IL2ERC20Gateway} from "../../../L2/gateways/IL2ERC20Gateway.sol";
|
||||
import {IL1ScrollMessenger} from "../../IL1ScrollMessenger.sol";
|
||||
import {IL1ERC20Gateway} from "../IL1ERC20Gateway.sol";
|
||||
|
||||
import {CCTPGatewayBase} from "../../../libraries/gateway/CCTPGatewayBase.sol";
|
||||
import {ScrollGatewayBase} from "../../../libraries/gateway/ScrollGatewayBase.sol";
|
||||
import {L1ERC20Gateway} from "../L1ERC20Gateway.sol";
|
||||
|
||||
/// @title L1USDCGatewayCCTP
|
||||
/// @notice The `L1USDCGateway` contract is used to deposit `USDC` token in layer 1 and
|
||||
/// finalize withdraw `USDC` from layer 2, after USDC become native in layer 2.
|
||||
contract L1USDCGatewayCCTP is CCTPGatewayBase, L1ERC20Gateway {
|
||||
/***************
|
||||
* Constructor *
|
||||
***************/
|
||||
|
||||
constructor(
|
||||
address _l1USDC,
|
||||
address _l2USDC,
|
||||
uint32 _destinationDomain
|
||||
) CCTPGatewayBase(_l1USDC, _l2USDC, _destinationDomain) {
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
/// @notice Initialize the storage of L1USDCGatewayCCTP.
|
||||
/// @param _counterpart The address of L2USDCGatewayCCTP in L2.
|
||||
/// @param _router The address of L1GatewayRouter.
|
||||
/// @param _messenger The address of L1ScrollMessenger.
|
||||
/// @param _cctpMessenger The address of TokenMessenger in local domain.
|
||||
/// @param _cctpTransmitter The address of MessageTransmitter in local domain.
|
||||
function initialize(
|
||||
address _counterpart,
|
||||
address _router,
|
||||
address _messenger,
|
||||
address _cctpMessenger,
|
||||
address _cctpTransmitter
|
||||
) external initializer {
|
||||
require(_router != address(0), "zero router address");
|
||||
ScrollGatewayBase._initialize(_counterpart, _router, _messenger);
|
||||
CCTPGatewayBase._initialize(_cctpMessenger, _cctpTransmitter);
|
||||
}
|
||||
|
||||
/*************************
|
||||
* Public View Functions *
|
||||
*************************/
|
||||
|
||||
/// @inheritdoc IL1ERC20Gateway
|
||||
function getL2ERC20Address(address) public view override returns (address) {
|
||||
return l2USDC;
|
||||
}
|
||||
|
||||
/*****************************
|
||||
* Public Mutating Functions *
|
||||
*****************************/
|
||||
|
||||
/// @notice Relay cross chain message and claim USDC that has been cross chained.
|
||||
/// @dev The `_scrollMessage` is actually encoded calldata for `L1ScrollMessenger.relayMessageWithProof`.
|
||||
///
|
||||
/// @dev This helper function is aimed to claim USDC in single transaction.
|
||||
/// Normally, an user should call `L1ScrollMessenger.relayMessageWithProof` first,
|
||||
/// then `L1USDCGatewayCCTP.claimUSDC`.
|
||||
///
|
||||
/// @param _nonce The nonce of the message from CCTP.
|
||||
/// @param _cctpMessage The message passed to MessageTransmitter contract in CCTP.
|
||||
/// @param _cctpSignature The message passed to MessageTransmitter contract in CCTP.
|
||||
/// @param _scrollMessage The message passed to L1ScrollMessenger contract.
|
||||
function relayAndClaimUSDC(
|
||||
uint256 _nonce,
|
||||
bytes calldata _cctpMessage,
|
||||
bytes calldata _cctpSignature,
|
||||
bytes calldata _scrollMessage
|
||||
) external {
|
||||
require(status[_nonce] == CCTPMessageStatus.None, "message relayed");
|
||||
// call messenger to set `status[_nonce]` to `CCTPMessageStatus.Pending`.
|
||||
(bool _success, ) = messenger.call(_scrollMessage);
|
||||
require(_success, "call messenger failed");
|
||||
|
||||
claimUSDC(_nonce, _cctpMessage, _cctpSignature);
|
||||
}
|
||||
|
||||
/// @inheritdoc IL1ERC20Gateway
|
||||
/// @dev The function will not mint the USDC, users need to call `claimUSDC` after this function is done.
|
||||
function finalizeWithdrawERC20(
|
||||
address _l1Token,
|
||||
address _l2Token,
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _amount,
|
||||
bytes memory _data
|
||||
) external payable override onlyCallByCounterpart {
|
||||
require(msg.value == 0, "nonzero msg.value");
|
||||
require(_l1Token == l1USDC, "l1 token not USDC");
|
||||
require(_l2Token == l2USDC, "l2 token not USDC");
|
||||
|
||||
uint256 _nonce;
|
||||
(_nonce, _data) = abi.decode(_data, (uint256, bytes));
|
||||
require(status[_nonce] == CCTPMessageStatus.None, "message relayed");
|
||||
status[_nonce] = CCTPMessageStatus.Pending;
|
||||
|
||||
emit FinalizeWithdrawERC20(_l1Token, _l2Token, _from, _to, _amount, _data);
|
||||
}
|
||||
|
||||
/*******************************
|
||||
* Public Restricted Functions *
|
||||
*******************************/
|
||||
|
||||
/// @notice Update the CCTP contract addresses.
|
||||
/// @param _messenger The address of TokenMessenger in local domain.
|
||||
/// @param _transmitter The address of MessageTransmitter in local domain.
|
||||
function updateCCTPContracts(address _messenger, address _transmitter) external onlyOwner {
|
||||
cctpMessenger = _messenger;
|
||||
cctpTransmitter = _transmitter;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* Internal Functions *
|
||||
**********************/
|
||||
|
||||
/// @inheritdoc L1ERC20Gateway
|
||||
function _beforeFinalizeWithdrawERC20(
|
||||
address,
|
||||
address,
|
||||
address,
|
||||
address,
|
||||
uint256,
|
||||
bytes calldata
|
||||
) internal virtual override {}
|
||||
|
||||
/// @inheritdoc L1ERC20Gateway
|
||||
function _beforeDropMessage(
|
||||
address,
|
||||
address,
|
||||
uint256
|
||||
) internal virtual override {
|
||||
require(msg.value == 0, "nonzero msg.value");
|
||||
}
|
||||
|
||||
/// @inheritdoc L1ERC20Gateway
|
||||
function _deposit(
|
||||
address _token,
|
||||
address _to,
|
||||
uint256 _amount,
|
||||
bytes memory _data,
|
||||
uint256 _gasLimit
|
||||
) internal virtual override nonReentrant {
|
||||
require(_amount > 0, "deposit zero amount");
|
||||
require(_token == l1USDC, "only USDC is allowed");
|
||||
|
||||
// 1. Extract real sender if this call is from L1GatewayRouter.
|
||||
address _from;
|
||||
(_from, _amount, _data) = _transferERC20In(_token, _amount, _data);
|
||||
|
||||
// 2. Burn token through CCTP TokenMessenger
|
||||
uint256 _nonce = ITokenMessenger(cctpMessenger).depositForBurnWithCaller(
|
||||
_amount,
|
||||
destinationDomain,
|
||||
bytes32(uint256(uint160(_to))),
|
||||
address(this),
|
||||
bytes32(uint256(uint160(counterpart)))
|
||||
);
|
||||
|
||||
// 3. Generate message passed to L2USDCGatewayCCTP.
|
||||
bytes memory _message = abi.encodeCall(
|
||||
IL2ERC20Gateway.finalizeDepositERC20,
|
||||
(_token, l2USDC, _from, _to, _amount, abi.encode(_nonce, _data))
|
||||
);
|
||||
|
||||
// 4. Send message to L1ScrollMessenger.
|
||||
IL1ScrollMessenger(messenger).sendMessage{value: msg.value}(counterpart, 0, _message, _gasLimit);
|
||||
|
||||
emit DepositERC20(_token, l2USDC, _from, _to, _amount, _data);
|
||||
}
|
||||
}
|
||||
@@ -36,10 +36,10 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
|
||||
/// @param newVerifier The address of new rollup verifier.
|
||||
event UpdateVerifier(address indexed oldVerifier, address indexed newVerifier);
|
||||
|
||||
/// @notice Emitted when the value of `maxNumL2TxInChunk` is updated.
|
||||
/// @param oldMaxNumL2TxInChunk The old value of `maxNumL2TxInChunk`.
|
||||
/// @param newMaxNumL2TxInChunk The new value of `maxNumL2TxInChunk`.
|
||||
event UpdateMaxNumL2TxInChunk(uint256 oldMaxNumL2TxInChunk, uint256 newMaxNumL2TxInChunk);
|
||||
/// @notice Emitted when the value of `maxNumTxInChunk` is updated.
|
||||
/// @param oldMaxNumTxInChunk The old value of `maxNumTxInChunk`.
|
||||
/// @param newMaxNumTxInChunk The new value of `maxNumTxInChunk`.
|
||||
event UpdateMaxNumTxInChunk(uint256 oldMaxNumTxInChunk, uint256 newMaxNumTxInChunk);
|
||||
|
||||
/*************
|
||||
* Constants *
|
||||
@@ -53,7 +53,7 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
|
||||
*************/
|
||||
|
||||
/// @notice The maximum number of transactions allowed in each chunk.
|
||||
uint256 public maxNumL2TxInChunk;
|
||||
uint256 public maxNumTxInChunk;
|
||||
|
||||
/// @notice The address of L1MessageQueue.
|
||||
address public messageQueue;
|
||||
@@ -107,16 +107,16 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
|
||||
function initialize(
|
||||
address _messageQueue,
|
||||
address _verifier,
|
||||
uint256 _maxNumL2TxInChunk
|
||||
uint256 _maxNumTxInChunk
|
||||
) public initializer {
|
||||
OwnableUpgradeable.__Ownable_init();
|
||||
|
||||
messageQueue = _messageQueue;
|
||||
verifier = _verifier;
|
||||
maxNumL2TxInChunk = _maxNumL2TxInChunk;
|
||||
maxNumTxInChunk = _maxNumTxInChunk;
|
||||
|
||||
emit UpdateVerifier(address(0), _verifier);
|
||||
emit UpdateMaxNumL2TxInChunk(0, _maxNumL2TxInChunk);
|
||||
emit UpdateMaxNumTxInChunk(0, _maxNumTxInChunk);
|
||||
}
|
||||
|
||||
/*************************
|
||||
@@ -398,13 +398,13 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
|
||||
emit UpdateVerifier(_oldVerifier, _newVerifier);
|
||||
}
|
||||
|
||||
/// @notice Update the value of `maxNumL2TxInChunk`.
|
||||
/// @param _maxNumL2TxInChunk The new value of `maxNumL2TxInChunk`.
|
||||
function updateMaxNumL2TxInChunk(uint256 _maxNumL2TxInChunk) external onlyOwner {
|
||||
uint256 _oldMaxNumL2TxInChunk = maxNumL2TxInChunk;
|
||||
maxNumL2TxInChunk = _maxNumL2TxInChunk;
|
||||
/// @notice Update the value of `maxNumTxInChunk`.
|
||||
/// @param _maxNumTxInChunk The new value of `maxNumTxInChunk`.
|
||||
function updateMaxNumTxInChunk(uint256 _maxNumTxInChunk) external onlyOwner {
|
||||
uint256 _oldMaxNumTxInChunk = maxNumTxInChunk;
|
||||
maxNumTxInChunk = _maxNumTxInChunk;
|
||||
|
||||
emit UpdateMaxNumL2TxInChunk(_oldMaxNumL2TxInChunk, _maxNumL2TxInChunk);
|
||||
emit UpdateMaxNumTxInChunk(_oldMaxNumTxInChunk, _maxNumTxInChunk);
|
||||
}
|
||||
|
||||
/// @notice Pause the contract
|
||||
@@ -462,19 +462,26 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
|
||||
|
||||
uint256 _numBlocks = ChunkCodec.validateChunkLength(chunkPtr, _chunk.length);
|
||||
|
||||
// concatenate block contexts
|
||||
uint256 _totalTransactionsInChunk;
|
||||
for (uint256 i = 0; i < _numBlocks; i++) {
|
||||
dataPtr = ChunkCodec.copyBlockContext(chunkPtr, dataPtr, i);
|
||||
uint256 _numTransactionsInBlock = ChunkCodec.numTransactions(blockPtr);
|
||||
unchecked {
|
||||
_totalTransactionsInChunk += _numTransactionsInBlock;
|
||||
blockPtr += ChunkCodec.BLOCK_CONTEXT_LENGTH;
|
||||
// concatenate block contexts, use scope to avoid stack too deep
|
||||
{
|
||||
uint256 _totalTransactionsInChunk;
|
||||
for (uint256 i = 0; i < _numBlocks; i++) {
|
||||
dataPtr = ChunkCodec.copyBlockContext(chunkPtr, dataPtr, i);
|
||||
uint256 _numTransactionsInBlock = ChunkCodec.numTransactions(blockPtr);
|
||||
unchecked {
|
||||
_totalTransactionsInChunk += _numTransactionsInBlock;
|
||||
blockPtr += ChunkCodec.BLOCK_CONTEXT_LENGTH;
|
||||
}
|
||||
}
|
||||
assembly {
|
||||
mstore(0x40, add(dataPtr, mul(_totalTransactionsInChunk, 0x20))) // reserve memory for tx hashes
|
||||
}
|
||||
}
|
||||
|
||||
// It is used to compute the actual number of transactions in chunk.
|
||||
uint256 txHashStartDataPtr;
|
||||
assembly {
|
||||
mstore(0x40, add(dataPtr, mul(_totalTransactionsInChunk, 0x20))) // reserve memory for tx hashes
|
||||
txHashStartDataPtr := dataPtr
|
||||
blockPtr := add(chunkPtr, 1) // reset block ptr
|
||||
}
|
||||
|
||||
@@ -513,11 +520,8 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
|
||||
}
|
||||
}
|
||||
|
||||
// check the number of L2 transactions in the chunk
|
||||
require(
|
||||
_totalTransactionsInChunk - _totalNumL1MessagesInChunk <= maxNumL2TxInChunk,
|
||||
"too many L2 txs in one chunk"
|
||||
);
|
||||
// check the actual number of transactions in the chunk
|
||||
require((dataPtr - txHashStartDataPtr) / 32 <= maxNumTxInChunk, "too many txs in one chunk");
|
||||
|
||||
// check chunk has correct length
|
||||
require(l2TxPtr - chunkPtr == _chunk.length, "incomplete l2 transaction data");
|
||||
@@ -550,9 +554,10 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
|
||||
|
||||
unchecked {
|
||||
uint256 _bitmap;
|
||||
uint256 rem;
|
||||
for (uint256 i = 0; i < _numL1Messages; i++) {
|
||||
uint256 quo = _totalL1MessagesPoppedInBatch >> 8;
|
||||
uint256 rem = _totalL1MessagesPoppedInBatch & 0xff;
|
||||
rem = _totalL1MessagesPoppedInBatch & 0xff;
|
||||
|
||||
// load bitmap every 256 bits
|
||||
if (i == 0 || rem == 0) {
|
||||
@@ -574,7 +579,7 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
|
||||
}
|
||||
|
||||
// check last L1 message is not skipped, _totalL1MessagesPoppedInBatch must > 0
|
||||
uint256 rem = (_totalL1MessagesPoppedInBatch - 1) & 0xff;
|
||||
rem = (_totalL1MessagesPoppedInBatch - 1) & 0xff;
|
||||
require(((_bitmap >> rem) & 1) == 0, "cannot skip last L1 message");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,21 +2,23 @@
|
||||
|
||||
pragma solidity =0.8.16;
|
||||
|
||||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||||
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
|
||||
import {SafeERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
|
||||
|
||||
import {IFiatToken} from "../../../interfaces/IFiatToken.sol";
|
||||
import {IUSDCDestinationBridge} from "../../../interfaces/IUSDCDestinationBridge.sol";
|
||||
import {IL1ERC20Gateway} from "../../../L1/gateways/IL1ERC20Gateway.sol";
|
||||
import {IL2ScrollMessenger} from "../../IL2ScrollMessenger.sol";
|
||||
import {IL2ERC20Gateway} from "../IL2ERC20Gateway.sol";
|
||||
|
||||
import {ScrollGatewayBase, IScrollGateway} from "../../../libraries/gateway/ScrollGatewayBase.sol";
|
||||
import {ScrollGatewayBase} from "../../../libraries/gateway/ScrollGatewayBase.sol";
|
||||
import {L2ERC20Gateway} from "../L2ERC20Gateway.sol";
|
||||
|
||||
/// @title L2USDCGateway
|
||||
/// @notice The `L2USDCGateway` contract is used to withdraw `USDC` token on layer 2 and
|
||||
/// finalize deposit `USDC` from layer 1.
|
||||
contract L2USDCGateway is L2ERC20Gateway {
|
||||
contract L2USDCGateway is L2ERC20Gateway, IUSDCDestinationBridge {
|
||||
using SafeERC20Upgradeable for IERC20Upgradeable;
|
||||
|
||||
/*************
|
||||
@@ -33,8 +35,15 @@ contract L2USDCGateway is L2ERC20Gateway {
|
||||
* Variables *
|
||||
*************/
|
||||
|
||||
/// @notice The address of caller from Circle.
|
||||
address public circleCaller;
|
||||
|
||||
/// @notice The flag indicates whether USDC deposit is paused.
|
||||
/// @dev This is not necessary to be set `true` since we will set `L1USDCGateway.depositPaused` first.
|
||||
/// This is kept just in case and will be set after all pending messages are relayed.
|
||||
bool public depositPaused;
|
||||
|
||||
/// @notice The flag indicates whether USDC withdrawal is paused.
|
||||
bool public withdrawPaused;
|
||||
|
||||
/***************
|
||||
@@ -91,7 +100,8 @@ contract L2USDCGateway is L2ERC20Gateway {
|
||||
|
||||
require(IFiatToken(_l2Token).mint(_to, _amount), "mint USDC failed");
|
||||
|
||||
_doCallback(_to, _data);
|
||||
// disable call for USDC
|
||||
// _doCallback(_to, _data);
|
||||
|
||||
emit FinalizeDepositERC20(_l1Token, _l2Token, _from, _to, _amount, _data);
|
||||
}
|
||||
@@ -100,6 +110,19 @@ contract L2USDCGateway is L2ERC20Gateway {
|
||||
* Public Restricted Functions *
|
||||
*******************************/
|
||||
|
||||
/// @inheritdoc IUSDCDestinationBridge
|
||||
function transferUSDCRoles(address _owner) external {
|
||||
require(msg.sender == circleCaller, "only circle caller");
|
||||
|
||||
OwnableUpgradeable(l2USDC).transferOwnership(_owner);
|
||||
}
|
||||
|
||||
/// @notice Update the Circle EOA address.
|
||||
/// @param _caller The address to update.
|
||||
function updateCircleCaller(address _caller) external onlyOwner {
|
||||
circleCaller = _caller;
|
||||
}
|
||||
|
||||
/// @notice Change the deposit pause status of this contract.
|
||||
/// @param _paused The new status, `true` means paused and `false` means not paused.
|
||||
function pauseDeposit(bool _paused) external onlyOwner {
|
||||
@@ -133,10 +156,11 @@ contract L2USDCGateway is L2ERC20Gateway {
|
||||
if (router == msg.sender) {
|
||||
(_from, _data) = abi.decode(_data, (address, bytes));
|
||||
}
|
||||
require(_data.length == 0, "call is not allowed");
|
||||
|
||||
// 2. Transfer token into this contract.
|
||||
IERC20Upgradeable(_token).safeTransferFrom(_from, address(this), _amount);
|
||||
require(IFiatToken(_token).burn(_amount), "burn USDC failed");
|
||||
IFiatToken(_token).burn(_amount);
|
||||
|
||||
// 3. Generate message passed to L1USDCGateway.
|
||||
address _l1USDC = l1USDC;
|
||||
@@ -145,7 +169,7 @@ contract L2USDCGateway is L2ERC20Gateway {
|
||||
(_l1USDC, _token, _from, _to, _amount, _data)
|
||||
);
|
||||
|
||||
// 4. Send message to L1ScrollMessenger.
|
||||
// 4. Send message to L2ScrollMessenger.
|
||||
IL2ScrollMessenger(messenger).sendMessage{value: msg.value}(counterpart, 0, _message, _gasLimit);
|
||||
|
||||
emit WithdrawERC20(_l1USDC, _token, _from, _to, _amount, _data);
|
||||
|
||||
156
contracts/src/L2/gateways/usdc/draft-L2USDCGatewayCCTP.sol
Normal file
156
contracts/src/L2/gateways/usdc/draft-L2USDCGatewayCCTP.sol
Normal file
@@ -0,0 +1,156 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity =0.8.16;
|
||||
|
||||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||||
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
|
||||
import {SafeERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
|
||||
|
||||
import {ITokenMessenger} from "../../../interfaces/ITokenMessenger.sol";
|
||||
import {IL1ERC20Gateway} from "../../../L1/gateways/IL1ERC20Gateway.sol";
|
||||
import {IL2ScrollMessenger} from "../../IL2ScrollMessenger.sol";
|
||||
import {IL2ERC20Gateway} from "../IL2ERC20Gateway.sol";
|
||||
|
||||
import {CCTPGatewayBase} from "../../../libraries/gateway/CCTPGatewayBase.sol";
|
||||
import {ScrollGatewayBase} from "../../../libraries/gateway/ScrollGatewayBase.sol";
|
||||
import {L2ERC20Gateway} from "../L2ERC20Gateway.sol";
|
||||
|
||||
/// @title L2USDCGatewayCCTP
|
||||
/// @notice The `L2USDCGatewayCCTP` contract is used to withdraw `USDC` token in layer 2 and
|
||||
/// finalize deposit `USDC` from layer 1.
|
||||
contract L2USDCGatewayCCTP is CCTPGatewayBase, L2ERC20Gateway {
|
||||
using SafeERC20Upgradeable for IERC20Upgradeable;
|
||||
|
||||
/***************
|
||||
* Constructor *
|
||||
***************/
|
||||
|
||||
constructor(
|
||||
address _l1USDC,
|
||||
address _l2USDC,
|
||||
uint32 _destinationDomain
|
||||
) CCTPGatewayBase(_l1USDC, _l2USDC, _destinationDomain) {
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
/// @notice Initialize the storage of L2USDCGatewayCCTP.
|
||||
/// @param _counterpart The address of L1USDCGatewayCCTP in L1.
|
||||
/// @param _router The address of L2GatewayRouter.
|
||||
/// @param _messenger The address of L2ScrollMessenger.
|
||||
/// @param _cctpMessenger The address of TokenMessenger in local domain.
|
||||
/// @param _cctpTransmitter The address of MessageTransmitter in local domain.
|
||||
function initialize(
|
||||
address _counterpart,
|
||||
address _router,
|
||||
address _messenger,
|
||||
address _cctpMessenger,
|
||||
address _cctpTransmitter
|
||||
) external initializer {
|
||||
require(_router != address(0), "zero router address");
|
||||
ScrollGatewayBase._initialize(_counterpart, _router, _messenger);
|
||||
CCTPGatewayBase._initialize(_cctpMessenger, _cctpTransmitter);
|
||||
}
|
||||
|
||||
/*************************
|
||||
* Public View Functions *
|
||||
*************************/
|
||||
|
||||
/// @inheritdoc IL2ERC20Gateway
|
||||
function getL1ERC20Address(address) external view override returns (address) {
|
||||
return l1USDC;
|
||||
}
|
||||
|
||||
/// @inheritdoc IL2ERC20Gateway
|
||||
function getL2ERC20Address(address) public view override returns (address) {
|
||||
return l2USDC;
|
||||
}
|
||||
|
||||
/*****************************
|
||||
* Public Mutating Functions *
|
||||
*****************************/
|
||||
|
||||
/// @inheritdoc IL2ERC20Gateway
|
||||
/// @dev The function will not mint the USDC, users need to call `claimUSDC` after this function is done.
|
||||
function finalizeDepositERC20(
|
||||
address _l1Token,
|
||||
address _l2Token,
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _amount,
|
||||
bytes memory _data
|
||||
) external payable override onlyCallByCounterpart {
|
||||
require(msg.value == 0, "nonzero msg.value");
|
||||
require(_l1Token == l1USDC, "l1 token not USDC");
|
||||
require(_l2Token == l2USDC, "l2 token not USDC");
|
||||
|
||||
uint256 _nonce;
|
||||
(_nonce, _data) = abi.decode(_data, (uint256, bytes));
|
||||
require(status[_nonce] == CCTPMessageStatus.None, "message relayed");
|
||||
status[_nonce] = CCTPMessageStatus.Pending;
|
||||
|
||||
emit FinalizeDepositERC20(_l1Token, _l2Token, _from, _to, _amount, _data);
|
||||
}
|
||||
|
||||
/*******************************
|
||||
* Public Restricted Functions *
|
||||
*******************************/
|
||||
|
||||
/// @notice Update the CCTP contract addresses.
|
||||
/// @param _messenger The address of TokenMessenger in local domain.
|
||||
/// @param _transmitter The address of MessageTransmitter in local domain.
|
||||
function updateCCTPContracts(address _messenger, address _transmitter) external onlyOwner {
|
||||
cctpMessenger = _messenger;
|
||||
cctpTransmitter = _transmitter;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* Internal Functions *
|
||||
**********************/
|
||||
|
||||
/// @inheritdoc L2ERC20Gateway
|
||||
function _withdraw(
|
||||
address _token,
|
||||
address _to,
|
||||
uint256 _amount,
|
||||
bytes memory _data,
|
||||
uint256 _gasLimit
|
||||
) internal virtual override {
|
||||
require(_amount > 0, "withdraw zero amount");
|
||||
require(_token == l2USDC, "only USDC is allowed");
|
||||
|
||||
// 1. Extract real sender if this call is from L1GatewayRouter.
|
||||
address _from = msg.sender;
|
||||
if (router == msg.sender) {
|
||||
(_from, _data) = abi.decode(_data, (address, bytes));
|
||||
}
|
||||
|
||||
// 2. Transfer token into this contract.
|
||||
IERC20Upgradeable(_token).safeTransferFrom(_from, address(this), _amount);
|
||||
|
||||
// 3. Burn token through CCTP TokenMessenger
|
||||
uint256 _nonce = ITokenMessenger(cctpMessenger).depositForBurnWithCaller(
|
||||
_amount,
|
||||
destinationDomain,
|
||||
bytes32(uint256(uint160(_to))),
|
||||
address(this),
|
||||
bytes32(uint256(uint160(counterpart)))
|
||||
);
|
||||
|
||||
// 4. Generate message passed to L1USDCGateway.
|
||||
address _l1USDC = l1USDC;
|
||||
bytes memory _message = abi.encodeWithSelector(
|
||||
IL1ERC20Gateway.finalizeWithdrawERC20.selector,
|
||||
_l1USDC,
|
||||
_token,
|
||||
_from,
|
||||
_to,
|
||||
_amount,
|
||||
abi.encode(_nonce, _data)
|
||||
);
|
||||
|
||||
// 4. Send message to L1ScrollMessenger.
|
||||
IL2ScrollMessenger(messenger).sendMessage{value: msg.value}(counterpart, 0, _message, _gasLimit);
|
||||
|
||||
emit WithdrawERC20(_l1USDC, _token, _from, _to, _amount, _data);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
A library for interacting with Scroll contracts.
|
||||
|
||||
This library includes contracts and interfaces needed to interact with the Scroll Smart Contracts deployed on both Layer 1 and Layer 2. This includes deposting and withdrawing ETH, ERC20 tokens and NFTs or sending arbitrary messages.
|
||||
This library includes contracts and interfaces needed to interact with the Scroll Smart Contracts deployed on both Layer 1 and Layer 2. This includes deposting and withdrawing ETH, ERC20 tokens and NFTs or sending arbitrary messages.
|
||||
|
||||
# Overview
|
||||
|
||||
@@ -21,10 +21,11 @@ pragma solidity 0.8.20;
|
||||
import "@scroll-tech/contracts/L1/gateways/IL1ETHGateway.sol";
|
||||
|
||||
contract MyContract {
|
||||
function bridgeETH(address scrollBridge, uint gasLimit) public payable {
|
||||
IL1ETHGateway(scrollBridge).depositETH(msg.sender, msg.value, gasLimit);
|
||||
}
|
||||
function bridgeETH(address scrollBridge, uint256 gasLimit) public payable {
|
||||
IL1ETHGateway(scrollBridge).depositETH(msg.sender, msg.value, gasLimit);
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Visit the Bridge Documentation for API reference, architecture overview and guides with code examples.
|
||||
|
||||
@@ -104,6 +104,9 @@ contract GasSwap is ERC2771Context, ReentrancyGuard, OwnableBase {
|
||||
_permit.s
|
||||
);
|
||||
|
||||
// record token balance in this contract
|
||||
uint256 _balance = IERC20(_permit.token).balanceOf(address(this));
|
||||
|
||||
// transfer token
|
||||
IERC20(_permit.token).safeTransferFrom(_sender, address(this), _permit.value);
|
||||
|
||||
@@ -128,7 +131,7 @@ contract GasSwap is ERC2771Context, ReentrancyGuard, OwnableBase {
|
||||
require(_success, "transfer ETH failed");
|
||||
|
||||
// refund rest token
|
||||
uint256 _dust = IERC20(_permit.token).balanceOf(address(this));
|
||||
uint256 _dust = IERC20(_permit.token).balanceOf(address(this)) - _balance;
|
||||
if (_dust > 0) {
|
||||
IERC20(_permit.token).safeTransfer(_sender, _dust);
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@ interface IFiatToken {
|
||||
* amount is less than or equal to the minter's account balance
|
||||
* @param _amount uint256 the amount of tokens to be burned
|
||||
*/
|
||||
function burn(uint256 _amount) external returns (bool);
|
||||
function burn(uint256 _amount) external;
|
||||
}
|
||||
|
||||
16
contracts/src/interfaces/IMessageTransmitter.sol
Normal file
16
contracts/src/interfaces/IMessageTransmitter.sol
Normal file
@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.16;
|
||||
|
||||
interface IMessageTransmitter {
|
||||
function usedNonces(bytes32 _sourceAndNonce) external view returns (uint256);
|
||||
|
||||
/**
|
||||
* @notice Receives an incoming message, validating the header and passing
|
||||
* the body to application-specific handler.
|
||||
* @param message The message raw bytes
|
||||
* @param signature The message signature
|
||||
* @return success bool, true if successful
|
||||
*/
|
||||
function receiveMessage(bytes calldata message, bytes calldata signature) external returns (bool success);
|
||||
}
|
||||
63
contracts/src/interfaces/ITokenMessenger.sol
Normal file
63
contracts/src/interfaces/ITokenMessenger.sol
Normal file
@@ -0,0 +1,63 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.16;
|
||||
|
||||
interface ITokenMessenger {
|
||||
/**
|
||||
* @notice Deposits and burns tokens from sender to be minted on destination domain. The mint
|
||||
* on the destination domain must be called by `destinationCaller`.
|
||||
* WARNING: if the `destinationCaller` does not represent a valid address as bytes32, then it will not be possible
|
||||
* to broadcast the message on the destination domain. This is an advanced feature, and the standard
|
||||
* depositForBurn() should be preferred for use cases where a specific destination caller is not required.
|
||||
* Emits a `DepositForBurn` event.
|
||||
* @dev reverts if:
|
||||
* - given destinationCaller is zero address
|
||||
* - given burnToken is not supported
|
||||
* - given destinationDomain has no TokenMessenger registered
|
||||
* - transferFrom() reverts. For example, if sender's burnToken balance or approved allowance
|
||||
* to this contract is less than `amount`.
|
||||
* - burn() reverts. For example, if `amount` is 0.
|
||||
* - MessageTransmitter returns false or reverts.
|
||||
* @param amount amount of tokens to burn
|
||||
* @param destinationDomain destination domain
|
||||
* @param mintRecipient address of mint recipient on destination domain
|
||||
* @param burnToken address of contract to burn deposited tokens, on local domain
|
||||
* @param destinationCaller caller on the destination domain, as bytes32
|
||||
* @return nonce unique nonce reserved by message
|
||||
*/
|
||||
function depositForBurnWithCaller(
|
||||
uint256 amount,
|
||||
uint32 destinationDomain,
|
||||
bytes32 mintRecipient,
|
||||
address burnToken,
|
||||
bytes32 destinationCaller
|
||||
) external returns (uint64 nonce);
|
||||
|
||||
/**
|
||||
* @notice Replace a BurnMessage to change the mint recipient and/or
|
||||
* destination caller. Allows the sender of a previous BurnMessage
|
||||
* (created by depositForBurn or depositForBurnWithCaller)
|
||||
* to send a new BurnMessage to replace the original.
|
||||
* The new BurnMessage will reuse the amount and burn token of the original,
|
||||
* without requiring a new deposit.
|
||||
* @dev The new message will reuse the original message's nonce. For a
|
||||
* given nonce, all replacement message(s) and the original message are
|
||||
* valid to broadcast on the destination domain, until the first message
|
||||
* at the nonce confirms, at which point all others are invalidated.
|
||||
* Note: The msg.sender of the replaced message must be the same as the
|
||||
* msg.sender of the original message.
|
||||
* @param originalMessage original message bytes (to replace)
|
||||
* @param originalAttestation original attestation bytes
|
||||
* @param newDestinationCaller the new destination caller, which may be the
|
||||
* same as the original destination caller, a new destination caller, or an empty
|
||||
* destination caller (bytes32(0), indicating that any destination caller is valid.)
|
||||
* @param newMintRecipient the new mint recipient, which may be the same as the
|
||||
* original mint recipient, or different.
|
||||
*/
|
||||
function replaceDepositForBurn(
|
||||
bytes calldata originalMessage,
|
||||
bytes calldata originalAttestation,
|
||||
bytes32 newDestinationCaller,
|
||||
bytes32 newMintRecipient
|
||||
) external;
|
||||
}
|
||||
12
contracts/src/interfaces/IUSDCBurnableSourceBridge.sol
Normal file
12
contracts/src/interfaces/IUSDCBurnableSourceBridge.sol
Normal file
@@ -0,0 +1,12 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.16;
|
||||
|
||||
// Implement this on the source chain (Ethereum).
|
||||
interface IUSDCBurnableSourceBridge {
|
||||
/**
|
||||
* @notice Called by Circle, this executes a burn on the source
|
||||
* chain.
|
||||
*/
|
||||
function burnAllLockedUSDC() external;
|
||||
}
|
||||
11
contracts/src/interfaces/IUSDCDestinationBridge.sol
Normal file
11
contracts/src/interfaces/IUSDCDestinationBridge.sol
Normal file
@@ -0,0 +1,11 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.16;
|
||||
|
||||
// Implement this on the destination chain (Scroll).
|
||||
interface IUSDCDestinationBridge {
|
||||
/**
|
||||
* @notice Called by Circle, this transfers FiatToken roles to the designated owner.
|
||||
*/
|
||||
function transferUSDCRoles(address owner) external;
|
||||
}
|
||||
@@ -103,29 +103,34 @@ abstract contract FeeVault is OwnableBase {
|
||||
receive() external payable {}
|
||||
|
||||
/// @notice Triggers a withdrawal of funds to the L1 fee wallet.
|
||||
function withdraw() external {
|
||||
uint256 value = address(this).balance;
|
||||
|
||||
/// @param _value The amount of ETH to withdraw.
|
||||
function withdraw(uint256 _value) public {
|
||||
require(
|
||||
value >= minWithdrawAmount,
|
||||
_value >= minWithdrawAmount,
|
||||
"FeeVault: withdrawal amount must be greater than minimum withdrawal amount"
|
||||
);
|
||||
|
||||
unchecked {
|
||||
totalProcessed += value;
|
||||
totalProcessed += _value;
|
||||
}
|
||||
|
||||
emit Withdrawal(value, recipient, msg.sender);
|
||||
emit Withdrawal(_value, recipient, msg.sender);
|
||||
|
||||
// no fee provided
|
||||
IL2ScrollMessenger(messenger).sendMessage{value: value}(
|
||||
IL2ScrollMessenger(messenger).sendMessage{value: _value}(
|
||||
recipient,
|
||||
value,
|
||||
_value,
|
||||
bytes(""), // no message (simple eth transfer)
|
||||
0 // _gasLimit can be zero for fee vault.
|
||||
);
|
||||
}
|
||||
|
||||
/// @notice Triggers a withdrawal of all available funds to the L1 fee wallet.
|
||||
function withdraw() external {
|
||||
uint256 value = address(this).balance;
|
||||
withdraw(value);
|
||||
}
|
||||
|
||||
/************************
|
||||
* Restricted Functions *
|
||||
************************/
|
||||
|
||||
95
contracts/src/libraries/gateway/CCTPGatewayBase.sol
Normal file
95
contracts/src/libraries/gateway/CCTPGatewayBase.sol
Normal file
@@ -0,0 +1,95 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import {IMessageTransmitter} from "../../interfaces/IMessageTransmitter.sol";
|
||||
|
||||
import {ScrollGatewayBase} from "./ScrollGatewayBase.sol";
|
||||
|
||||
abstract contract CCTPGatewayBase is ScrollGatewayBase {
|
||||
/*********
|
||||
* Enums *
|
||||
*********/
|
||||
|
||||
enum CCTPMessageStatus {
|
||||
None,
|
||||
Pending,
|
||||
Relayed
|
||||
}
|
||||
|
||||
/*************
|
||||
* Constants *
|
||||
*************/
|
||||
|
||||
/// @notice The address of L1 USDC address.
|
||||
address public immutable l1USDC;
|
||||
|
||||
/// @notice The address of L2 USDC address.
|
||||
address public immutable l2USDC;
|
||||
|
||||
/// @notice The destination domain for layer2.
|
||||
uint32 public immutable destinationDomain;
|
||||
|
||||
/*************
|
||||
* Variables *
|
||||
*************/
|
||||
|
||||
/// @notice The address of TokenMessenger in local domain.
|
||||
address public cctpMessenger;
|
||||
|
||||
/// @notice The address of MessageTransmitter in local domain.
|
||||
address public cctpTransmitter;
|
||||
|
||||
/// @notice Mapping from destination domain CCTP nonce to status.
|
||||
mapping(uint256 => CCTPMessageStatus) public status;
|
||||
|
||||
/***************
|
||||
* Constructor *
|
||||
***************/
|
||||
|
||||
constructor(
|
||||
address _l1USDC,
|
||||
address _l2USDC,
|
||||
uint32 _destinationDomain
|
||||
) {
|
||||
l1USDC = _l1USDC;
|
||||
l2USDC = _l2USDC;
|
||||
destinationDomain = _destinationDomain;
|
||||
}
|
||||
|
||||
function _initialize(address _cctpMessenger, address _cctpTransmitter) internal {
|
||||
cctpMessenger = _cctpMessenger;
|
||||
cctpTransmitter = _cctpTransmitter;
|
||||
}
|
||||
|
||||
/*****************************
|
||||
* Public Mutating Functions *
|
||||
*****************************/
|
||||
|
||||
/// @notice Claim USDC that has been cross chained.
|
||||
/// @param _nonce The nonce of the message from CCTP.
|
||||
/// @param _cctpMessage The message passed to MessageTransmitter contract in CCTP.
|
||||
/// @param _cctpSignature The message passed to MessageTransmitter contract in CCTP.
|
||||
function claimUSDC(
|
||||
uint256 _nonce,
|
||||
bytes calldata _cctpMessage,
|
||||
bytes calldata _cctpSignature
|
||||
) public {
|
||||
// Check `_nonce` match with `_cctpMessage`.
|
||||
// According to the encoding of `_cctpMessage`, the nonce is in bytes 12 to 16.
|
||||
// See here: https://github.com/circlefin/evm-cctp-contracts/blob/master/src/messages/Message.sol#L29
|
||||
uint256 _expectedMessageNonce;
|
||||
assembly {
|
||||
_expectedMessageNonce := and(shr(96, calldataload(_cctpMessage.offset)), 0xffffffffffffffff)
|
||||
}
|
||||
require(_expectedMessageNonce == _nonce, "nonce mismatch");
|
||||
|
||||
require(status[_nonce] == CCTPMessageStatus.Pending, "message not relayed");
|
||||
|
||||
// call transmitter to mint USDC
|
||||
bool _success = IMessageTransmitter(cctpTransmitter).receiveMessage(_cctpMessage, _cctpSignature);
|
||||
require(_success, "call transmitter failed");
|
||||
|
||||
status[_nonce] = CCTPMessageStatus.Relayed;
|
||||
}
|
||||
}
|
||||
391
contracts/src/misc/ERC2771Forwarder.sol
Normal file
391
contracts/src/misc/ERC2771Forwarder.sol
Normal file
@@ -0,0 +1,391 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// @note This file is directly copied from OpenZeppelin's master branch:
|
||||
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/metatx/ERC2771Forwarder.sol
|
||||
// Modifications are made to make it compatible with solidity 0.8.16.
|
||||
|
||||
pragma solidity =0.8.16;
|
||||
|
||||
import {ERC2771Context} from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
|
||||
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
||||
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
|
||||
import {Nonces} from "./Nonces.sol";
|
||||
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
||||
|
||||
/**
|
||||
* @dev A forwarder compatible with ERC2771 contracts. See {ERC2771Context}.
|
||||
*
|
||||
* This forwarder operates on forward requests that include:
|
||||
*
|
||||
* * `from`: An address to operate on behalf of. It is required to be equal to the request signer.
|
||||
* * `to`: The address that should be called.
|
||||
* * `value`: The amount of native token to attach with the requested call.
|
||||
* * `gas`: The amount of gas limit that will be forwarded with the requested call.
|
||||
* * `nonce`: A unique transaction ordering identifier to avoid replayability and request invalidation.
|
||||
* * `deadline`: A timestamp after which the request is not executable anymore.
|
||||
* * `data`: Encoded `msg.data` to send with the requested call.
|
||||
*
|
||||
* Relayers are able to submit batches if they are processing a high volume of requests. With high
|
||||
* throughput, relayers may run into limitations of the chain such as limits on the number of
|
||||
* transactions in the mempool. In these cases the recommendation is to distribute the load among
|
||||
* multiple accounts.
|
||||
*
|
||||
* NOTE: Batching requests includes an optional refund for unused `msg.value` that is achieved by
|
||||
* performing a call with empty calldata. While this is within the bounds of ERC-2771 compliance,
|
||||
* if the refund receiver happens to consider the forwarder a trusted forwarder, it MUST properly
|
||||
* handle `msg.data.length == 0`. `ERC2771Context` in OpenZeppelin Contracts versions prior to 4.9.3
|
||||
* do not handle this properly.
|
||||
*
|
||||
* ==== Security Considerations
|
||||
*
|
||||
* If a relayer submits a forward request, it should be willing to pay up to 100% of the gas amount
|
||||
* specified in the request. This contract does not implement any kind of retribution for this gas,
|
||||
* and it is assumed that there is an out of band incentive for relayers to pay for execution on
|
||||
* behalf of signers. Often, the relayer is operated by a project that will consider it a user
|
||||
* acquisition cost.
|
||||
*
|
||||
* By offering to pay for gas, relayers are at risk of having that gas used by an attacker toward
|
||||
* some other purpose that is not aligned with the expected out of band incentives. If you operate a
|
||||
* relayer, consider whitelisting target contracts and function selectors. When relaying ERC-721 or
|
||||
* ERC-1155 transfers specifically, consider rejecting the use of the `data` field, since it can be
|
||||
* used to execute arbitrary code.
|
||||
*/
|
||||
contract ERC2771Forwarder is EIP712, Nonces {
|
||||
using ECDSA for bytes32;
|
||||
|
||||
struct ForwardRequestData {
|
||||
address from;
|
||||
address to;
|
||||
uint256 value;
|
||||
uint256 gas;
|
||||
uint48 deadline;
|
||||
bytes data;
|
||||
bytes signature;
|
||||
}
|
||||
|
||||
bytes32 internal constant _FORWARD_REQUEST_TYPEHASH =
|
||||
keccak256(
|
||||
"ForwardRequest(address from,address to,uint256 value,uint256 gas,uint256 nonce,uint48 deadline,bytes data)"
|
||||
);
|
||||
|
||||
/**
|
||||
* @dev Emitted when a `ForwardRequest` is executed.
|
||||
*
|
||||
* NOTE: An unsuccessful forward request could be due to an invalid signature, an expired deadline,
|
||||
* or simply a revert in the requested call. The contract guarantees that the relayer is not able to force
|
||||
* the requested call to run out of gas.
|
||||
*/
|
||||
event ExecutedForwardRequest(address indexed signer, uint256 nonce, bool success);
|
||||
|
||||
/**
|
||||
* @dev The request `from` doesn't match with the recovered `signer`.
|
||||
*/
|
||||
error ERC2771ForwarderInvalidSigner(address signer, address from);
|
||||
|
||||
/**
|
||||
* @dev The `requestedValue` doesn't match with the available `msgValue`.
|
||||
*/
|
||||
error ERC2771ForwarderMismatchedValue(uint256 requestedValue, uint256 msgValue);
|
||||
|
||||
/**
|
||||
* @dev The request `deadline` has expired.
|
||||
*/
|
||||
error ERC2771ForwarderExpiredRequest(uint48 deadline);
|
||||
|
||||
/**
|
||||
* @dev The request target doesn't trust the `forwarder`.
|
||||
*/
|
||||
error ERC2771UntrustfulTarget(address target, address forwarder);
|
||||
|
||||
/**
|
||||
* @dev A call to an address target failed. The target may have reverted.
|
||||
*/
|
||||
error FailedInnerCall();
|
||||
|
||||
/**
|
||||
* @dev See {EIP712-constructor}.
|
||||
*/
|
||||
constructor(string memory name) EIP712(name, "1") {}
|
||||
|
||||
/**
|
||||
* @dev Returns `true` if a request is valid for a provided `signature` at the current block timestamp.
|
||||
*
|
||||
* A transaction is considered valid when the target trusts this forwarder, the request hasn't expired
|
||||
* (deadline is not met), and the signer matches the `from` parameter of the signed request.
|
||||
*
|
||||
* NOTE: A request may return false here but it won't cause {executeBatch} to revert if a refund
|
||||
* receiver is provided.
|
||||
*/
|
||||
function verify(ForwardRequestData calldata request) public view virtual returns (bool) {
|
||||
(bool isTrustedForwarder, bool active, bool signerMatch, ) = _validate(request);
|
||||
return isTrustedForwarder && active && signerMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Executes a `request` on behalf of `signature`'s signer using the ERC-2771 protocol. The gas
|
||||
* provided to the requested call may not be exactly the amount requested, but the call will not run
|
||||
* out of gas. Will revert if the request is invalid or the call reverts, in this case the nonce is not consumed.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - The request value should be equal to the provided `msg.value`.
|
||||
* - The request should be valid according to {verify}.
|
||||
*/
|
||||
function execute(ForwardRequestData calldata request) public payable virtual {
|
||||
// We make sure that msg.value and request.value match exactly.
|
||||
// If the request is invalid or the call reverts, this whole function
|
||||
// will revert, ensuring value isn't stuck.
|
||||
if (msg.value != request.value) {
|
||||
revert ERC2771ForwarderMismatchedValue(request.value, msg.value);
|
||||
}
|
||||
|
||||
if (!_execute(request, true)) {
|
||||
revert FailedInnerCall();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Batch version of {execute} with optional refunding and atomic execution.
|
||||
*
|
||||
* In case a batch contains at least one invalid request (see {verify}), the
|
||||
* request will be skipped and the `refundReceiver` parameter will receive back the
|
||||
* unused requested value at the end of the execution. This is done to prevent reverting
|
||||
* the entire batch when a request is invalid or has already been submitted.
|
||||
*
|
||||
* If the `refundReceiver` is the `address(0)`, this function will revert when at least
|
||||
* one of the requests was not valid instead of skipping it. This could be useful if
|
||||
* a batch is required to get executed atomically (at least at the top-level). For example,
|
||||
* refunding (and thus atomicity) can be opt-out if the relayer is using a service that avoids
|
||||
* including reverted transactions.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - The sum of the requests' values should be equal to the provided `msg.value`.
|
||||
* - All of the requests should be valid (see {verify}) when `refundReceiver` is the zero address.
|
||||
*
|
||||
* NOTE: Setting a zero `refundReceiver` guarantees an all-or-nothing requests execution only for
|
||||
* the first-level forwarded calls. In case a forwarded request calls to a contract with another
|
||||
* subcall, the second-level call may revert without the top-level call reverting.
|
||||
*/
|
||||
function executeBatch(ForwardRequestData[] calldata requests, address payable refundReceiver)
|
||||
public
|
||||
payable
|
||||
virtual
|
||||
{
|
||||
bool atomic = refundReceiver == address(0);
|
||||
|
||||
uint256 requestsValue;
|
||||
uint256 refundValue;
|
||||
|
||||
for (uint256 i; i < requests.length; ++i) {
|
||||
requestsValue += requests[i].value;
|
||||
bool success = _execute(requests[i], atomic);
|
||||
if (!success) {
|
||||
refundValue += requests[i].value;
|
||||
}
|
||||
}
|
||||
|
||||
// The batch should revert if there's a mismatched msg.value provided
|
||||
// to avoid request value tampering
|
||||
if (requestsValue != msg.value) {
|
||||
revert ERC2771ForwarderMismatchedValue(requestsValue, msg.value);
|
||||
}
|
||||
|
||||
// Some requests with value were invalid (possibly due to frontrunning).
|
||||
// To avoid leaving ETH in the contract this value is refunded.
|
||||
if (refundValue != 0) {
|
||||
// We know refundReceiver != address(0) && requestsValue == msg.value
|
||||
// meaning we can ensure refundValue is not taken from the original contract's balance
|
||||
// and refundReceiver is a known account.
|
||||
Address.sendValue(refundReceiver, refundValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Validates if the provided request can be executed at current block timestamp with
|
||||
* the given `request.signature` on behalf of `request.signer`.
|
||||
*/
|
||||
function _validate(ForwardRequestData calldata request)
|
||||
internal
|
||||
view
|
||||
virtual
|
||||
returns (
|
||||
bool isTrustedForwarder,
|
||||
bool active,
|
||||
bool signerMatch,
|
||||
address signer
|
||||
)
|
||||
{
|
||||
(bool isValid, address recovered) = _recoverForwardRequestSigner(request);
|
||||
|
||||
return (
|
||||
_isTrustedByTarget(request.to),
|
||||
request.deadline >= block.timestamp,
|
||||
isValid && recovered == request.from,
|
||||
recovered
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns a tuple with the recovered the signer of an EIP712 forward request message hash
|
||||
* and a boolean indicating if the signature is valid.
|
||||
*
|
||||
* NOTE: The signature is considered valid if {ECDSA-tryRecover} indicates no recover error for it.
|
||||
*/
|
||||
function _recoverForwardRequestSigner(ForwardRequestData calldata request)
|
||||
internal
|
||||
view
|
||||
virtual
|
||||
returns (bool, address)
|
||||
{
|
||||
(address recovered, ECDSA.RecoverError err) = _hashTypedDataV4(
|
||||
keccak256(
|
||||
abi.encode(
|
||||
_FORWARD_REQUEST_TYPEHASH,
|
||||
request.from,
|
||||
request.to,
|
||||
request.value,
|
||||
request.gas,
|
||||
nonces(request.from),
|
||||
request.deadline,
|
||||
keccak256(request.data)
|
||||
)
|
||||
)
|
||||
).tryRecover(request.signature);
|
||||
|
||||
return (err == ECDSA.RecoverError.NoError, recovered);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Validates and executes a signed request returning the request call `success` value.
|
||||
*
|
||||
* Internal function without msg.value validation.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - The caller must have provided enough gas to forward with the call.
|
||||
* - The request must be valid (see {verify}) if the `requireValidRequest` is true.
|
||||
*
|
||||
* Emits an {ExecutedForwardRequest} event.
|
||||
*
|
||||
* IMPORTANT: Using this function doesn't check that all the `msg.value` was sent, potentially
|
||||
* leaving value stuck in the contract.
|
||||
*/
|
||||
function _execute(ForwardRequestData calldata request, bool requireValidRequest)
|
||||
internal
|
||||
virtual
|
||||
returns (bool success)
|
||||
{
|
||||
(bool isTrustedForwarder, bool active, bool signerMatch, address signer) = _validate(request);
|
||||
|
||||
// Need to explicitly specify if a revert is required since non-reverting is default for
|
||||
// batches and reversion is opt-in since it could be useful in some scenarios
|
||||
if (requireValidRequest) {
|
||||
if (!isTrustedForwarder) {
|
||||
revert ERC2771UntrustfulTarget(request.to, address(this));
|
||||
}
|
||||
|
||||
if (!active) {
|
||||
revert ERC2771ForwarderExpiredRequest(request.deadline);
|
||||
}
|
||||
|
||||
if (!signerMatch) {
|
||||
revert ERC2771ForwarderInvalidSigner(signer, request.from);
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore an invalid request because requireValidRequest = false
|
||||
if (isTrustedForwarder && signerMatch && active) {
|
||||
// Nonce should be used before the call to prevent reusing by reentrancy
|
||||
uint256 currentNonce = _useNonce(signer);
|
||||
|
||||
uint256 reqGas = request.gas;
|
||||
address to = request.to;
|
||||
uint256 value = request.value;
|
||||
bytes memory data = abi.encodePacked(request.data, request.from);
|
||||
|
||||
uint256 gasLeft;
|
||||
|
||||
assembly {
|
||||
success := call(reqGas, to, value, add(data, 0x20), mload(data), 0, 0)
|
||||
gasLeft := gas()
|
||||
}
|
||||
|
||||
_checkForwardedGas(gasLeft, request);
|
||||
|
||||
emit ExecutedForwardRequest(signer, currentNonce, success);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns whether the target trusts this forwarder.
|
||||
*
|
||||
* This function performs a static call to the target contract calling the
|
||||
* {ERC2771Context-isTrustedForwarder} function.
|
||||
*/
|
||||
function _isTrustedByTarget(address target) private view returns (bool) {
|
||||
bytes memory encodedParams = abi.encodeCall(ERC2771Context.isTrustedForwarder, (address(this)));
|
||||
|
||||
bool success;
|
||||
uint256 returnSize;
|
||||
uint256 returnValue;
|
||||
/// @solidity memory-safe-assembly
|
||||
assembly {
|
||||
// Perform the staticcal and save the result in the scratch space.
|
||||
// | Location | Content | Content (Hex) |
|
||||
// |-----------|----------|--------------------------------------------------------------------|
|
||||
// | | | result ↓ |
|
||||
// | 0x00:0x1F | selector | 0x0000000000000000000000000000000000000000000000000000000000000001 |
|
||||
success := staticcall(gas(), target, add(encodedParams, 0x20), mload(encodedParams), 0, 0x20)
|
||||
returnSize := returndatasize()
|
||||
returnValue := mload(0)
|
||||
}
|
||||
|
||||
return success && returnSize >= 0x20 && returnValue > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Checks if the requested gas was correctly forwarded to the callee.
|
||||
*
|
||||
* As a consequence of https://eips.ethereum.org/EIPS/eip-150[EIP-150]:
|
||||
* - At most `gasleft() - floor(gasleft() / 64)` is forwarded to the callee.
|
||||
* - At least `floor(gasleft() / 64)` is kept in the caller.
|
||||
*
|
||||
* It reverts consuming all the available gas if the forwarded gas is not the requested gas.
|
||||
*
|
||||
* IMPORTANT: The `gasLeft` parameter should be measured exactly at the end of the forwarded call.
|
||||
* Any gas consumed in between will make room for bypassing this check.
|
||||
*/
|
||||
function _checkForwardedGas(uint256 gasLeft, ForwardRequestData calldata request) private pure {
|
||||
// To avoid insufficient gas griefing attacks, as referenced in https://ronan.eth.limo/blog/ethereum-gas-dangers/
|
||||
//
|
||||
// A malicious relayer can attempt to shrink the gas forwarded so that the underlying call reverts out-of-gas
|
||||
// but the forwarding itself still succeeds. In order to make sure that the subcall received sufficient gas,
|
||||
// we will inspect gasleft() after the forwarding.
|
||||
//
|
||||
// Let X be the gas available before the subcall, such that the subcall gets at most X * 63 / 64.
|
||||
// We can't know X after CALL dynamic costs, but we want it to be such that X * 63 / 64 >= req.gas.
|
||||
// Let Y be the gas used in the subcall. gasleft() measured immediately after the subcall will be gasleft() = X - Y.
|
||||
// If the subcall ran out of gas, then Y = X * 63 / 64 and gasleft() = X - Y = X / 64.
|
||||
// Under this assumption req.gas / 63 > gasleft() is true is true if and only if
|
||||
// req.gas / 63 > X / 64, or equivalently req.gas > X * 63 / 64.
|
||||
// This means that if the subcall runs out of gas we are able to detect that insufficient gas was passed.
|
||||
//
|
||||
// We will now also see that req.gas / 63 > gasleft() implies that req.gas >= X * 63 / 64.
|
||||
// The contract guarantees Y <= req.gas, thus gasleft() = X - Y >= X - req.gas.
|
||||
// - req.gas / 63 > gasleft()
|
||||
// - req.gas / 63 >= X - req.gas
|
||||
// - req.gas >= X * 63 / 64
|
||||
// In other words if req.gas < X * 63 / 64 then req.gas / 63 <= gasleft(), thus if the relayer behaves honestly
|
||||
// the forwarding does not revert.
|
||||
if (gasLeft < request.gas / 63) {
|
||||
// We explicitly trigger invalid opcode to consume all gas and bubble-up the effects, since
|
||||
// neither revert or assert consume all gas since Solidity 0.8.20
|
||||
// https://docs.soliditylang.org/en/v0.8.20/control-structures.html#panic-via-assert-and-error-via-require
|
||||
/// @solidity memory-safe-assembly
|
||||
assembly {
|
||||
invalid()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
51
contracts/src/misc/Nonces.sol
Normal file
51
contracts/src/misc/Nonces.sol
Normal file
@@ -0,0 +1,51 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// @note This file is directly copied from OpenZeppelin's master branch:
|
||||
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Nonces.sol
|
||||
// Modifications are made to make it compatible with solidity 0.8.16.
|
||||
|
||||
pragma solidity ^0.8.16;
|
||||
|
||||
/**
|
||||
* @dev Provides tracking nonces for addresses. Nonces will only increment.
|
||||
*/
|
||||
abstract contract Nonces {
|
||||
/**
|
||||
* @dev The nonce used for an `account` is not the expected current nonce.
|
||||
*/
|
||||
error InvalidAccountNonce(address account, uint256 currentNonce);
|
||||
|
||||
mapping(address => uint256) private _nonces;
|
||||
|
||||
/**
|
||||
* @dev Returns an the next unused nonce for an address.
|
||||
*/
|
||||
function nonces(address owner) public view virtual returns (uint256) {
|
||||
return _nonces[owner];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Consumes a nonce.
|
||||
*
|
||||
* Returns the current value and increments nonce.
|
||||
*/
|
||||
function _useNonce(address owner) internal virtual returns (uint256) {
|
||||
// For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be
|
||||
// decremented or reset. This guarantees that the nonce never overflows.
|
||||
unchecked {
|
||||
// It is important to do x++ and not ++x here.
|
||||
return _nonces[owner]++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {_useNonce} but checking that `nonce` is the next valid for `owner`.
|
||||
*/
|
||||
function _useCheckedNonce(address owner, uint256 nonce) internal virtual returns (uint256) {
|
||||
uint256 current = _useNonce(owner);
|
||||
if (nonce != current) {
|
||||
revert InvalidAccountNonce(owner, current);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
pragma solidity =0.8.16;
|
||||
|
||||
import {AccessControlEnumerable} from "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
|
||||
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
||||
@@ -10,6 +10,22 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet
|
||||
contract ScrollOwner is AccessControlEnumerable {
|
||||
using EnumerableSet for EnumerableSet.Bytes32Set;
|
||||
|
||||
/**********
|
||||
* Events *
|
||||
**********/
|
||||
|
||||
/// @notice Emitted when the access to target contract is granted.
|
||||
/// @param role The role to grant access.
|
||||
/// @param target The address of target contract.
|
||||
/// @param selectors The list of function selectors to grant access.
|
||||
event GrantAccess(bytes32 indexed role, address indexed target, bytes4[] selectors);
|
||||
|
||||
/// @notice Emitted when the access to target contract is revoked.
|
||||
/// @param role The role to revoke access.
|
||||
/// @param target The address of target contract.
|
||||
/// @param selectors The list of function selectors to revoke access.
|
||||
event RevokeAccess(bytes32 indexed role, address indexed target, bytes4[] selectors);
|
||||
|
||||
/*************
|
||||
* Variables *
|
||||
*************/
|
||||
@@ -69,7 +85,7 @@ contract ScrollOwner is AccessControlEnumerable {
|
||||
uint256 _value,
|
||||
bytes calldata _data,
|
||||
bytes32 _role
|
||||
) public payable onlyRole(_role) hasAccess(_target, bytes4(_data[0:4]), _role) {
|
||||
) external payable onlyRole(_role) hasAccess(_target, bytes4(_data[0:4]), _role) {
|
||||
_execute(_target, _value, _data);
|
||||
}
|
||||
|
||||
@@ -95,10 +111,14 @@ contract ScrollOwner is AccessControlEnumerable {
|
||||
for (uint256 i = 0; i < _selectors.length; i++) {
|
||||
targetAccess[_target][_selectors[i]].add(_role);
|
||||
}
|
||||
|
||||
emit GrantAccess(_role, _target, _selectors);
|
||||
} else {
|
||||
for (uint256 i = 0; i < _selectors.length; i++) {
|
||||
targetAccess[_target][_selectors[i]].remove(_role);
|
||||
}
|
||||
|
||||
emit RevokeAccess(_role, _target, _selectors);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,9 +134,9 @@ contract ScrollOwner is AccessControlEnumerable {
|
||||
address _target,
|
||||
uint256 _value,
|
||||
bytes calldata _data
|
||||
) internal {
|
||||
) private {
|
||||
// solhint-disable-next-line avoid-low-level-calls
|
||||
(bool success, ) = address(_target).call{value: _value}(_data);
|
||||
(bool success, ) = _target.call{value: _value}(_data);
|
||||
if (!success) {
|
||||
// solhint-disable-next-line no-inline-assembly
|
||||
assembly {
|
||||
|
||||
@@ -15,7 +15,7 @@ contract ETHRateLimiter is Ownable, IETHRateLimiter {
|
||||
* Structs *
|
||||
***********/
|
||||
|
||||
struct TokenAmount {
|
||||
struct ETHAmount {
|
||||
// The timestamp when the amount is updated.
|
||||
uint48 lastUpdateTs;
|
||||
// The ETH limit in wei.
|
||||
@@ -39,8 +39,8 @@ contract ETHRateLimiter is Ownable, IETHRateLimiter {
|
||||
* Variables *
|
||||
*************/
|
||||
|
||||
/// @notice The token amount used in current period.
|
||||
TokenAmount public currentPeriod;
|
||||
/// @notice The ETH amount used in current period.
|
||||
ETHAmount public currentPeriod;
|
||||
|
||||
/***************
|
||||
* Constructor *
|
||||
@@ -55,14 +55,10 @@ contract ETHRateLimiter is Ownable, IETHRateLimiter {
|
||||
revert PeriodIsZero();
|
||||
}
|
||||
|
||||
if (_totalLimit == 0) {
|
||||
revert TotalLimitIsZero();
|
||||
}
|
||||
|
||||
periodDuration = _periodDuration;
|
||||
spender = _spender;
|
||||
|
||||
currentPeriod.limit = _totalLimit;
|
||||
_updateTotalLimit(_totalLimit);
|
||||
}
|
||||
|
||||
/*****************************
|
||||
@@ -80,9 +76,9 @@ contract ETHRateLimiter is Ownable, IETHRateLimiter {
|
||||
|
||||
// check total limit
|
||||
uint256 _currentTotalAmount;
|
||||
TokenAmount memory _currentPeriod = currentPeriod;
|
||||
ETHAmount memory _currentPeriod = currentPeriod;
|
||||
|
||||
if (_currentPeriod.lastUpdateTs < _currentPeriodStart) {
|
||||
if (uint256(_currentPeriod.lastUpdateTs) < _currentPeriodStart) {
|
||||
_currentTotalAmount = _amount;
|
||||
} else {
|
||||
_currentTotalAmount = _currentPeriod.amount + _amount;
|
||||
@@ -101,9 +97,19 @@ contract ETHRateLimiter is Ownable, IETHRateLimiter {
|
||||
* Restricted Functions *
|
||||
************************/
|
||||
|
||||
/// @notice Update the total token amount limit.
|
||||
/// @notice Update the total ETH amount limit.
|
||||
/// @param _newTotalLimit The new total limit.
|
||||
function updateTotalLimit(uint104 _newTotalLimit) external onlyOwner {
|
||||
_updateTotalLimit(_newTotalLimit);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* Internal Functions *
|
||||
**********************/
|
||||
|
||||
/// @dev Internal function to update the total token amount limit.
|
||||
/// @param _newTotalLimit The new total limit.
|
||||
function _updateTotalLimit(uint104 _newTotalLimit) private {
|
||||
if (_newTotalLimit == 0) {
|
||||
revert TotalLimitIsZero();
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ contract TokenRateLimiter is AccessControlEnumerable, ITokenRateLimiter {
|
||||
revert PeriodIsZero();
|
||||
}
|
||||
|
||||
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
|
||||
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
|
||||
|
||||
periodDuration = _periodDuration;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ contract TokenRateLimiter is AccessControlEnumerable, ITokenRateLimiter {
|
||||
// check total limit, `0` means no limit at all.
|
||||
uint256 _currentTotalAmount;
|
||||
TokenAmount memory _currentPeriod = currentPeriod[_token];
|
||||
if (_currentPeriod.lastUpdateTs < _currentPeriodStart) {
|
||||
if (uint256(_currentPeriod.lastUpdateTs) < _currentPeriodStart) {
|
||||
_currentTotalAmount = _amount;
|
||||
} else {
|
||||
_currentTotalAmount = _currentPeriod.amount + _amount;
|
||||
|
||||
528
contracts/src/test/L1USDCGateway.t.sol
Normal file
528
contracts/src/test/L1USDCGateway.t.sol
Normal file
@@ -0,0 +1,528 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";
|
||||
|
||||
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
|
||||
|
||||
import {L1GatewayRouter} from "../L1/gateways/L1GatewayRouter.sol";
|
||||
import {IL1ERC20Gateway, L1USDCGateway} from "../L1/gateways/usdc/L1USDCGateway.sol";
|
||||
import {IL1ScrollMessenger} from "../L1/IL1ScrollMessenger.sol";
|
||||
import {IL2ERC20Gateway, L2USDCGateway} from "../L2/gateways/usdc/L2USDCGateway.sol";
|
||||
import {AddressAliasHelper} from "../libraries/common/AddressAliasHelper.sol";
|
||||
|
||||
import {L1GatewayTestBase} from "./L1GatewayTestBase.t.sol";
|
||||
import {MockScrollMessenger} from "./mocks/MockScrollMessenger.sol";
|
||||
import {MockGatewayRecipient} from "./mocks/MockGatewayRecipient.sol";
|
||||
|
||||
contract L1USDCGatewayTest is L1GatewayTestBase {
|
||||
// from L1USDCGateway
|
||||
event FinalizeWithdrawERC20(
|
||||
address indexed _l1Token,
|
||||
address indexed _l2Token,
|
||||
address indexed _from,
|
||||
address _to,
|
||||
uint256 _amount,
|
||||
bytes _data
|
||||
);
|
||||
event DepositERC20(
|
||||
address indexed _l1Token,
|
||||
address indexed _l2Token,
|
||||
address indexed _from,
|
||||
address _to,
|
||||
uint256 _amount,
|
||||
bytes _data
|
||||
);
|
||||
|
||||
MockERC20 private l1USDC;
|
||||
MockERC20 private l2USDC;
|
||||
|
||||
L1USDCGateway private gateway;
|
||||
L1GatewayRouter private router;
|
||||
|
||||
L2USDCGateway private counterpartGateway;
|
||||
|
||||
function setUp() public {
|
||||
setUpBase();
|
||||
|
||||
// Deploy tokens
|
||||
l1USDC = new MockERC20("USDC", "USDC", 6);
|
||||
l2USDC = new MockERC20("USDC", "USDC", 6);
|
||||
|
||||
// Deploy L1 contracts
|
||||
gateway = _deployGateway();
|
||||
router = L1GatewayRouter(address(new ERC1967Proxy(address(new L1GatewayRouter()), new bytes(0))));
|
||||
|
||||
// Deploy L2 contracts
|
||||
counterpartGateway = new L2USDCGateway(address(l1USDC), address(l2USDC));
|
||||
|
||||
// Initialize L1 contracts
|
||||
gateway.initialize(address(counterpartGateway), address(router), address(l1Messenger));
|
||||
router.initialize(address(0), address(gateway));
|
||||
|
||||
// Prepare token balances
|
||||
l1USDC.mint(address(this), type(uint128).max);
|
||||
l1USDC.approve(address(gateway), type(uint256).max);
|
||||
l1USDC.approve(address(router), type(uint256).max);
|
||||
}
|
||||
|
||||
function testInitialized() public {
|
||||
assertEq(address(counterpartGateway), gateway.counterpart());
|
||||
assertEq(address(router), gateway.router());
|
||||
assertEq(address(l1Messenger), gateway.messenger());
|
||||
assertEq(address(l1USDC), gateway.l1USDC());
|
||||
assertEq(address(l2USDC), gateway.l2USDC());
|
||||
assertEq(address(l2USDC), gateway.getL2ERC20Address(address(l1USDC)));
|
||||
assertEq(0, gateway.totalBridgedUSDC());
|
||||
|
||||
hevm.expectRevert("Initializable: contract is already initialized");
|
||||
gateway.initialize(address(counterpartGateway), address(router), address(l1Messenger));
|
||||
}
|
||||
|
||||
function testDepositPaused() public {
|
||||
// non-owner call pause, should revert
|
||||
hevm.startPrank(address(1));
|
||||
hevm.expectRevert("Ownable: caller is not the owner");
|
||||
gateway.pauseDeposit(false);
|
||||
hevm.expectRevert("Ownable: caller is not the owner");
|
||||
gateway.pauseDeposit(true);
|
||||
hevm.stopPrank();
|
||||
|
||||
// pause deposit
|
||||
gateway.pauseDeposit(true);
|
||||
|
||||
// deposit paused, should revert
|
||||
hevm.expectRevert("deposit paused");
|
||||
gateway.depositERC20(address(l1USDC), 1, 0);
|
||||
hevm.expectRevert("deposit paused");
|
||||
gateway.depositERC20(address(l1USDC), address(this), 1, 0);
|
||||
hevm.expectRevert("deposit paused");
|
||||
gateway.depositERC20AndCall(address(l1USDC), address(this), 1, new bytes(0), 0);
|
||||
}
|
||||
|
||||
function testPauseWithdraw() public {
|
||||
// non-owner call pause, should revert
|
||||
hevm.startPrank(address(1));
|
||||
hevm.expectRevert("Ownable: caller is not the owner");
|
||||
gateway.pauseWithdraw(false);
|
||||
hevm.expectRevert("Ownable: caller is not the owner");
|
||||
gateway.pauseWithdraw(true);
|
||||
hevm.stopPrank();
|
||||
}
|
||||
|
||||
function testDepositERC20(
|
||||
uint256 amount,
|
||||
uint256 gasLimit,
|
||||
uint256 feePerGas
|
||||
) public {
|
||||
_depositERC20(false, amount, gasLimit, feePerGas);
|
||||
}
|
||||
|
||||
function testDepositERC20WithRecipient(
|
||||
uint256 amount,
|
||||
address recipient,
|
||||
uint256 gasLimit,
|
||||
uint256 feePerGas
|
||||
) public {
|
||||
_depositERC20WithRecipient(false, amount, recipient, gasLimit, feePerGas);
|
||||
}
|
||||
|
||||
function testRouterDepositERC20(
|
||||
uint256 amount,
|
||||
uint256 gasLimit,
|
||||
uint256 feePerGas
|
||||
) public {
|
||||
_depositERC20(true, amount, gasLimit, feePerGas);
|
||||
}
|
||||
|
||||
function testRouterDepositERC20WithRecipient(
|
||||
uint256 amount,
|
||||
address recipient,
|
||||
uint256 gasLimit,
|
||||
uint256 feePerGas
|
||||
) public {
|
||||
_depositERC20WithRecipient(true, amount, recipient, gasLimit, feePerGas);
|
||||
}
|
||||
|
||||
function testFinalizeWithdrawERC20FailedMocking(
|
||||
address sender,
|
||||
address recipient,
|
||||
uint256 amount,
|
||||
bytes memory dataToCall
|
||||
) public {
|
||||
amount = bound(amount, 1, 100000);
|
||||
|
||||
// revert when caller is not messenger
|
||||
hevm.expectRevert("only messenger can call");
|
||||
gateway.finalizeWithdrawERC20(address(l1USDC), address(l2USDC), sender, recipient, amount, dataToCall);
|
||||
|
||||
MockScrollMessenger mockMessenger = new MockScrollMessenger();
|
||||
gateway = _deployGateway();
|
||||
gateway.initialize(address(counterpartGateway), address(router), address(mockMessenger));
|
||||
|
||||
// only call by conterpart
|
||||
hevm.expectRevert("only call by counterpart");
|
||||
mockMessenger.callTarget(
|
||||
address(gateway),
|
||||
abi.encodeWithSelector(
|
||||
gateway.finalizeWithdrawERC20.selector,
|
||||
address(l1USDC),
|
||||
address(l2USDC),
|
||||
sender,
|
||||
recipient,
|
||||
amount,
|
||||
dataToCall
|
||||
)
|
||||
);
|
||||
|
||||
mockMessenger.setXDomainMessageSender(address(counterpartGateway));
|
||||
|
||||
// nonzero msg.value
|
||||
hevm.expectRevert("nonzero msg.value");
|
||||
mockMessenger.callTarget{value: 1}(
|
||||
address(gateway),
|
||||
abi.encodeWithSelector(
|
||||
gateway.finalizeWithdrawERC20.selector,
|
||||
address(l1USDC),
|
||||
address(l2USDC),
|
||||
sender,
|
||||
recipient,
|
||||
amount,
|
||||
dataToCall
|
||||
)
|
||||
);
|
||||
|
||||
// l1 token not USDC
|
||||
hevm.expectRevert("l1 token not USDC");
|
||||
mockMessenger.callTarget(
|
||||
address(gateway),
|
||||
abi.encodeWithSelector(
|
||||
gateway.finalizeWithdrawERC20.selector,
|
||||
address(l2USDC),
|
||||
address(l2USDC),
|
||||
sender,
|
||||
recipient,
|
||||
amount,
|
||||
dataToCall
|
||||
)
|
||||
);
|
||||
|
||||
// l2 token not USDC
|
||||
hevm.expectRevert("l2 token not USDC");
|
||||
mockMessenger.callTarget(
|
||||
address(gateway),
|
||||
abi.encodeWithSelector(
|
||||
gateway.finalizeWithdrawERC20.selector,
|
||||
address(l1USDC),
|
||||
address(l1USDC),
|
||||
sender,
|
||||
recipient,
|
||||
amount,
|
||||
dataToCall
|
||||
)
|
||||
);
|
||||
|
||||
// withdraw paused
|
||||
gateway.pauseWithdraw(true);
|
||||
hevm.expectRevert("withdraw paused");
|
||||
mockMessenger.callTarget(
|
||||
address(gateway),
|
||||
abi.encodeWithSelector(
|
||||
gateway.finalizeWithdrawERC20.selector,
|
||||
address(l1USDC),
|
||||
address(l2USDC),
|
||||
sender,
|
||||
recipient,
|
||||
amount,
|
||||
dataToCall
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function testFinalizeWithdrawERC20Failed(
|
||||
address sender,
|
||||
address recipient,
|
||||
uint256 amount,
|
||||
bytes memory dataToCall
|
||||
) public {
|
||||
// blacklist some addresses
|
||||
hevm.assume(recipient != address(0));
|
||||
hevm.assume(recipient != address(gateway));
|
||||
|
||||
amount = bound(amount, 1, l1USDC.balanceOf(address(this)));
|
||||
|
||||
// deposit some USDC to L1ScrollMessenger
|
||||
gateway.depositERC20(address(l1USDC), amount, 0);
|
||||
|
||||
// do finalize withdraw usdc
|
||||
bytes memory message = abi.encodeWithSelector(
|
||||
IL1ERC20Gateway.finalizeWithdrawERC20.selector,
|
||||
address(l1USDC),
|
||||
address(l2USDC),
|
||||
sender,
|
||||
recipient,
|
||||
amount,
|
||||
dataToCall
|
||||
);
|
||||
bytes memory xDomainCalldata = abi.encodeWithSignature(
|
||||
"relayMessage(address,address,uint256,uint256,bytes)",
|
||||
address(uint160(address(counterpartGateway)) + 1),
|
||||
address(gateway),
|
||||
0,
|
||||
0,
|
||||
message
|
||||
);
|
||||
|
||||
prepareL2MessageRoot(keccak256(xDomainCalldata));
|
||||
|
||||
IL1ScrollMessenger.L2MessageProof memory proof;
|
||||
proof.batchIndex = rollup.lastFinalizedBatchIndex();
|
||||
|
||||
// conterpart is not L2USDCGateway
|
||||
// emit FailedRelayedMessage from L1ScrollMessenger
|
||||
hevm.expectEmit(true, false, false, true);
|
||||
emit FailedRelayedMessage(keccak256(xDomainCalldata));
|
||||
|
||||
uint256 gatewayBalance = l1USDC.balanceOf(address(gateway));
|
||||
uint256 recipientBalance = l1USDC.balanceOf(recipient);
|
||||
assertBoolEq(false, l1Messenger.isL2MessageExecuted(keccak256(xDomainCalldata)));
|
||||
l1Messenger.relayMessageWithProof(
|
||||
address(uint160(address(counterpartGateway)) + 1),
|
||||
address(gateway),
|
||||
0,
|
||||
0,
|
||||
message,
|
||||
proof
|
||||
);
|
||||
assertEq(gatewayBalance, l1USDC.balanceOf(address(gateway)));
|
||||
assertEq(recipientBalance, l1USDC.balanceOf(recipient));
|
||||
assertBoolEq(false, l1Messenger.isL2MessageExecuted(keccak256(xDomainCalldata)));
|
||||
}
|
||||
|
||||
function testFinalizeWithdrawERC20(
|
||||
address sender,
|
||||
uint256 amount,
|
||||
bytes memory dataToCall
|
||||
) public {
|
||||
MockGatewayRecipient recipient = new MockGatewayRecipient();
|
||||
|
||||
amount = bound(amount, 1, l1USDC.balanceOf(address(this)));
|
||||
|
||||
// deposit some USDC to gateway
|
||||
gateway.depositERC20(address(l1USDC), amount, 0);
|
||||
|
||||
// do finalize withdraw usdc
|
||||
bytes memory message = abi.encodeWithSelector(
|
||||
IL1ERC20Gateway.finalizeWithdrawERC20.selector,
|
||||
address(l1USDC),
|
||||
address(l2USDC),
|
||||
sender,
|
||||
address(recipient),
|
||||
amount,
|
||||
dataToCall
|
||||
);
|
||||
bytes memory xDomainCalldata = abi.encodeWithSignature(
|
||||
"relayMessage(address,address,uint256,uint256,bytes)",
|
||||
address(counterpartGateway),
|
||||
address(gateway),
|
||||
0,
|
||||
0,
|
||||
message
|
||||
);
|
||||
|
||||
prepareL2MessageRoot(keccak256(xDomainCalldata));
|
||||
|
||||
IL1ScrollMessenger.L2MessageProof memory proof;
|
||||
proof.batchIndex = rollup.lastFinalizedBatchIndex();
|
||||
|
||||
// emit FinalizeWithdrawERC20 from L1USDCGateway
|
||||
{
|
||||
hevm.expectEmit(true, true, true, true);
|
||||
emit FinalizeWithdrawERC20(
|
||||
address(l1USDC),
|
||||
address(l2USDC),
|
||||
sender,
|
||||
address(recipient),
|
||||
amount,
|
||||
dataToCall
|
||||
);
|
||||
}
|
||||
|
||||
// emit RelayedMessage from L1ScrollMessenger
|
||||
{
|
||||
hevm.expectEmit(true, false, false, true);
|
||||
emit RelayedMessage(keccak256(xDomainCalldata));
|
||||
}
|
||||
|
||||
uint256 gatewayBalance = l1USDC.balanceOf(address(gateway));
|
||||
uint256 totalBridgedUSDCBefore = gateway.totalBridgedUSDC();
|
||||
uint256 recipientBalance = l1USDC.balanceOf(address(recipient));
|
||||
assertBoolEq(false, l1Messenger.isL2MessageExecuted(keccak256(xDomainCalldata)));
|
||||
l1Messenger.relayMessageWithProof(address(counterpartGateway), address(gateway), 0, 0, message, proof);
|
||||
assertEq(gatewayBalance - amount, l1USDC.balanceOf(address(gateway)));
|
||||
assertEq(totalBridgedUSDCBefore - amount, gateway.totalBridgedUSDC());
|
||||
assertEq(recipientBalance + amount, l1USDC.balanceOf(address(recipient)));
|
||||
assertBoolEq(true, l1Messenger.isL2MessageExecuted(keccak256(xDomainCalldata)));
|
||||
}
|
||||
|
||||
function _depositERC20(
|
||||
bool useRouter,
|
||||
uint256 amount,
|
||||
uint256 gasLimit,
|
||||
uint256 feePerGas
|
||||
) private {
|
||||
amount = bound(amount, 0, l1USDC.balanceOf(address(this)));
|
||||
gasLimit = bound(gasLimit, 0, 1000000);
|
||||
feePerGas = bound(feePerGas, 0, 1000);
|
||||
|
||||
gasOracle.setL2BaseFee(feePerGas);
|
||||
|
||||
uint256 feeToPay = feePerGas * gasLimit;
|
||||
bytes memory message = abi.encodeWithSelector(
|
||||
IL2ERC20Gateway.finalizeDepositERC20.selector,
|
||||
address(l1USDC),
|
||||
address(l2USDC),
|
||||
address(this),
|
||||
address(this),
|
||||
amount,
|
||||
new bytes(0)
|
||||
);
|
||||
bytes memory xDomainCalldata = abi.encodeWithSignature(
|
||||
"relayMessage(address,address,uint256,uint256,bytes)",
|
||||
address(gateway),
|
||||
address(counterpartGateway),
|
||||
0,
|
||||
0,
|
||||
message
|
||||
);
|
||||
|
||||
if (amount == 0) {
|
||||
hevm.expectRevert("deposit zero amount");
|
||||
if (useRouter) {
|
||||
router.depositERC20{value: feeToPay + extraValue}(address(l1USDC), amount, gasLimit);
|
||||
} else {
|
||||
gateway.depositERC20{value: feeToPay + extraValue}(address(l1USDC), amount, gasLimit);
|
||||
}
|
||||
} else {
|
||||
// token is not l1USDC
|
||||
hevm.expectRevert("only USDC is allowed");
|
||||
gateway.depositERC20(address(l2USDC), amount, gasLimit);
|
||||
|
||||
// emit QueueTransaction from L1MessageQueue
|
||||
{
|
||||
hevm.expectEmit(true, true, false, true);
|
||||
address sender = AddressAliasHelper.applyL1ToL2Alias(address(l1Messenger));
|
||||
emit QueueTransaction(sender, address(l2Messenger), 0, 0, gasLimit, xDomainCalldata);
|
||||
}
|
||||
|
||||
// emit SentMessage from L1ScrollMessenger
|
||||
{
|
||||
hevm.expectEmit(true, true, false, true);
|
||||
emit SentMessage(address(gateway), address(counterpartGateway), 0, 0, gasLimit, message);
|
||||
}
|
||||
|
||||
// emit DepositERC20 from L1USDCGateway
|
||||
hevm.expectEmit(true, true, true, true);
|
||||
emit DepositERC20(address(l1USDC), address(l2USDC), address(this), address(this), amount, new bytes(0));
|
||||
|
||||
uint256 gatewayBalance = l1USDC.balanceOf(address(gateway));
|
||||
uint256 totalBridgedUSDCBefore = gateway.totalBridgedUSDC();
|
||||
uint256 feeVaultBalance = address(feeVault).balance;
|
||||
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
|
||||
if (useRouter) {
|
||||
router.depositERC20{value: feeToPay + extraValue}(address(l1USDC), amount, gasLimit);
|
||||
} else {
|
||||
gateway.depositERC20{value: feeToPay + extraValue}(address(l1USDC), amount, gasLimit);
|
||||
}
|
||||
assertEq(amount + gatewayBalance, l1USDC.balanceOf(address(gateway)));
|
||||
assertEq(amount + totalBridgedUSDCBefore, gateway.totalBridgedUSDC());
|
||||
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
|
||||
assertBoolEq(true, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
|
||||
}
|
||||
}
|
||||
|
||||
function _depositERC20WithRecipient(
|
||||
bool useRouter,
|
||||
uint256 amount,
|
||||
address recipient,
|
||||
uint256 gasLimit,
|
||||
uint256 feePerGas
|
||||
) private {
|
||||
amount = bound(amount, 0, l1USDC.balanceOf(address(this)));
|
||||
gasLimit = bound(gasLimit, 0, 1000000);
|
||||
feePerGas = bound(feePerGas, 0, 1000);
|
||||
|
||||
gasOracle.setL2BaseFee(feePerGas);
|
||||
|
||||
uint256 feeToPay = feePerGas * gasLimit;
|
||||
bytes memory message = abi.encodeWithSelector(
|
||||
IL2ERC20Gateway.finalizeDepositERC20.selector,
|
||||
address(l1USDC),
|
||||
address(l2USDC),
|
||||
address(this),
|
||||
recipient,
|
||||
amount,
|
||||
new bytes(0)
|
||||
);
|
||||
bytes memory xDomainCalldata = abi.encodeWithSignature(
|
||||
"relayMessage(address,address,uint256,uint256,bytes)",
|
||||
address(gateway),
|
||||
address(counterpartGateway),
|
||||
0,
|
||||
0,
|
||||
message
|
||||
);
|
||||
|
||||
if (amount == 0) {
|
||||
hevm.expectRevert("deposit zero amount");
|
||||
if (useRouter) {
|
||||
router.depositERC20{value: feeToPay + extraValue}(address(l1USDC), recipient, amount, gasLimit);
|
||||
} else {
|
||||
gateway.depositERC20{value: feeToPay + extraValue}(address(l1USDC), recipient, amount, gasLimit);
|
||||
}
|
||||
} else {
|
||||
// token is not l1USDC
|
||||
hevm.expectRevert("only USDC is allowed");
|
||||
gateway.depositERC20(address(l2USDC), recipient, amount, gasLimit);
|
||||
|
||||
// emit QueueTransaction from L1MessageQueue
|
||||
{
|
||||
hevm.expectEmit(true, true, false, true);
|
||||
address sender = AddressAliasHelper.applyL1ToL2Alias(address(l1Messenger));
|
||||
emit QueueTransaction(sender, address(l2Messenger), 0, 0, gasLimit, xDomainCalldata);
|
||||
}
|
||||
|
||||
// emit SentMessage from L1ScrollMessenger
|
||||
{
|
||||
hevm.expectEmit(true, true, false, true);
|
||||
emit SentMessage(address(gateway), address(counterpartGateway), 0, 0, gasLimit, message);
|
||||
}
|
||||
|
||||
// emit DepositERC20 from L1USDCGateway
|
||||
hevm.expectEmit(true, true, true, true);
|
||||
emit DepositERC20(address(l1USDC), address(l2USDC), address(this), recipient, amount, new bytes(0));
|
||||
|
||||
uint256 gatewayBalance = l1USDC.balanceOf(address(gateway));
|
||||
uint256 totalBridgedUSDCBefore = gateway.totalBridgedUSDC();
|
||||
uint256 feeVaultBalance = address(feeVault).balance;
|
||||
assertBoolEq(false, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
|
||||
if (useRouter) {
|
||||
router.depositERC20{value: feeToPay + extraValue}(address(l1USDC), recipient, amount, gasLimit);
|
||||
} else {
|
||||
gateway.depositERC20{value: feeToPay + extraValue}(address(l1USDC), recipient, amount, gasLimit);
|
||||
}
|
||||
assertEq(amount + gatewayBalance, l1USDC.balanceOf(address(gateway)));
|
||||
assertEq(amount + totalBridgedUSDCBefore, gateway.totalBridgedUSDC());
|
||||
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
|
||||
assertBoolEq(true, l1Messenger.isL1MessageSent(keccak256(xDomainCalldata)));
|
||||
}
|
||||
}
|
||||
|
||||
function _deployGateway() internal returns (L1USDCGateway) {
|
||||
return
|
||||
L1USDCGateway(
|
||||
payable(new ERC1967Proxy(address(new L1USDCGateway(address(l1USDC), address(l2USDC))), new bytes(0)))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,20 @@ contract L2TxFeeVaultTest is DSTestPlus {
|
||||
vault.withdraw();
|
||||
}
|
||||
|
||||
function testCantWithdrawAmountBelowMinimum(uint256 amount) public {
|
||||
amount = bound(amount, 0 ether, 10 ether - 1);
|
||||
hevm.deal(address(vault), 100 ether);
|
||||
hevm.expectRevert("FeeVault: withdrawal amount must be greater than minimum withdrawal amount");
|
||||
vault.withdraw(amount);
|
||||
}
|
||||
|
||||
function testCantWithdrawMoreThanBalance(uint256 amount) public {
|
||||
hevm.assume(amount >= 10 ether);
|
||||
hevm.deal(address(vault), amount - 1);
|
||||
hevm.expectRevert(new bytes(0));
|
||||
vault.withdraw(amount);
|
||||
}
|
||||
|
||||
function testWithdrawOnce() public {
|
||||
hevm.deal(address(vault), 11 ether);
|
||||
vault.withdraw();
|
||||
@@ -30,6 +44,17 @@ contract L2TxFeeVaultTest is DSTestPlus {
|
||||
assertEq(vault.totalProcessed(), 11 ether);
|
||||
}
|
||||
|
||||
function testWithdrawAmountOnce(uint256 amount) public {
|
||||
amount = bound(amount, 10 ether, 100 ether);
|
||||
|
||||
hevm.deal(address(vault), 100 ether);
|
||||
vault.withdraw(amount);
|
||||
|
||||
assertEq(address(messenger).balance, amount);
|
||||
assertEq(vault.totalProcessed(), amount);
|
||||
assertEq(address(vault).balance, 100 ether - amount);
|
||||
}
|
||||
|
||||
function testWithdrawTwice() public {
|
||||
hevm.deal(address(vault), 11 ether);
|
||||
vault.withdraw();
|
||||
@@ -41,4 +66,21 @@ contract L2TxFeeVaultTest is DSTestPlus {
|
||||
assertEq(address(messenger).balance, 33 ether);
|
||||
assertEq(vault.totalProcessed(), 33 ether);
|
||||
}
|
||||
|
||||
function testWithdrawAmountTwice(uint256 amount1, uint256 amount2) public {
|
||||
amount1 = bound(amount1, 10 ether, 100 ether);
|
||||
amount2 = bound(amount2, 10 ether, 100 ether);
|
||||
|
||||
hevm.deal(address(vault), 200 ether);
|
||||
|
||||
vault.withdraw(amount1);
|
||||
assertEq(address(messenger).balance, amount1);
|
||||
assertEq(vault.totalProcessed(), amount1);
|
||||
|
||||
vault.withdraw(amount2);
|
||||
assertEq(address(messenger).balance, amount1 + amount2);
|
||||
assertEq(vault.totalProcessed(), amount1 + amount2);
|
||||
|
||||
assertEq(address(vault).balance, 200 ether - amount1 - amount2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ contract L2USDCGatewayTest is L2GatewayTestBase {
|
||||
router = L2GatewayRouter(address(new ERC1967Proxy(address(new L2GatewayRouter()), new bytes(0))));
|
||||
|
||||
// Deploy L1 contracts
|
||||
counterpartGateway = new L1USDCGateway();
|
||||
counterpartGateway = new L1USDCGateway(address(l1USDC), address(l2USDC));
|
||||
|
||||
// Initialize L2 contracts
|
||||
gateway.initialize(address(counterpartGateway), address(router), address(l2Messenger));
|
||||
@@ -128,16 +128,6 @@ contract L2USDCGatewayTest is L2GatewayTestBase {
|
||||
_withdrawERC20WithRecipient(false, amount, recipient, gasLimit, feePerGas);
|
||||
}
|
||||
|
||||
function testWithdrawERC20WithRecipientAndCalldata(
|
||||
uint256 amount,
|
||||
address recipient,
|
||||
bytes memory dataToCall,
|
||||
uint256 gasLimit,
|
||||
uint256 feePerGas
|
||||
) public {
|
||||
_withdrawERC20WithRecipientAndCalldata(false, amount, recipient, dataToCall, gasLimit, feePerGas);
|
||||
}
|
||||
|
||||
function testRouterWithdrawERC20(
|
||||
uint256 amount,
|
||||
uint256 gasLimit,
|
||||
@@ -155,16 +145,6 @@ contract L2USDCGatewayTest is L2GatewayTestBase {
|
||||
_withdrawERC20WithRecipient(true, amount, recipient, gasLimit, feePerGas);
|
||||
}
|
||||
|
||||
function testRouterWithdrawERC20WithRecipientAndCalldata(
|
||||
uint256 amount,
|
||||
address recipient,
|
||||
bytes memory dataToCall,
|
||||
uint256 gasLimit,
|
||||
uint256 feePerGas
|
||||
) public {
|
||||
_withdrawERC20WithRecipientAndCalldata(true, amount, recipient, dataToCall, gasLimit, feePerGas);
|
||||
}
|
||||
|
||||
function testFinalizeDepositERC20FailedMocking(
|
||||
address sender,
|
||||
address recipient,
|
||||
@@ -356,7 +336,6 @@ contract L2USDCGatewayTest is L2GatewayTestBase {
|
||||
) private {
|
||||
amount = bound(amount, 0, l2USDC.balanceOf(address(this)));
|
||||
gasLimit = bound(gasLimit, 21000, 1000000);
|
||||
feePerGas = bound(feePerGas, 0, 1000);
|
||||
feePerGas = 0;
|
||||
|
||||
setL1BaseFee(feePerGas);
|
||||
@@ -433,7 +412,6 @@ contract L2USDCGatewayTest is L2GatewayTestBase {
|
||||
) private {
|
||||
amount = bound(amount, 0, l2USDC.balanceOf(address(this)));
|
||||
gasLimit = bound(gasLimit, 21000, 1000000);
|
||||
feePerGas = bound(feePerGas, 0, 1000);
|
||||
feePerGas = 0;
|
||||
|
||||
setL1BaseFee(feePerGas);
|
||||
@@ -501,85 +479,6 @@ contract L2USDCGatewayTest is L2GatewayTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
function _withdrawERC20WithRecipientAndCalldata(
|
||||
bool useRouter,
|
||||
uint256 amount,
|
||||
address recipient,
|
||||
bytes memory dataToCall,
|
||||
uint256 gasLimit,
|
||||
uint256 feePerGas
|
||||
) private {
|
||||
amount = bound(amount, 0, l2USDC.balanceOf(address(this)));
|
||||
gasLimit = bound(gasLimit, 21000, 1000000);
|
||||
feePerGas = bound(feePerGas, 0, 1000);
|
||||
// we don't charge fee now.
|
||||
feePerGas = 0;
|
||||
|
||||
setL1BaseFee(feePerGas);
|
||||
|
||||
uint256 feeToPay = feePerGas * gasLimit;
|
||||
bytes memory message = abi.encodeWithSelector(
|
||||
IL1ERC20Gateway.finalizeWithdrawERC20.selector,
|
||||
address(l1USDC),
|
||||
address(l2USDC),
|
||||
address(this),
|
||||
recipient,
|
||||
amount,
|
||||
dataToCall
|
||||
);
|
||||
bytes memory xDomainCalldata = abi.encodeWithSignature(
|
||||
"relayMessage(address,address,uint256,uint256,bytes)",
|
||||
address(gateway),
|
||||
address(counterpartGateway),
|
||||
0,
|
||||
0,
|
||||
message
|
||||
);
|
||||
|
||||
if (amount == 0) {
|
||||
hevm.expectRevert("withdraw zero amount");
|
||||
if (useRouter) {
|
||||
router.withdrawERC20AndCall{value: feeToPay}(address(l2USDC), recipient, amount, dataToCall, gasLimit);
|
||||
} else {
|
||||
gateway.withdrawERC20AndCall{value: feeToPay}(address(l2USDC), recipient, amount, dataToCall, gasLimit);
|
||||
}
|
||||
} else {
|
||||
// token is not l1USDC
|
||||
hevm.expectRevert("only USDC is allowed");
|
||||
gateway.withdrawERC20AndCall(address(l1USDC), recipient, amount, dataToCall, gasLimit);
|
||||
|
||||
// emit AppendMessage from L2MessageQueue
|
||||
{
|
||||
hevm.expectEmit(false, false, false, true);
|
||||
emit AppendMessage(0, keccak256(xDomainCalldata));
|
||||
}
|
||||
|
||||
// emit SentMessage from L2ScrollMessenger
|
||||
{
|
||||
hevm.expectEmit(true, true, false, true);
|
||||
emit SentMessage(address(gateway), address(counterpartGateway), 0, 0, gasLimit, message);
|
||||
}
|
||||
|
||||
// emit WithdrawERC20 from L2USDCGateway
|
||||
hevm.expectEmit(true, true, true, true);
|
||||
emit WithdrawERC20(address(l1USDC), address(l2USDC), address(this), recipient, amount, dataToCall);
|
||||
|
||||
uint256 senderBalance = l2USDC.balanceOf(address(this));
|
||||
uint256 gatewayBalance = l2USDC.balanceOf(address(gateway));
|
||||
uint256 feeVaultBalance = address(feeVault).balance;
|
||||
assertBoolEq(false, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
|
||||
if (useRouter) {
|
||||
router.withdrawERC20AndCall{value: feeToPay}(address(l2USDC), recipient, amount, dataToCall, gasLimit);
|
||||
} else {
|
||||
gateway.withdrawERC20AndCall{value: feeToPay}(address(l2USDC), recipient, amount, dataToCall, gasLimit);
|
||||
}
|
||||
assertEq(senderBalance - amount, l2USDC.balanceOf(address(this)));
|
||||
assertEq(gatewayBalance, l2USDC.balanceOf(address(gateway)));
|
||||
assertEq(feeToPay + feeVaultBalance, address(feeVault).balance);
|
||||
assertBoolEq(true, l2Messenger.isL2MessageSent(keccak256(xDomainCalldata)));
|
||||
}
|
||||
}
|
||||
|
||||
function _deployGateway() internal returns (L2USDCGateway) {
|
||||
return
|
||||
L2USDCGateway(
|
||||
|
||||
@@ -410,7 +410,7 @@ contract L2WETHGatewayTest is L2GatewayTestBase {
|
||||
uint256 gasLimit,
|
||||
uint256 feePerGas
|
||||
) private {
|
||||
amount = bound(amount, 0, l1weth.balanceOf(address(this)));
|
||||
amount = bound(amount, 0, l2weth.balanceOf(address(this)));
|
||||
gasLimit = bound(gasLimit, 21000, 1000000);
|
||||
feePerGas = 0;
|
||||
|
||||
@@ -485,7 +485,7 @@ contract L2WETHGatewayTest is L2GatewayTestBase {
|
||||
uint256 gasLimit,
|
||||
uint256 feePerGas
|
||||
) private {
|
||||
amount = bound(amount, 0, l1weth.balanceOf(address(this)));
|
||||
amount = bound(amount, 0, l2weth.balanceOf(address(this)));
|
||||
gasLimit = bound(gasLimit, 21000, 1000000);
|
||||
feePerGas = 0;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ contract ScrollChainTest is DSTestPlus {
|
||||
event UpdateSequencer(address indexed account, bool status);
|
||||
event UpdateProver(address indexed account, bool status);
|
||||
event UpdateVerifier(address indexed oldVerifier, address indexed newVerifier);
|
||||
event UpdateMaxNumL2TxInChunk(uint256 oldMaxNumL2TxInChunk, uint256 newMaxNumL2TxInChunk);
|
||||
event UpdateMaxNumTxInChunk(uint256 oldMaxNumTxInChunk, uint256 newMaxNumTxInChunk);
|
||||
|
||||
event CommitBatch(uint256 indexed batchIndex, bytes32 indexed batchHash);
|
||||
event FinalizeBatch(uint256 indexed batchIndex, bytes32 indexed batchHash, bytes32 stateRoot, bytes32 withdrawRoot);
|
||||
@@ -429,6 +429,15 @@ contract ScrollChainTest is DSTestPlus {
|
||||
mstore(add(bitmap, add(0x20, 32)), 42) // bitmap1
|
||||
}
|
||||
|
||||
// too many txs in one chunk, revert
|
||||
rollup.updateMaxNumTxInChunk(2); // 3 - 1
|
||||
hevm.expectRevert("too many txs in one chunk");
|
||||
rollup.commitBatch(0, batchHeader1, chunks, bitmap); // first chunk with too many txs
|
||||
rollup.updateMaxNumTxInChunk(185); // 5+10+300 - 2 - 127
|
||||
hevm.expectRevert("too many txs in one chunk");
|
||||
rollup.commitBatch(0, batchHeader1, chunks, bitmap); // second chunk with too many txs
|
||||
|
||||
rollup.updateMaxNumTxInChunk(186);
|
||||
hevm.expectEmit(true, true, false, true);
|
||||
emit CommitBatch(2, bytes32(0x03a9cdcb9d582251acf60937db006ec99f3505fd4751b7c1f92c9a8ef413e873));
|
||||
rollup.commitBatch(0, batchHeader1, chunks, bitmap);
|
||||
@@ -631,20 +640,20 @@ contract ScrollChainTest is DSTestPlus {
|
||||
assertEq(rollup.verifier(), _newVerifier);
|
||||
}
|
||||
|
||||
function testUpdateMaxNumL2TxInChunk(uint256 _maxNumL2TxInChunk) public {
|
||||
function testUpdateMaxNumTxInChunk(uint256 _maxNumTxInChunk) public {
|
||||
// set by non-owner, should revert
|
||||
hevm.startPrank(address(1));
|
||||
hevm.expectRevert("Ownable: caller is not the owner");
|
||||
rollup.updateMaxNumL2TxInChunk(_maxNumL2TxInChunk);
|
||||
rollup.updateMaxNumTxInChunk(_maxNumTxInChunk);
|
||||
hevm.stopPrank();
|
||||
|
||||
// change to random operator
|
||||
hevm.expectEmit(false, false, false, true);
|
||||
emit UpdateMaxNumL2TxInChunk(100, _maxNumL2TxInChunk);
|
||||
emit UpdateMaxNumTxInChunk(100, _maxNumTxInChunk);
|
||||
|
||||
assertEq(rollup.maxNumL2TxInChunk(), 100);
|
||||
rollup.updateMaxNumL2TxInChunk(_maxNumL2TxInChunk);
|
||||
assertEq(rollup.maxNumL2TxInChunk(), _maxNumL2TxInChunk);
|
||||
assertEq(rollup.maxNumTxInChunk(), 100);
|
||||
rollup.updateMaxNumTxInChunk(_maxNumTxInChunk);
|
||||
assertEq(rollup.maxNumTxInChunk(), _maxNumTxInChunk);
|
||||
}
|
||||
|
||||
function testImportGenesisBlock() public {
|
||||
|
||||
@@ -7,6 +7,8 @@ import {DSTestPlus} from "solmate/test/utils/DSTestPlus.sol";
|
||||
import {ScrollOwner} from "../misc/ScrollOwner.sol";
|
||||
|
||||
contract ScrollOwnerTest is DSTestPlus {
|
||||
event GrantAccess(bytes32 indexed role, address indexed target, bytes4[] selectors);
|
||||
event RevokeAccess(bytes32 indexed role, address indexed target, bytes4[] selectors);
|
||||
event Call();
|
||||
|
||||
ScrollOwner private owner;
|
||||
@@ -32,10 +34,18 @@ contract ScrollOwnerTest is DSTestPlus {
|
||||
assertEq(0, _roles.length);
|
||||
_selectors = new bytes4[](1);
|
||||
_selectors[0] = ScrollOwnerTest.revertOnCall.selector;
|
||||
|
||||
hevm.expectEmit(true, true, false, true);
|
||||
emit GrantAccess(bytes32(uint256(1)), address(this), _selectors);
|
||||
|
||||
owner.updateAccess(address(this), _selectors, bytes32(uint256(1)), true);
|
||||
_roles = owner.callableRoles(address(this), ScrollOwnerTest.revertOnCall.selector);
|
||||
assertEq(1, _roles.length);
|
||||
assertEq(_roles[0], bytes32(uint256(1)));
|
||||
|
||||
hevm.expectEmit(true, true, false, true);
|
||||
emit RevokeAccess(bytes32(uint256(1)), address(this), _selectors);
|
||||
|
||||
owner.updateAccess(address(this), _selectors, bytes32(uint256(1)), false);
|
||||
_roles = owner.callableRoles(address(this), ScrollOwnerTest.revertOnCall.selector);
|
||||
assertEq(0, _roles.length);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user