Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sui Native bridge #17579

Merged
merged 87 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
f24c965
[native bridge move code 1/n] - native bridge move package (#16259)
patrickkuo Feb 16, 2024
5f3a386
move doc
patrickkuo Feb 16, 2024
9e518bb
[native bridge smart contract 2/n] - Add Bridge object to Sui framewo…
patrickkuo Feb 22, 2024
8ab546e
[native bridge move] bridge limiter (#16210)
longbowlu Feb 26, 2024
f63016a
[Native bridge move] tests for msg encoding and some changes (#16216)
longbowlu Feb 13, 2024
e71461f
[bridge move] governance actions (#16221)
longbowlu Feb 26, 2024
e632527
[bridge 43/n] add bridge types in sui-types and helper functions (#16…
longbowlu Feb 26, 2024
c97c9ab
[bridge 44/n] skeleton for bridge-api (#16293)
longbowlu Feb 26, 2024
98eebd8
[native bridge smart contract 7/n] - committee registration and initi…
patrickkuo Mar 1, 2024
a3c98a9
[bridge 45/n] replace env ids in Bridge Node (#16359)
longbowlu Mar 3, 2024
7190d6d
[bridge 46/n] replace remaining env ids in Bridge Node (#16358)
longbowlu Mar 3, 2024
6b68f08
[bridge 47/n] updates to limiter & get_token_transfer_action_status …
longbowlu Mar 5, 2024
6d6362c
fixup after rebase
patrickkuo Mar 7, 2024
7b6e7d1
[native bridge move] - revert unused sui sys changes (#16544)
patrickkuo Mar 19, 2024
8d22e89
[native bridge move] - remove sui_system new function dependency to a…
patrickkuo Mar 19, 2024
72311ff
fixup after rebase
patrickkuo Mar 19, 2024
5c35593
fixup after rebase
patrickkuo Mar 22, 2024
112fd90
fixup after rebase
patrickkuo Mar 26, 2024
8a73938
[native bridge] - bridge feature branch snapshot test fix (#16530)
patrickkuo Mar 26, 2024
13b5dab
[bridge 48/n] types: introduce a few more constants and move things t…
longbowlu Mar 27, 2024
36ac3aa
[bridge 49/n] use devInpsect to get on chain status (#16379)
longbowlu Mar 27, 2024
50d8533
[bridge] Bridge 2024 (#16883)
damirka Mar 27, 2024
0a31736
[bridge 50/n] use right threshold for different action types (#16378)
longbowlu Mar 27, 2024
3577414
[bridge 51/n] support build sui transaction for emergency op action (…
longbowlu Mar 27, 2024
7318e23
[bridge 52/n] support build sui transaction for committee blocklist u…
longbowlu Mar 27, 2024
863e149
[bridge 53/n] build sui transaction for limit update action (#16389)
longbowlu Mar 28, 2024
f6fee1f
[bridge 54/n] support build sui transaction for price update action (…
longbowlu Mar 28, 2024
1247d42
[bridge 56/n] update abi and eth event structs (#16438)
longbowlu Mar 28, 2024
72cf465
[bridge 57/n] enum-dispatch BridgeActions and move encoding logic to …
longbowlu Mar 28, 2024
14c0f36
[bridge 58/n] handle eth message conversion and transaction builder (…
longbowlu Mar 28, 2024
eaffd3d
[bridge 59/n] add bridge governance command to faciliate governance a…
longbowlu Mar 28, 2024
f64196e
[bridge 60/n] add a sui command to init bridge committee registration…
longbowlu Mar 28, 2024
58272e3
[bridge 61/n] polish governance client commands (#16508)
longbowlu Mar 28, 2024
2e9a721
[bridge 62/n] make `bridge_client_gas_object` optional, add tests for…
longbowlu Mar 28, 2024
c08eae0
[bridge/63] remove unnecessary fields in bridge config (#16840)
longbowlu Mar 28, 2024
8750dfc
[bridge 64/n] the first integration test (#16867)
longbowlu Mar 28, 2024
cb46828
Fix audit feedback on committee creation (#16909)
dariorussi Mar 28, 2024
b66f31f
[bridge 65/n] change tokenId from enum to u8, to prepare for the add …
longbowlu Mar 28, 2024
a98ab99
[bridge] enable some tests for sol changes (#16942)
longbowlu Mar 28, 2024
e8cf468
Utils config refactor (#16886)
Bridgerz Mar 29, 2024
d716029
Add Token Message (#16892)
Bridgerz Mar 29, 2024
e07cf64
token price uint256 => uint64 (#16933)
Bridgerz Mar 29, 2024
bdbf9ee
Signature verification Audit request (#16934)
Bridgerz Mar 29, 2024
77b26b4
[bridge 66/n] resume pending actions when node restarts (#16950)
longbowlu Mar 29, 2024
f17bacc
Check bridge routes on send token (#16960)
dariorussi Mar 30, 2024
9945369
[native-bridge] - add coins dynamically (#16904)
patrickkuo Mar 31, 2024
4ccdc2f
More audit, rename and invariants (#16924)
dariorussi Mar 31, 2024
c1e452c
Reset index in loop to restart member search (#16955)
dariorussi Mar 31, 2024
590f15f
[bridge 67/n] handle add_tokens_on_sui action, simplify test setup (#…
longbowlu Apr 2, 2024
35e044c
EVM Unit Tests Pre-Land (#16972)
Bridgerz Apr 2, 2024
9d23875
Unit tests and test coverage (#17078)
dariorussi Apr 8, 2024
69d58b7
[bridge 68/n] handle add_tokens_on_evm action, enhance sol tests and …
longbowlu Apr 8, 2024
034fe65
Update BridgeConfigTest.t.sol (#16984)
Bridgerz Apr 9, 2024
63a7356
Fix `crates/sui-bridge` build (#17118)
dariorussi Apr 11, 2024
76d0038
[bridge 69/n] add pub function `get_token_transfer_action_signatures`…
longbowlu Apr 15, 2024
7ef94ef
documentation update from audit (#17050)
Bridgerz Apr 15, 2024
d397ce9
Upgrade mechanism improvement (#17049)
Bridgerz Apr 15, 2024
9f8819b
Use SafeERC20 (#17019)
Bridgerz Apr 15, 2024
f6c3492
Bridge token message payload length (#17139)
Bridgerz Apr 16, 2024
ba71e4e
Add missing Evm contract tests (#17181)
Bridgerz Apr 16, 2024
fcfba00
Price decimal precision 4 => 8 (#16895)
Bridgerz Apr 17, 2024
908494b
Bridge Custom Networks (#17140)
Bridgerz Apr 17, 2024
300d26b
[bridge/70] cache the result of get_mutable_bridge_object_arg (#17152)
longbowlu Apr 17, 2024
bfeeae3
[bridge 71] remove stale comments (#17162)
longbowlu Apr 17, 2024
b01bb0d
Committee length < 256 (#17210)
Bridgerz Apr 18, 2024
d25329d
[bridge 72/n] rework node config a little bit (#17197)
longbowlu Apr 18, 2024
1033fee
Cleanup and test rework (#17116)
dariorussi Apr 19, 2024
c194382
E2E test refactor (#17138)
Bridgerz Apr 19, 2024
015d947
Move all ETH wrapping and unwrapping to vault (#17255)
Bridgerz Apr 21, 2024
3e3bd67
[bridge] use different foundry-out for each test run (#17258)
longbowlu Apr 22, 2024
bc7154c
[bridge 73] add `eth_contracts_start_block_fallback` (#17239)
longbowlu Apr 22, 2024
ca26c89
[native bridge] - fix bridge move test and enable test in CI (#17331)
patrickkuo Apr 25, 2024
e8e7e6f
[native bridge move] - fix limiter error handling (#17208)
patrickkuo Apr 25, 2024
e5bb838
[bridge] refactor test utils (#17288)
longbowlu Apr 25, 2024
8dbdff6
[bridge] add more sui events emitted in bridge.move (#17302)
longbowlu Apr 25, 2024
272831d
[bridge] rename `TokenBridgeEvent` to `TokenDepositedEvent` and remo…
longbowlu Apr 30, 2024
b60d1af
[bridge 76/n] add events for committee.move (#17374)
longbowlu May 2, 2024
6e258e2
[native-bridge] - committee registration cli tool (#17110)
patrickkuo May 2, 2024
4d6e9a3
[bridge] remove unnecessary &mut (#17470)
longbowlu May 2, 2024
112a6bb
Sui Bridge EVM Upgrade Action (#17266)
Bridgerz May 4, 2024
99f1e62
Disable upgrade safety in deployment script (#17553)
Bridgerz May 8, 2024
2cedaec
tests and move 2024 cleanup (#17517)
dariorussi May 8, 2024
f515446
fixup after rebase
patrickkuo May 8, 2024
72ef8a1
audit feedback (#17573)
dariorussi May 8, 2024
09e3522
Update BridgeVault.sol (#17231)
Bridgerz May 8, 2024
5bc4639
regen snapshots
patrickkuo May 9, 2024
bb61ecf
update snapshots
patrickkuo May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/actions/diffs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ outputs:
isMove:
description: True when changes happened to the Move code
value: "${{ steps.diff.outputs.isMove }}"
isSolidity:
description: True when changes happened to the Solidity code
value: "${{ steps.diff.outputs.isSolidity }}"
isReleaseNotesEligible:
description: True when changes happened in Release Notes eligible paths
value: "${{ steps.diff.outputs.isReleaseNotesEligible }}"
Expand Down Expand Up @@ -58,6 +61,8 @@ runs:
- 'Cargo.toml'
- 'examples/**'
- 'sui_programmability/**'
isSolidity:
- 'bridge/evm/**'
isReleaseNotesEligible:
- 'consensus/**'
- 'crates/**'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/narwhal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ jobs:
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 256
- name: Install Foundry
run: |
curl -L https://foundry.paradigm.xyz | { cat; echo '$FOUNDRY_BIN_DIR/foundryup'; } | bash
echo "$HOME/.config/.foundry/bin" >> $GITHUB_PATH
- name: cargo test
run: |
cargo nextest run --profile ci
Expand Down
33 changes: 31 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
outputs:
isRust: ${{ steps.diff.outputs.isRust }}
isMove: ${{ steps.diff.outputs.isMove }}
isSolidity: ${{ steps.diff.outputs.isSolidity }}
isReleaseNotesEligible: ${{ steps.diff.outputs.isReleaseNotesEligible }}
isMoveAutoFormatter: ${{ steps.diff.outputs.isMoveAutoFormatter }}
steps:
Expand Down Expand Up @@ -108,7 +109,7 @@ jobs:

test:
needs: diff
if: needs.diff.outputs.isRust == 'true'
if: needs.diff.outputs.isRust == 'true' || needs.diff.outputs.isSolidity == 'true'
timeout-minutes: 45
env:
# Tests written with #[sim_test] are often flaky if run as #[tokio::test] - this var
Expand All @@ -128,6 +129,10 @@ jobs:
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 256
- name: Install Foundry
run: |
curl -L https://foundry.paradigm.xyz | { cat; echo '$FOUNDRY_BIN_DIR/foundryup'; } | bash
echo "$HOME/.config/.foundry/bin" >> $GITHUB_PATH
- name: cargo test
run: |
cargo nextest run --profile ci
Expand Down Expand Up @@ -221,7 +226,7 @@ jobs:

simtest:
needs: diff
if: needs.diff.outputs.isRust == 'true'
if: needs.diff.outputs.isRust == 'true' || needs.diff.outputs.isSolidity == 'true'
timeout-minutes: 45
runs-on: [ubuntu-ghcloud]
env:
Expand Down Expand Up @@ -465,3 +470,27 @@ jobs:
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432

bridge-evm:
name: bridge-evm-tests
needs: diff
if: needs.diff.outputs.isSolidity == 'true'
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
- name: Install Foundry
run: |
curl -L https://foundry.paradigm.xyz | { cat; echo '$FOUNDRY_BIN_DIR/foundryup'; } | bash
echo "$HOME/.config/.foundry/bin" >> $GITHUB_PATH
- name: Install Dependencies
working-directory: bridge/evm
run: |
forge install https://github.com/OpenZeppelin/[email protected] https://github.com/foundry-rs/[email protected] https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades --no-git --no-commit
- name: Check Bridge EVM Unit Tests
shell: bash
working-directory: bridge/evm
env:
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}
run: |
forge clean
forge test --ffi
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ sui-analytics-indexer-derive = { path = "crates/sui-analytics-indexer-derive" }
sui-archival = { path = "crates/sui-archival" }
sui-authority-aggregation = { path = "crates/sui-authority-aggregation" }
sui-benchmark = { path = "crates/sui-benchmark" }
sui-bridge = { path = "crates/sui-bridge" }
sui-cluster-test = { path = "crates/sui-cluster-test" }
sui-common = { path = "crates/sui-common" }
sui-config = { path = "crates/sui-config" }
Expand Down
5 changes: 3 additions & 2 deletions bridge/evm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ cache*
network_config.json
.vscode
cache/
out/
out*/
*.txt
!remappings.txt
lcov.info
broadcast/**/31337

lib/*
lib/*

58 changes: 31 additions & 27 deletions bridge/evm/contracts/BridgeCommittee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,31 @@ contract BridgeCommittee is IBridgeCommittee, CommitteeUpgradeable {
mapping(address committeeMember => bool isBlocklisted) public blocklist;
IBridgeConfig public config;

/* ========== INITIALIZER ========== */
/* ========== INITIALIZERS ========== */

/// @notice Initializes the contract with the provided parameters.
/// @dev should be called directly after deployment (see OpenZeppelin upgradeable standards).
/// the provided arrays must have the same length and the total stake provided must equal 10000.
/// @param _config The address of the BridgeConfig contract.
/// the provided arrays must have the same length and the total stake provided must be greater than,
/// or equal to the provided minimum stake required.
/// @param committee addresses of the committee members.
/// @param stake amounts of the committee members.
function initialize(
address _config,
address[] memory committee,
uint16[] memory stake,
uint16 minStakeRequired
) external initializer {
/// @param minStakeRequired minimum stake required for the committee.
function initialize(address[] memory committee, uint16[] memory stake, uint16 minStakeRequired)
external
initializer
{
__CommitteeUpgradeable_init(address(this));
__UUPSUpgradeable_init();

uint256 _committeeLength = committee.length;

require(_committeeLength < 256, "BridgeCommittee: Committee length must be less than 256");

require(
_committeeLength == stake.length,
"BridgeCommittee: Committee and stake arrays must be of the same length"
);

config = IBridgeConfig(_config);

uint16 totalStake;
for (uint16 i; i < _committeeLength; i++) {
require(
Expand All @@ -57,19 +56,28 @@ contract BridgeCommittee is IBridgeCommittee, CommitteeUpgradeable {
require(totalStake >= minStakeRequired, "BridgeCommittee: total stake is less than minimum"); // 10000 == 100%
}

/// @notice Initializes the contract with the provided parameters.
/// @dev This function should be called directly after config deployment. The config contract address
/// provided should be verified before bridging any assets.
/// @param _config The address of the BridgeConfig contract.
function initializeConfig(address _config) external {
require(address(config) == address(0), "BridgeCommittee: Config already initialized");
config = IBridgeConfig(_config);
}

/* ========== EXTERNAL FUNCTIONS ========== */

/// @notice Verifies the provided signatures for the given message by aggregating and validating the
/// stake of each signer against the required stake of the given message type.
/// @dev The function will revert if the total stake of the signers is less than the required stake.
/// @param signatures The array of signatures to be verified.
/// @param message The `BridgeMessage.Message` to be verified.
function verifySignatures(bytes[] memory signatures, BridgeMessage.Message memory message)
/// @param message The `BridgeUtils.Message` to be verified.
function verifySignatures(bytes[] memory signatures, BridgeUtils.Message memory message)
external
view
override
{
uint32 requiredStake = BridgeMessage.requiredStake(message);
uint32 requiredStake = BridgeUtils.requiredStake(message);

uint16 approvalStake;
address signer;
Expand All @@ -81,19 +89,15 @@ contract BridgeCommittee is IBridgeCommittee, CommitteeUpgradeable {
// recover the signer from the signature
(bytes32 r, bytes32 s, uint8 v) = splitSignature(signature);

(signer,,) = ECDSA.tryRecover(BridgeMessage.computeHash(message), v, r, s);
(signer,,) = ECDSA.tryRecover(BridgeUtils.computeHash(message), v, r, s);

// skip if signer is block listed or has no stake
if (blocklist[signer] || committeeStake[signer] == 0) continue;
require(!blocklist[signer], "BridgeCommittee: Signer is blocklisted");
require(committeeStake[signer] > 0, "BridgeCommittee: Signer has no stake");

uint8 index = committeeIndex[signer];
uint256 mask = 1 << index;
if (bitmap & mask == 0) {
bitmap |= mask;
} else {
// skip if duplicate signature
continue;
}
require(bitmap & mask == 0, "BridgeCommittee: Duplicate signature provided");
bitmap |= mask;

approvalStake += committeeStake[signer];
}
Expand All @@ -103,18 +107,18 @@ contract BridgeCommittee is IBridgeCommittee, CommitteeUpgradeable {

/// @notice Updates the blocklist status of the provided addresses if provided signatures are valid.
/// @param signatures The array of signatures to validate the message.
/// @param message BridgeMessage containing the update blocklist payload.
/// @param message BridgeUtils containing the update blocklist payload.
function updateBlocklistWithSignatures(
bytes[] memory signatures,
BridgeMessage.Message memory message
BridgeUtils.Message memory message
)
external
nonReentrant
verifyMessageAndSignatures(message, signatures, BridgeMessage.BLOCKLIST)
verifyMessageAndSignatures(message, signatures, BridgeUtils.BLOCKLIST)
{
// decode the blocklist payload
(bool isBlocklisted, address[] memory _blocklist) =
BridgeMessage.decodeBlocklistPayload(message.payload);
BridgeUtils.decodeBlocklistPayload(message.payload);

// update the blocklist
_updateBlocklist(_blocklist, isBlocklisted);
Expand Down
Loading
Loading