Skip to content

Commit

Permalink
evm: refactor
Browse files Browse the repository at this point in the history
* add WormholeCctpTokenMessenger

* inherit above in CircleIntegration

* remove updateWormholeFinality (gov)

* reorganize

* add more forge tests

* remove integration tests

* add gas snapshot
  • Loading branch information
a5-pickle committed Jan 12, 2024
1 parent 74e11b1 commit f7df33b
Show file tree
Hide file tree
Showing 90 changed files with 15,149 additions and 9,156 deletions.
17 changes: 0 additions & 17 deletions .github/main.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "CI"

env:
FOUNDRY_PROFILE: "ci"

on:
workflow_dispatch:
pull_request:
push:
branches:
- "main"

jobs:
evm-test:
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: "actions/checkout@v3"
with:
submodules: "recursive"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: "Run the tests"
run: "cd evm && make test"

- name: "Add test summary"
run: |
echo "## Tests result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
36 changes: 36 additions & 0 deletions evm/.gas-snapshot-current
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CircleIntegrationComparison:test_Composed__RedeemUsdc(uint256,bytes32,bytes32) (runs: 256, μ: 267202, ~: 267111)
CircleIntegrationComparison:test_Composed__TransferUsdc(uint256,bytes32,bytes32) (runs: 256, μ: 295433, ~: 295430)
CircleIntegrationComparison:test_Control__RedeemTokensWithPayload(uint256,bytes32,bytes32) (runs: 256, μ: 73756, ~: 73625)
CircleIntegrationComparison:test_Control__TransferTokensWithPayload(uint256,bytes32,bytes32) (runs: 256, μ: 135806, ~: 135676)
CircleIntegrationComparison:test_Fork__RedeemTokensWithPayload(uint256,bytes32,bytes32) (runs: 256, μ: 275608, ~: 275475)
CircleIntegrationComparison:test_Fork__TransferTokensWithPayload(uint256,bytes32,bytes32) (runs: 256, μ: 273234, ~: 273231)
CircleIntegrationComparison:test_Inherited__RedeemUsdc(uint256,bytes32,bytes32) (runs: 256, μ: 226968, ~: 226904)
CircleIntegrationComparison:test_Inherited__TransferUsdc(uint256,bytes32,bytes32) (runs: 256, μ: 248858, ~: 248856)
CircleIntegrationComparison:test_Latest__RedeemTokensWithPayload(uint256,bytes32,bytes32) (runs: 256, μ: 252196, ~: 252072)
CircleIntegrationComparison:test_Latest__TransferTokensWithPayload(uint256,bytes32,bytes32) (runs: 256, μ: 263957, ~: 263956)
CircleIntegrationTest:test_CannotRedeemTokensWithPayloadCallerMustBeMintRecipient(address) (runs: 256, μ: 76012, ~: 76012)
CircleIntegrationTest:test_CannotRedeemTokensWithPayloadInvalidMessagePair() (gas: 95486)
CircleIntegrationTest:test_CannotRedeemTokensWithPayloadMintTokenNotSupported(bytes32) (runs: 256, μ: 141797, ~: 141789)
CircleIntegrationTest:test_CannotRedeemTokensWithPayloadUnknownEmitter(bytes32) (runs: 256, μ: 203129, ~: 203121)
CircleIntegrationTest:test_CannotTransferTokensWithPayloadInvalidMintRecipient() (gas: 177584)
CircleIntegrationTest:test_CannotTransferTokensWithPayloadInvalidToken() (gas: 248030)
CircleIntegrationTest:test_CannotTransferTokensWithPayloadTargetContractNotRegistered() (gas: 120482)
CircleIntegrationTest:test_CannotTransferTokensWithPayloadZeroAmount() (gas: 49696)
CircleIntegrationTest:test_RedeemTokensWithPayload(uint256) (runs: 256, μ: 255379, ~: 255334)
CircleIntegrationTest:test_TransferTokensWithPayload(uint256,bytes32) (runs: 256, μ: 394493, ~: 394457)
ForkSlots:test_UpgradeForkAndCheckSlots() (gas: 2316557)
GovernanceTest:test_CannotConsumeGovernanceMessageInvalidAction(uint8,uint8) (runs: 256, μ: 61609, ~: 61609)
GovernanceTest:test_CannotConsumeGovernanceMessageInvalidGovernanceChainId(uint16,uint8) (runs: 256, μ: 62307, ~: 62307)
GovernanceTest:test_CannotConsumeGovernanceMessageInvalidGovernanceContract(bytes32,uint8) (runs: 256, μ: 62055, ~: 62055)
GovernanceTest:test_CannotConsumeGovernanceMessageInvalidModule(bytes32,uint8) (runs: 256, μ: 61414, ~: 61414)
GovernanceTest:test_CannotRegisterEmitterAndDomainInvalidDomain(uint16,bytes32) (runs: 256, μ: 94755, ~: 94755)
GovernanceTest:test_CannotRegisterEmitterAndDomainInvalidEmitterAddress(uint16,uint32) (runs: 256, μ: 95882, ~: 95882)
GovernanceTest:test_CannotRegisterEmitterAndDomainInvalidForeignChain(bytes32,uint32) (runs: 256, μ: 163511, ~: 163511)
GovernanceTest:test_CannotRegisterEmitterAndDomainInvalidLength(uint16,bytes32,uint32) (runs: 256, μ: 96605, ~: 96605)
GovernanceTest:test_CannotRegisterEmitterAndDomainInvalidTargetChain(uint16,uint16,bytes32,uint32) (runs: 256, μ: 96243, ~: 96243)
GovernanceTest:test_CannotUpgradeContractInvalidImplementation(bytes12,address) (runs: 256, μ: 208638, ~: 208638)
GovernanceTest:test_RegisterEmitterAndDomain(uint16,bytes32,uint32) (runs: 256, μ: 214666, ~: 214666)
GovernanceTest:test_RegisterEmitterAndDomainNoTarget() (gas: 155128)
GovernanceTest:test_UpgradeContract() (gas: 2272176)
InheritingWormholeCctpTest:test_TransferUsdc(uint256,bytes32) (runs: 256, μ: 268693, ~: 268654)
MessagesTest:test_DepositWithPayloadSerde(bytes32,uint256,uint32,uint32,uint64,bytes32,bytes32,bytes) (runs: 256, μ: 7871, ~: 7706)
3 changes: 1 addition & 2 deletions evm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
.env
.private
.vscode
anvil*.log
broadcast*
cache
deploy.out
lib
node_modules
out
ts/src/ethers-contracts
24 changes: 24 additions & 0 deletions evm/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 100,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
},
{
"files": "*.ts",
"options": {
"printWidth": 100,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": true
}
}
]
}
41 changes: 15 additions & 26 deletions evm/Makefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,37 @@
include env/testing.env

