Skip to content

Commit

Permalink
ethereum: rm truffle
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-gray committed Aug 11, 2024
1 parent af7f6b3 commit 0a50809
Show file tree
Hide file tree
Showing 48 changed files with 19,629 additions and 116,434 deletions.
12 changes: 2 additions & 10 deletions ethereum/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,7 @@ flattened: $(patsubst contracts/%, flattened/%, $(FLATTEN_FILES))
.env: .env.test
cp $< $@

test: test-forge test-identifiers test-ganache

.PHONY: test-ganache
test-ganache: build .env dependencies
@if pgrep ganache-cli; then echo "Error: ganache-cli already running. Stop it before running tests"; exit 1; fi
. ./.env && npx ganache-cli --chain.vmErrorsOnRPCResponse --chain.chainId $$INIT_EVM_CHAIN_ID --wallet.defaultBalance 10000 --wallet.deterministic --chain.time="1970-01-01T00:00:00+00:00" --chain.asyncRequestProcessing=false > ganache.log &
sleep 5
npm test || (pkill ganache-cli && exit 1)
pkill ganache-cli || true
test: test-forge test-identifiers

.PHONY: test-upgrade
test-upgrade: build .env node_modules
Expand All @@ -87,4 +79,4 @@ test-push0: dependencies
@if grep -qr --include \*.json PUSH0 ./build-forge; then echo "Contract uses PUSH0 instruction" 1>&2; exit 1; fi

clean:
rm -rf ganache.log .env node_modules build flattened build-forge ethers-contracts lib/forge-std lib/openzeppelin-contracts
rm -rf .env node_modules build flattened build-forge ethers-contracts lib/forge-std lib/openzeppelin-contracts
24 changes: 1 addition & 23 deletions ethereum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,9 @@ ethereum$ MNEMONIC= ./sh/upgrade.sh testnet TokenBridge blast
ethereum$ MNEMONIC= ./sh/registerAllChainsOnTokenBridge.sh.sh testnet blast
```

### Deploying using Truffle (deprecated)

To deploy the bridge on Ethereum you first need to compile all smart contracts:
`npx truffle compile`

To deploy you can either use the bytecode from the `build/contracts` folder or the oz cli `oz deploy <Contract>`
([Documentation](https://docs.openzeppelin.com/learn/deploying-and-interacting)).

You first need to deploy one `Wrapped Asset` and initialize it using dummy data.

Then deploy the `Wormhole` using the initial guardian key (`key_x,y_parity,0`) and the address of the previously deployed
`WrappedAsset`. The wrapped asset contract will be used as proxy library to all the creation of cheap proxy wrapped
assets.

### Testing

For each test run:

Run `npx ganache-cli --chain.vmErrorsOnRPCResponse --chain.chainId 1 --wallet.defaultBalance 10000 --wallet.deterministic --chain.time="1970-01-01T00:00:00+00:00" --chain.asyncRequestProcessing=false` to start a chain.

Run the all ethereum tests using `DEV=True make test`

Run a specific test file using `npx truffle test test/wormhole.js`

Run a specific test file while skipping compile `npx truffle test test/wormhole.js --compile-none`
Run the all ethereum tests using `make test`

### User methods

Expand Down
34 changes: 8 additions & 26 deletions ethereum/VERIFY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ transaction payloads according to the contract ABI.
This document outlines the process of verification. In general, you will need an
API key for the relevant explorer (this can be obtained by creating an account)
and to know at which address the contract code lives. The API key is expected to
be set in the `ETHERSCAN_KEY` environment variable for all APIs (not just
be set in the `ETHERSCAN_API_KEY` environment variable for all APIs (not just
etherscan, bit of a misnomer).

Our contracts are structured as a separate proxy and an implementation. Both of
Expand All @@ -19,39 +19,21 @@ verified each time it's upgraded.

## Verifying the proxy contract (first time)

The proxy contract is called `TokenBridge`. To verify it on e.g. avalanche, at contract address `0x0e082F06FF657D94310cB8cE8B0D9a04541d8052`, run
The proxy contract is called `TokenBridge`. To verify it on e.g. Ethereum, at contract address `0x3ee18B2214AFF97000D974cf647E7C347E8fa585`, run

```bash
forge verify-contract --etherscan-api-key $ETHERSCAN_API_KEY --verifier-url "https://api.etherscan.io/api" 0x3ee18B2214AFF97000D974cf647E7C347E8fa585 contracts/bridge/TokenBridge.sol:TokenBridge --watch
```
ETHERSCAN_KEY=... npm run verify --module=TokenBridge --contract_address=0x0e082F06FF657D94310cB8cE8B0D9a04541d8052 --network=avalanche
```

