This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: David Dunn <26876072+doubledup@users.noreply.github.com> Co-authored-by: Clara van Staden <claravanstaden64@gmail.com> Co-authored-by: Alistair Singh <alistair.singh7@gmail.com> Co-authored-by: Ron <yrong1997@gmail.com> Co-authored-by: claravanstaden <Cats 4 life!>
- Loading branch information
1 parent
3c4bec4
commit 30d0f0a
Showing
258 changed files
with
8,975 additions
and
10,796 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: contracts | ||
|
||
on: | ||
push: | ||
paths: | ||
- "contracts/**" | ||
- "!contracts/**/README.md" | ||
branches: | ||
- main | ||
pull_request: | ||
paths: | ||
- "contracts/**" | ||
- "!contracts/**/README.md" | ||
|
||
jobs: | ||
build: | ||
runs-on: snowbridge-runner | ||
timeout-minutes: 15 | ||
steps: | ||
- uses: actions/checkout@v1 | ||
with: | ||
fetch-depth: 2 | ||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
- name: Test | ||
working-directory: contracts | ||
run: forge test | ||
- name: Coverage | ||
working-directory: contracts | ||
run: forge coverage --report=lcov --via-ir | ||
- name: Upload coverage reports to Codecov with GitHub Action | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
working-directory: contracts | ||
files: lcov.info | ||
flags: solidity |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,6 @@ node_modules/ | |
.envrc | ||
parachain/build_rs_cov.profraw | ||
compiler_config.json | ||
contracts/beefy-state.json | ||
|
||
go/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
AgentTest:testInvoke() (gas: 20810) | ||
AgentTest:testInvokeFail() (gas: 13429) | ||
AgentTest:testInvokeUnauthorized() (gas: 13974) | ||
BeefyClientTest:testCreateFinalBitfield() (gas: 278225) | ||
BeefyClientTest:testCreateFinalBitfieldInvalid() (gas: 265008) | ||
BeefyClientTest:testCreateInitialBitfield() (gas: 650507) | ||
BeefyClientTest:testCreateInitialBitfieldInvalid() (gas: 578841) | ||
BeefyClientTest:testScaleEncodeCommit() (gas: 32353) | ||
BeefyClientTest:testSubmit():((uint32,uint64,(bytes2,bytes)[])) (gas: 708627) | ||
BeefyClientTest:testSubmitFailForPrevRandaoCapturedMoreThanOnce() (gas: 266184) | ||
BeefyClientTest:testSubmitFailForPrevRandaoTooEarlyOrTooLate() (gas: 207388) | ||
BeefyClientTest:testSubmitFailInvalidSignature() (gas: 657123) | ||
BeefyClientTest:testSubmitFailValidatorNotInBitfield() (gas: 645077) | ||
BeefyClientTest:testSubmitFailWithInvalidBitfield() (gas: 634383) | ||
BeefyClientTest:testSubmitFailWithInvalidMMRLeaf() (gas: 748779) | ||
BeefyClientTest:testSubmitFailWithInvalidMMRLeafProof() (gas: 752764) | ||
BeefyClientTest:testSubmitFailWithInvalidTicket() (gas: 638107) | ||
BeefyClientTest:testSubmitFailWithInvalidValidatorSet() (gas: 642432) | ||
BeefyClientTest:testSubmitFailWithNotEnoughClaims() (gas: 197586) | ||
BeefyClientTest:testSubmitFailWithStaleCommitment() (gas: 835952) | ||
BeefyClientTest:testSubmitFailWithoutPrevRandao() (gas: 532261) | ||
BeefyClientTest:testSubmitWithHandover() (gas: 736139) | ||
BeefyClientTest:testSubmitWithHandoverFailStaleCommitment() (gas: 859922) | ||
BeefyClientTest:testSubmitWithHandoverFailWithInvalidValidatorSet() (gas: 666242) | ||
BeefyClientTest:testSubmitWithHandoverFailWithoutPrevRandao() (gas: 556301) | ||
GatewayTest:testAgentExecution() (gas: 52791) | ||
GatewayTest:testAgentExecutionBadOrigin() (gas: 23354) | ||
GatewayTest:testAgentExecutionBadPayload() (gas: 22077) | ||
GatewayTest:testCreateAgent() (gas: 254909) | ||
GatewayTest:testCreateAgentAlreadyCreated() (gas: 256489) | ||
GatewayTest:testCreateChannel() (gas: 332117) | ||
GatewayTest:testCreateChannelFailsAgentDoesNotExist() (gas: 19185) | ||
GatewayTest:testCreateChannelFailsChannelAlreadyExists() (gas: 335995) | ||
GatewayTest:testDisableOutboundMessaging() (gas: 67040) | ||
GatewayTest:testDisableOutboundMessagingForChannel() (gas: 161374) | ||
GatewayTest:testGetters() (gas: 37883) | ||
GatewayTest:testHandlersNotExternallyCallable() (gas: 52292) | ||
GatewayTest:testInitializeNotExternallyCallable() (gas: 16762) | ||
GatewayTest:testRegisterToken() (gas: 85845) | ||
GatewayTest:testRelayerNotRewarded() (gas: 75289) | ||
GatewayTest:testRelayerRewardedFromAgent() (gas: 310728) | ||
GatewayTest:testSendTokenAddress20() (gas: 128049) | ||
GatewayTest:testSendTokenAddress20FailsInvalidDestination() (gas: 59703) | ||
GatewayTest:testSendTokenAddress32() (gas: 129387) | ||
GatewayTest:testSendTokenAddress32ToAssetHub() (gas: 128776) | ||
GatewayTest:testSetOperatingMode() (gas: 39208) | ||
GatewayTest:testSubmitFailInvalidChannel() (gas: 27926) | ||
GatewayTest:testSubmitFailInvalidNonce() (gas: 318948) | ||
GatewayTest:testSubmitHappyPath() (gas: 312342) | ||
GatewayTest:testUpdateChannel() (gas: 58121) | ||
GatewayTest:testUpdateChannelFailDoesNotExist() (gas: 20107) | ||
GatewayTest:testUpdateChannelSanityChecksForBridgeHubChannel() (gas: 22147) | ||
GatewayTest:testUpgrade() (gas: 208455) | ||
GatewayTest:testUpgradeFailCodeHashMismatch() (gas: 178843) | ||
GatewayTest:testUpgradeFailOnInitializationFailure() (gas: 182568) | ||
GatewayTest:testUserDoesNotProvideEnoughFees() (gas: 218463) | ||
GatewayTest:testUserPaysFees() (gas: 244678) | ||
GatewayTest:testWithdrawAgentFunds() (gas: 64315) | ||
MMRProofTest:testVerifyLeafProof() (gas: 370749) | ||
MMRProofTest:testVerifyLeafProofFailsExceededProofSize() (gas: 358741) | ||
ScaleCodecTest:testCheckedEncodeCompactU32() (gas: 5120) | ||
ScaleCodecTest:testEncodeCompactU32() (gas: 9722) | ||
ScaleCodecTest:testEncodeU128() (gas: 192) | ||
ScaleCodecTest:testEncodeU16() (gas: 434) | ||
ScaleCodecTest:testEncodeU256() (gas: 478) | ||
ScaleCodecTest:testEncodeU32() (gas: 170) | ||
ScaleCodecTest:testEncodeU64() (gas: 280) | ||
VerificationTest:testCreateParachainHeaderMerkleFailInvalidHeader() (gas: 11341) | ||
VerificationTest:testCreateParachainHeaderMerkleLeaf() (gas: 20830) | ||
VerificationTest:testIsCommitmentInHeaderDigest() (gas: 21863) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ types/ | |
tsconfig.tsbuildinfo | ||
lcov.info | ||
tenderly.yaml | ||
docs/ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Ethereum Contracts | ||
|
||
## Overview | ||
|
||
### Gateway | ||
|
||
The Ethereum side of the bridge is organised around a central `Gateway` contract, responsible for the following: | ||
* Receiving, verifying, and dispatching inbound messages from Polkadot | ||
* Accepting outbound messages for delivery to Polkadot | ||
* Higher-level application features such as token transfers | ||
|
||
The gateway is defined by the following contracts | ||
* [IGateway.sol](src/interfaces/IGateway.sol): Public API of the gateway | ||
* [GatewayProxy.sol](src/Gateway.sol): Proxy contract for the gateway | ||
* [Gateway.sol](src/Gateway.sol): Implementation contract of the gateway | ||
|
||
The gateway is modular in design, being composed of libraries implementing specific functionality: | ||
|
||
* [Verification.sol](src/Verification.sol): Verification of inbound messages from Polakdot | ||
* [Assets.sol](src/Assets.sol): ERC20 token transfers to Polkadot | ||
|
||
#### Governance | ||
|
||
Using cross-chain messaging, the gateway is governed remotely by the governance of the Polkadot relay chain. | ||
|
||
#### Upgrades | ||
|
||
The gateway consists of an upgradable proxy, and an implementation contract, loosely following the [ERC1967](https://eips.ethereum.org/EIPS/eip-1967) standard. | ||
|
||
### Agents | ||
|
||
Agents are proxy contracts for arbitrary consensus systems on Polkadot. Logically, one can think of them as the sovereign accounts of remote consensus systems. | ||
|
||
They have a number of uses: | ||
* When an Ethereum user sends ERC20 tokens to Polkadot (Specifically the AssetHub parachain), these tokens are actually locked into the agent contract corresponding to the AssetHub parachain. Then finally, on the AssetHub parachain, wrapped tokens are minted into an account controlled by the sender. | ||
* When a Polkadot parachain wishes to call a function on an Ethereum contract, it will appear to the destination contract that the message sender is the agent contract for the origin parachain. | ||
* Agents control the funds for receiving fees from users and disbursing rewards to message relayers | ||
|
||
Agents are defined by the following contracts: | ||
* [Agent.sol](src/Agent.sol): Agent contract | ||
* [AgentExecutor.sol](src/AgentExecutor.sol): Code executed within an agent using `delegatecall` | ||
|
||
The creation of new agents can be initiated by calling `EthereumControl::create_agent` extrinsic on the BridgeHub parachain. | ||
|
||
### BeefyClient | ||
|
||
The [BeefyClient.sol](src/BeefyClient.sol) contract implements a light client for following a subset of Polkadot consensus. In conjunction with the [Verification.sol](src/Verification.sol) library, it used to verify inbound messages from the BridgeHub parachain. | ||
|
||
## Testing | ||
|
||
Run all tests: | ||
|
||
```bash | ||
forge test | ||
``` | ||
|
||
Run coverage reports: | ||
|
||
```bash | ||
forge coverage | ||
``` | ||
|
||
## Test Fixtures | ||
|
||
Some of the unit tests require fixture data generated by a live deployment. For this purpose, we use logging artifacts from the offchain relayers running in the [E2E](../web/packages/test) stack. | ||
``` | ||
BEEFY commitments & proofs extracted from `/tmp/snowbridge/beefy-relay.log`. | ||
1. Search for `Sent SubmitFinal transaction` in relayer log file | ||
2. Copy into `test/data/beefy-commitment.json` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule ds-test
updated
from 000000 to e28215
Submodule openzeppelin-contracts
added at
e50c24
File renamed without changes.
File renamed without changes.
Oops, something went wrong.