.PHONY: dependencies unit-test forge-test integration-test clean all
.PHONY: dependencies test clean all

all: build

.PHONY: clean
clean:
rm -rf anvil.log node_modules lib out ts/src/ethers-contracts
forge clean
rm -rf node_modules lib out ts/src/ethers-contracts

.PHONY: dependencies
dependencies: node_modules lib/forge-std lib/wormhole
dependencies: node_modules lib/forge-std

node_modules:
yarn
npm ci

lib/forge-std:
forge install --no-git --no-commit foundry-rs/forge-std

lib/wormhole:
forge install --no-git --no-commit wormhole=wormhole-foundation/wormhole
ts/src/ethers-contracts:
npm run build-types

build: dependencies
forge build
yarn build-types

.PHONY: unit-test
unit-test: forge-test

.PHONY: forge-test
forge-test: dependencies
forge test \
-vv \
--fork-url ${TESTING_FORK_RPC} \
.PHONY: test
test: dependencies
forge test --fork-url ${TESTING_FORK_RPC} -vv

.PHONY: forge-test
.PHONY: gas-report
gas-report: dependencies
forge test \
--fork-url ${TESTING_FORK_RPC} \
--gas-report

.PHONY: integration-test
integration-test: dependencies build
bash shell-scripts/run_integration_tests.sh