(Note: the network name comes from the `truffle-config.json`).
(Note: In this case, the `ETHERSCAN_KEY` is your snowtrace API key).


## Verifying the implementation contract (on each upgrade)

To verify the actual implementation, at address `0xa321448d90d4e5b0a732867c18ea198e75cac48e`, run
To verify the actual implementation, at address `0x381752f5458282d317d12c30d2bd4d6e1fd8841e`, run

```sh
ETHERSCAN_KEY=... npm run verify --module=BridgeImplementation --contract_address=0xa321448d90d4e5b0a732867c18ea198e75cac48e --network=avalanche
```bash
forge verify-contract --etherscan-api-key $ETHERSCAN_API_KEY --verifier-url "https://api.etherscan.io/api" 0x381752f5458282d317d12c30d2bd4d6e1fd8841e contracts/bridge/BridgeImplementation.sol:BridgeImplementation --watch
```

As a final step, when first registering the proxy contract, we need to verify
that it's a proxy that points to the implementation we just verified. This can
be done on avalanche at
https://snowtrace.io/proxyContractChecker?a=0x0e082F06FF657D94310cB8cE8B0D9a04541d8052

be done on ethereum at https://etherscan.io/proxyContractChecker
(other evm scanner sites have an identical page).


# Note
The `npm run verify` script uses the `truffle-plugin-verify` plugin under the
hood. The version of `truffle-plugin-verify` pinned in the repo (`^0.5.11` at
the time of writing) doesn't support the avalanche RPC. In later versions of the
plugin, support was added, but other stuff has changed as well in the transitive
dependencies, so it fails to parse the `HDWallet` arguments in our
`truffle-config.json`. As a quick workaround, we backport the patch to `0.5.11`
by applying the `truffle-verify-constants.patch` file, which the `npm run
verify` script does transparently. Once the toolchain has been upgraded and the
errors fixed, this patch can be removed.
1 change: 0 additions & 1 deletion ethereum/devnet_mnemonic.txt

This file was deleted.

20 changes: 10 additions & 10 deletions ethereum/docs/token_verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ https://moonscan.io/verifyContract and paste in contract address, in our case
`0xab3f0245b83feb11d15aaffefd7ad465a59817ed`. Fill in the rest of the form with
the following values, then continue.

| Field | Value |
| ---------------- | ------------------------- |
| Compiler type | Solidity (Single file) |
| Compiler version | v0.8.4+commit.c7e474f2 |
| License type | Apache-2 |
| Field | Value |
| ---------------- | ---------------------- |
| Compiler type | Solidity (Single file) |
| Compiler version | v0.8.4+commit.c7e474f2 |
| License type | Apache-2 |

On the next page, select "optimizations: yes", and paste the contents of
`token/Token.sol` from before into the source file textarea.
Expand All @@ -61,7 +61,7 @@ default.

## ABI-encoded constructor arguments

The last missing piece is the ABI-encoded constructor arguments field. These
The last missing piece is the ABI-encoded constructor arguments field. These
are the arguments that the contract was instantiated with, and it will be
different for each wrapped contract.
There are two ways to proceed. The first method is easier, but does not
Expand All @@ -77,8 +77,8 @@ At this point, some explorers will just return a generic error message saying
the bytecodes didn't match, without any additional information. If this is the
case, go to method #2.

If the page shows what the *expected* bytecode was, and lists out the *actual*
bytecodes it found in the source file, then we may proceed here. The *expected*
If the page shows what the _expected_ bytecode was, and lists out the _actual_
bytecodes it found in the source file, then we may proceed here. The _expected_
bytecode will be the same as the `BridgeToken` bytecode with the constructor
arguments appended to the end. This means that the `BridgeToken` bytecode is a
proper prefix of the expected bytecode. Just copy the rest of the bytes of the
Expand Down Expand Up @@ -130,7 +130,7 @@ section. Click "Decode input data" which will show the hex value of the
We copy this field and go back to our terminal. Run the following

```
wormhole/ethereum $ forge script scripts/TokenABI.s.sol -s "token_constructor_args(bytes, address)" <VAA-BYTES> <CONTRACT-ADDRESS>
wormhole/ethereum $ forge script forge-scripts/TokenABI.s.sol --tc BridgeScript -s "token_constructor_args(bytes, address)" <VAA-BYTES> <CONTRACT-ADDRESS>
```

where in place of `<VAA-BYTES>`, substitute the hex sequence we just copied from
Expand All @@ -143,5 +143,5 @@ Running that command prints the following:
0x000000000000000000000000b1731c586ca89a23809861c6103f0b96b3f57d9200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000164c71f461500000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000014c53000000000000000000000000b1731c586ca89a23809861c6103f0b96b3f57d920000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000d57726170706564204574686572000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004574554480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
```

Copy the hex *excluding* the 0x at the front, and paste that into the
Copy the hex _excluding_ the 0x at the front, and paste that into the
constructor arguments field, then hit verify. The contract should now be verified.
24 changes: 24 additions & 0 deletions ethereum/forge-scripts/DeployNFTBridgeImplementationOnly.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@


// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;
import {NFTBridgeImplementation} from "../contracts/nft/NFTBridgeImplementation.sol";
import "forge-std/Script.sol";

contract DeployNFTBridgeImplementationOnly is Script {
// DryRun - Deploy the system
function dryRun() public {
_deploy();
}
// Deploy the system
function run() public returns (address deployedAddress) {
vm.startBroadcast();
deployedAddress = _deploy();
vm.stopBroadcast();
}
function _deploy() internal returns (address deployedAddress) {
NFTBridgeImplementation impl = new NFTBridgeImplementation();

return address(impl);
}
}
4 changes: 2 additions & 2 deletions ethereum/forge-scripts/DeployNFTBridgeShutdown.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
pragma solidity ^0.8.4;
import {NFTBridgeShutdown} from "../contracts/nft/NFTBridgeShutdown.sol";
import "forge-std/Script.sol";

Expand All @@ -21,4 +21,4 @@ contract DeployNFTBridgeShutdown is Script {

return address(shutdown);
}
}
}
51 changes: 51 additions & 0 deletions ethereum/forge-scripts/TokenABI.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: Apache 2

pragma solidity ^0.8.0;

import "forge-std/Script.sol";
import "../contracts/Messages.sol";
import "../contracts/Structs.sol";
import "../contracts/bridge/Bridge.sol";
import "../contracts/bridge/BridgeStructs.sol";

contract BridgeTest is Bridge {

function token_constructor_args(bytes calldata encodedVM, address tokenBridge) public returns (bytes memory constructorArgs) {
Messages m = new Messages();
Structs.VM memory vm = m.parseVM(encodedVM);
BridgeStructs.AssetMeta memory meta = parseAssetMeta(vm.payload);
constructorArgs = token_constructor_args(bytes32ToString(meta.name), bytes32ToString(meta.symbol), meta.decimals, vm.sequence, tokenBridge, meta.tokenChain, meta.tokenAddress);
}

function token_constructor_args(string memory name, string memory symbol, uint8 decimals, uint64 sequence, address tokenBridge, uint16 tokenChain, bytes32 tokenAddress) pure public returns (bytes memory constructorArgs) {
bytes memory initialisationArgs = abi.encodeWithSelector(
TokenImplementation.initialize.selector,
name,
symbol,
decimals,
sequence,

tokenBridge,

tokenChain,
tokenAddress
);

constructorArgs = abi.encode(tokenBridge, initialisationArgs);
}
}