.PHONY: test
test: forge-test integration-test
forge test --fork-url ${TESTING_FORK_RPC} --match-path forge/tests/gas/* --fuzz-runs 512 --gas-report

.PHONY: gas-snapshot
gas-snapshot: dependencies
forge snapshot --fork-url ${TESTING_FORK_RPC} --diff .gas-snapshot-current
5 changes: 1 addition & 4 deletions evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ export RELEASE_WORMHOLE_ADDRESS=0x
# Circle Bridge Contract Address (TokenMessenger)
export RELEASE_CIRCLE_BRIDGE_ADDRESS=0x
# Circle Message Transmitter Address
export RELEASE_WORMHOLE_FINALITY=
```

Then run the following command to deploy (and set up) the proxy contract:

```
# sample deployment command
. env/put_your_env_file_here.env && PRIVATE_KEY=put_your_private_key_here bash shell-scripts/deploy_contracts.sh
. env/put_your_env_file_here.env && PRIVATE_KEY=put_your_private_key_here bash sh/deploy_contracts.sh
```

## Test Suite
Expand Down
1 change: 0 additions & 1 deletion evm/env/mainnet/arbitrum-mainnet.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export RPC="https://arbitrum-one.public.blastapi.io"
### Contract addresses
export RELEASE_WORMHOLE_ADDRESS=0xa5f208e072434bC67592E4C49C1B991BA79BCA46
export RELEASE_CIRCLE_BRIDGE_ADDRESS=0x19330d10D9Cc8751218eaf51E8885D058642E08A
export RELEASE_WORMHOLE_FINALITY=1

### Deployed Circle Integration addresses
export CIRCLE_INTEGRATION_IMPLEMENTATION=0xD73aFD826D6bDD4D2fEF326DF5091451A5d8130a
Expand Down
1 change: 0 additions & 1 deletion evm/env/mainnet/optimism-mainnet.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export RPC="https://rpc.ankr.com/optimism"
### Contract addresses
export RELEASE_WORMHOLE_ADDRESS=0xEe91C335eab126dF5fDB3797EA9d6aD93aeC9722
export RELEASE_CIRCLE_BRIDGE_ADDRESS=0x2B4069517957735bE00ceE0fadAE88a26365528f
export RELEASE_WORMHOLE_FINALITY=1

### Deployed Circle Integration addresses
export CIRCLE_INTEGRATION_IMPLEMENTATION=0xD73aFD826D6bDD4D2fEF326DF5091451A5d8130a
Expand Down
27 changes: 6 additions & 21 deletions evm/env/testing.env
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
###############################################################################
#
# Ethereum Testnet (Goerli)
# Polygon Testnet (Mumbai)
#
###############################################################################
export ETH_FORK_RPC=
export ETH_FORK_CHAIN_ID=5
export ETH_USDC_TOKEN_ADDRESS=0x07865c6E87B9F70255377e024ace6630C1Eaa37F
export ETH_CIRCLE_BRIDGE_ADDRESS=0xd0c3da58f55358142b8d3e06c1c30c5c6114efe8
export ETH_WORMHOLE_ADDRESS=0x706abc4E45D419950511e474C7B9Ed348A4a716c
export ETH_WORMHOLE_FINALITY=15
export ETH_FORK_RPC=https://polygon-mumbai-bor.publicnode.com
export ETH_FORK_CHAIN_ID=80001
export ETH_USDC_TOKEN_ADDRESS=0x9999f7Fea5938fD3b1E26A12c3f2fb024e194f97
export ETH_CIRCLE_BRIDGE_ADDRESS=0x9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5
export ETH_WORMHOLE_ADDRESS=0x0CBE91CF822c73C2315FB05100C2F714765d5c20

###############################################################################
#
Expand All @@ -20,7 +19,6 @@ export AVAX_FORK_CHAIN_ID=43113
export AVAX_USDC_TOKEN_ADDRESS=0x5425890298aed601595a70AB815c96711a31Bc65
export AVAX_CIRCLE_BRIDGE_ADDRESS=0xeb08f243e5d3fcff26a9e38ae5520a669f4019d0
export AVAX_WORMHOLE_ADDRESS=0x7bbcE28e64B3F8b84d876Ab298393c38ad7aac4C
export AVAX_WORMHOLE_FINALITY=1

###############################################################################
#
Expand All @@ -31,19 +29,6 @@ export TESTING_DEVNET_GUARDIAN=cfb12303a19cde580bb4dd771639b0d26bc68353645571a8c
export TESTING_WORMHOLE_ADDRESS=${ETH_WORMHOLE_ADDRESS}
export TESTING_FORK_RPC=${ETH_FORK_RPC}
export TESTING_FORK_CHAIN_ID=${ETH_FORK_CHAIN_ID}
export TESTING_WORMHOLE_CHAIN_ID=2
export TESTING_WORMHOLE_MESSAGE_FEE=0
export TESTING_WORMHOLE_GUARDIAN_SET_INDEX=0
export TESTING_CIRCLE_BRIDGE_ADDRESS=${ETH_CIRCLE_BRIDGE_ADDRESS}
export TESTING_MESSAGE_ATTESTER_ADDRESS=0x749945748f72C66D5127D5172279405dfa195bF0
export TESTING_USDC_TOKEN_ADDRESS=${ETH_USDC_TOKEN_ADDRESS}
export TESTING_FOREIGN_USDC_TOKEN_ADDRESS=${AVAX_USDC_TOKEN_ADDRESS}
export TESTING_LAST_NONCE=94802

###############################################################################
#
# Integration (Anvil) Test
#
###############################################################################
export WALLET_PRIVATE_KEY=4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d
export WALLET_PRIVATE_KEY_TWO=92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e
1 change: 0 additions & 1 deletion evm/env/testnet/arbitrum-testnet.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export RPC=""
### Contract addresses
export RELEASE_WORMHOLE_ADDRESS=0xC7A204bDBFe983FCD8d8E61D02b475D4073fF97e
export RELEASE_CIRCLE_BRIDGE_ADDRESS=0x12dcfd3fe2e9eac2859fd1ed86d2ab8c5a2f9352
export RELEASE_WORMHOLE_FINALITY=1

### Deployed Circle Integration addresses
export CIRCLE_INTEGRATION_IMPLEMENTATION=0xa098368aaadc0fdf3e309cda710d7a5f8bdeecd9
Expand Down
1 change: 0 additions & 1 deletion evm/env/testnet/avax-testnet.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export RPC="https://api.avax-test.network/ext/bc/C/rpc"
### Contract addresses
export RELEASE_WORMHOLE_ADDRESS=0x7bbcE28e64B3F8b84d876Ab298393c38ad7aac4C
export RELEASE_CIRCLE_BRIDGE_ADDRESS=0xeb08f243e5d3fcff26a9e38ae5520a669f4019d0
export RELEASE_WORMHOLE_FINALITY=1

### Deployed Circle Integration addresses
export CIRCLE_INTEGRATION_IMPLEMENTATION=0xf0ff9898918351148ffd97c7ddb412086505eae1
Expand Down
1 change: 0 additions & 1 deletion evm/env/testnet/eth-testnet.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export RPC=""
### Contract addresses
export RELEASE_WORMHOLE_ADDRESS=0x706abc4E45D419950511e474C7B9Ed348A4a716c
export RELEASE_CIRCLE_BRIDGE_ADDRESS=0xd0c3da58f55358142b8d3e06c1c30c5c6114efe8
export RELEASE_WORMHOLE_FINALITY=200

### Deployed Circle Integration addresses
export CIRCLE_INTEGRATION_IMPLEMENTATION=0x4fa4b2c3744b29D0e4F1AaFE8B758F953FaCf1A4
Expand Down
1 change: 0 additions & 1 deletion evm/env/testnet/optimism-testnet.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export RPC="https://goerli.optimism.io"
### Contract addresses
export RELEASE_WORMHOLE_ADDRESS=0x6b9C8671cdDC8dEab9c719bB87cBd3e782bA6a35
export RELEASE_CIRCLE_BRIDGE_ADDRESS=0x23a04d5935ed8bc8e3eb78db3541f0abfb001c6e
export RELEASE_WORMHOLE_FINALITY=1


### Deployed Circle Integration addresses
Expand Down
75 changes: 0 additions & 75 deletions evm/forge-scripts/deploy_contracts.sol

This file was deleted.

Loading

0 comments on commit f7df33b

Please sign in to comment.