contract BridgeScript is Script {

// forge script forge-scripts/TokenABI.s.sol --tc BridgeScript -s "token_constructor_args(bytes, address)" 0x01000000020d00b7ba3819d44da891c74c583e29eb2222dd37dabbe7929bdbf4f2186bbcc721085d85d9906bbd8ca5ae62cdf30c7555dc4c57fd15f84a0161c27e91846203439c0102736caa697f6c17c2e6b0526291b0e6b4dec760a8494df7f69c93be3df1956224637ef962be9a28ef2dbeebe6bdb30311d9f2394966a1bb170634bd69913abfb200038c598c6e7c288c5dbb0f0008c38168d3f00ac8da7b3ad5420f30c8808c94a8a972c090d25da27558f1b8f8d30f894850d3139f4df92c8e8736be7803d397f33e0006649e6aca07694046fd94b5851ff3711783d4f4c8e0319f9de9431232cb153bce2ff2ac0f7bfad6f3db461571cd6ecffc99d7740a7b653d2f6a25908d821d9ca70107b31051fda4062585f80b291978a480cae6c9191d37a67bc2e1e61db8e97907fa71b5064d2ada48b4cd2f8c4def7fd50484004d1ceb3438a8f67ea071a31a6a88000af4842bbcd0fad425bd3b82bc3b1acefd72555fd1fbb49b71700ec2b41ac6309f20222e24c557f4ad6af35d96f1d4c38fb25177e027a22d2d071956d5d45985ba000bc0ebb4202aae662de331bce75d5e49ea97ac9a74df65006250c96ca9d82a16be6e78c577004a6059169aa7640436e1e5deef5d80bfa52784cf82f67bb368e066010d14586fa1f6f37d2c4d0eae78c42ecc3c9fc6bf17b3a57406382165d615cfb4a1651b979419c42e40a3f62fbe05eb3ff4bafac0af30c15a060e39d935776e54cc000e98d02eb76745301cb5fb12e6b0c7e3e9be347460ed51be360828c46be3bc40ef622f9234fb443b431db9e98980a7165b36eda10bd37abf6998156ebbdf96c4b6010fda503c3deb9c937709ab5742c4a44ed29f04664585c4c73568cd3b4863e1e2326b9cab4d1b139d9698585bb8abcbdc4072b3f98fdfe1b50fa35656c1451f862400106644b7697f41052d4d7c1685d342df4828c7ba7231f86c04476805271c58b4e30614ee43988072decec39f0400a48583f7b6d0fb109516385f73a64ce2a2b16501111cc03c23da18a3ed794cb944aa6d131306c243d13f207796c9ea9430a6c7da063b0ffbc75416c924b588ecc24c3d1c6136ea8e181a4f3d8c1d3d1831c7d4ae7301120b48f7b0c43cb43b4541d179f4bdfe6b9c83289b5b7cd494f6ea33eec062b36408606f4ad406365539d6b3a6b59b2eeae70baf0266c341fb476c8092d64ebd620062cb923534d80000000e000000000000000000000000796dff6d74f3e27060b71255fe517bfb23c93eed00000000000000560102000000000000000000000000765de816845861e75a25fca122bb6898b8b1282a000e12635553440000000000000000000000000000000000000000000000000000000043656c6f20446f6c6c6172000000000000000000000000000000000000000000 $(worm info contract mainnet ethereum TokenBridge)
function token_constructor_args(bytes calldata encodedVM, address tokenBridge) public {
BridgeTest bridge = new BridgeTest();
console.logBytes(bridge.token_constructor_args(encodedVM, tokenBridge));
}

// forge script forge-scripts/TokenABI.s.sol --tc BridgeScript -s "token_constructor_args(string,string,uint8,uint64,address,uint16,bytes32)" "Wrapped Ether" "WETH" 18 69201 0x796Dff6D74F3E27060B71255Fe517BFb23C93eed 2 0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
function token_constructor_args(string memory name, string memory symbol, uint8 decimals, uint64 sequence, address tokenBridge, uint16 tokenChain, bytes32 tokenAddress) public {
BridgeTest bridge = new BridgeTest();
console.logBytes(bridge.token_constructor_args(name, symbol, decimals, sequence, tokenBridge, tokenChain, tokenAddress));
}
}
15 changes: 0 additions & 15 deletions ethereum/migrations/10_deploy_batched_vaa_sender.js

This file was deleted.

6 changes: 0 additions & 6 deletions ethereum/migrations/1_initial_migration.js

This file was deleted.

34 changes: 0 additions & 34 deletions ethereum/migrations/2_deploy_wormhole.js

This file was deleted.

42 changes: 0 additions & 42 deletions ethereum/migrations/3_deploy_bridge.js

This file was deleted.

Loading

0 comments on commit 0a50809

Please sign in to comment.