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

Merge reality back to main #25

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
721ba30
(feat) Zilbridge compatibility contracts.
rrw-zilliqa Aug 30, 2024
a2b5107
(feat) Update trunk in an attempt to get it to obey the configuration…
rrw-zilliqa Aug 30, 2024
8c31637
(fix) Trunk now complains about its own auto-generated default config…
rrw-zilliqa Aug 30, 2024
2996c8a
(feat) Allow the UI to use zilbridge compatibility test tokens.
rrw-zilliqa Aug 30, 2024
d251a5d
(fix) Fix typescript compile
rrw-zilliqa Aug 30, 2024
7793dcb
(feat) A LockProxyProxy contract which limits access to the LockProxy…
rrw-zilliqa Nov 6, 2024
266e8af
Start of zilbridge migration
rrw-zilliqa Dec 19, 2024
380c83c
(fix) Remove spurious transfer function
rrw-zilliqa Dec 19, 2024
2a7a7a0
(feat) DummyLockProxyProxy
rrw-zilliqa Dec 20, 2024
3662a32
(feat) Deploy token managers to zilliqa
rrw-zilliqa Dec 20, 2024
51203a4
(feat) more docs
rrw-zilliqa Dec 20, 2024
95368e7
Update scripts
rrw-zilliqa Dec 20, 2024
028da62
(feat) Deploy token managers to bsc.
rrw-zilliqa Dec 20, 2024
4b64fac
(feat) Deploy to polygon
rrw-zilliqa Dec 20, 2024
674967d
(feat) Managers deployed to everything other than eth, I think. Now r…
rrw-zilliqa Dec 20, 2024
92ad6aa
(fix) You should never use the Zilliqa mainnet unrestricted lockproxy…
rrw-zilliqa Dec 23, 2024
bec51bf
(fix) Check that the remote token manager exists before trying to use…
rrw-zilliqa Dec 23, 2024
652006b
(fix) Fixes for deployment scripts to account for renaming in mainnet…
rrw-zilliqa Dec 23, 2024
7a0dbd1
(feat) Start of an exception list
rrw-zilliqa Dec 23, 2024
da22940
(feat) An exceptions facility so that we can retroactively correct (s…
rrw-zilliqa Dec 24, 2024
9c3b011
(feat) Allow zero value transfers, for special effects.
rrw-zilliqa Dec 24, 2024
dc7b749
(fix) Bring broadcast back in so we have a record of what was broadcast.
rrw-zilliqa Dec 27, 2024
80c8cc8
(feat) Add polygon routing.
rrw-zilliqa Dec 27, 2024
a293a5b
(feat) more zilbridge transition scripts
rrw-zilliqa Dec 27, 2024
bcbfac6
(feat) Add polygon bridging
rrw-zilliqa Jan 7, 2025
bc83607
(feat) Add a scale factor to the V4 token maanager
rrw-zilliqa Jan 7, 2025
0034e16
(feat) Update storage layout.
rrw-zilliqa Jan 7, 2025
b2a3f4c
(feat) Ability to remove tokens.
rrw-zilliqa Jan 7, 2025
8eaa798
(feat) More tests - including a scale test that fails. Next step is t…
rrw-zilliqa Jan 7, 2025
d143a03
(fix) Fix scaling function
rrw-zilliqa Jan 8, 2025
599477f
(feat) Overflow test.
rrw-zilliqa Jan 8, 2025
1dc0238
(feat) Deployment scripts and config for upgrading testnet token mana…
rrw-zilliqa Jan 8, 2025
3481f78
(feat) Zilliqa side token manager upgrade script
rrw-zilliqa Jan 8, 2025
28f5fc2
(feat) Update (new) token managers on Zilliqa mainnet and Polygon to …
rrw-zilliqa Jan 9, 2025
5aa1251
(feat) bridge-web: force Zilliqa to be one of the networks to bridge …
rrw-zilliqa Jan 10, 2025
05b8b5a
(feat) Deployment scripts for Ethereum
rrw-zilliqa Jan 12, 2025
dfd993a
(feat) Go back to the old lockProxyProxy on eth, because it is the on…
rrw-zilliqa Jan 13, 2025
1aef6f8
(fix) config updates.
rrw-zilliqa Jan 13, 2025
c8d620c
(feat) Support for explicitly calling eth_maxPriorityFeePerGas becaus…
rrw-zilliqa Jan 13, 2025
011c1e0
(fix) Fix trigger
rrw-zilliqa Jan 13, 2025
03eaa0a
(feat) Start of a token manager which can cope with Tether
rrw-zilliqa Jan 14, 2025
bdf03e8
(feat) A version of the lock and release token manager which copes wi…
rrw-zilliqa Jan 14, 2025
7a37607
(feat) Support for USDT.
rrw-zilliqa Jan 14, 2025
90a562c
(feat) Token logos
rrw-zilliqa Jan 15, 2025
28e2784
(fix) FEES should have the same name at both ends.
rrw-zilliqa Jan 15, 2025
c435e86
(fix) Fix env vars and rotate keys
rrw-zilliqa Jan 15, 2025
3779cd3
(fix) Routing changes.
rrw-zilliqa Jan 20, 2025
ff57569
(fix) Use stable foundry to compile contracts (so that it works - nig…
rrw-zilliqa Jan 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci-bridge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
version: stable

- name: Run Foundry tests
run: forge test --gas-limit 2000000000000 # arbitrary, but seemingly no way to disable entirely.
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cicd-prd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- main
workflow_dispatch:
# On released
release:
types: [published]
Expand Down
56 changes: 31 additions & 25 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
# To learn more about the format of this file,
# see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.22.3
version: 1.22.4
# Trunk provides extensibility via plugins.
# (https://docs.trunk.io/plugins)
plugins:
sources:
- id: trunk
ref: v1.6.2
uri: https://github.com/trunk-io/plugins

# Many linters and tools depend on runtimes -
# configure them here. (https://docs.trunk.io/runtimes)
runtimes:
enabled:
- [email protected]
- [email protected]
# This is the section where you manage your linters.
# (https://docs.trunk.io/check/configuration)
lint:
enabled:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- git-diff-check
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
# - [email protected] - removed for being over-prissy and wanting tab indents - rrw 2023-04-25
- [email protected]
- [email protected]
- [email protected]
- [email protected]
ignore:
- linters: [osv-scanner]
paths:
- scilla-contracts/**
- linters: [gitleaks]
paths:
- smart-contracts/script/config.ts
Expand All @@ -39,6 +46,7 @@ lint:
- linters: [eslint]
paths:
- bridge-web
- scilla-contracts
- linters: [ALL]
paths:
- .devcontainer/*
Expand All @@ -57,15 +65,13 @@ lint:
- "**/templates/*"
- "templates/**"
- "**/templates/**"
- smart-contracts/broadcast/**
- smart-contracts/test/zilbridge/tokens/switcheo/**

runtimes:
enabled:
- [email protected]
- [email protected]
- [email protected]
actions:
enabled:
disabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
enabled:
- trunk-upgrade-available
7 changes: 7 additions & 0 deletions bridge-validators/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ legacy_gas_estimation_percent = 130
## fetching the receipt and scanning it for relevant logs. This is slow, but at least it works ..
## use_get_transactions = true

## Defines the exception set - events that should be treated like other events.
## This is used for exceptional reprocessing of bridge transactions that have been generated
## as the result of bugs and need to be reprocessed.
## Annoyingly, the exceptions must be single-line as otherwise the toml parser will complain.
##exceptions = [
## { transaction_id = "0xa4738bffe20fff0d71d449685ad8e252dc2645948034d0e1ca12772422744b0c", block_hash="0xb71c1c134044480d1ffd1b7822382769b160b38729a27b35d14c5093b93911c9", block_number=46770995, chain_id="0x61", replacement_bytes="0x00000000000000000000000041823941d00f47ea1a98d75586915bf828f4a038000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000f4240000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e41a90748a000000000000000000000000000000000000000000000000000000000000006100000000000000000000000036b8a9cd6bf9bfa5984093005cf81cafb1bf06f7000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000600000000000000000000000009be4dcfb335a263c65a8a763d55710718bbdb416000000000000000000000000b85ff091342e2e7a7461238796d5224fa81ca556000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000", replacement_chainid="0x000000000000000000000000000000000000000000000000000000000000814d" }]


# BSC Mainnet
# [[chain_configs]]
Expand Down
9 changes: 7 additions & 2 deletions bridge-validators/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ impl ChainClient {
}
if matches {
info!("Event matches; pushing for transit");
result.push(log);
if let Some(v) = self.except.transform_log(&log) {
result.push(v);
} else {
info!("Log {log:?} could not be sent for transit due transform_log() failure");
}
}
}
} else {
Expand Down Expand Up @@ -202,6 +206,7 @@ impl BlockPolling for ChainClient {

let events: Vec<D> = logs
.into_iter()
.filter_map(|log| self.except.transform_log(&log))
.map(|log| Ok(parse_log::<D>(log)?))
.collect::<Result<Vec<D>>>()?;

Expand Down Expand Up @@ -311,7 +316,7 @@ impl<D: EthEvent> EventListener<D> {
let mut interval = interval(Duration::from_secs(3));
// Set this down 1 because we (almost) certainly haven't scanned this block
// yet...
self.current_block = self.chain_client.client.get_block_number().await? - 1;
self.current_block = self.get_block_number().await? - 1;

loop {
interval.tick().await;
Expand Down
12 changes: 10 additions & 2 deletions bridge-validators/src/bridge_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ impl BridgeNode {
}

pub async fn sync_historic_events(&mut self) -> Result<()> {
if self.chain_client.chain_gateway_block_deployed == 0 {
warn!(
"block_deployed=0 , so not synchronising historic events for chain id {}",
self.chain_client.chain_id
);
return Ok(());
}

let max_block_specifier = if self.chain_client.block_instant_finality {
BlockNumber::Latest
} else {
Expand All @@ -103,7 +111,7 @@ impl BridgeNode {
let to_block_number = if let Some(v) = self.chain_client.to_block_number {
if v > finalized_block_number.as_u64() {
warn!("to_block in config file {} was greater than latest finalized block {} - will terminate at {}",
v, finalized_block_number, v);
v, finalized_block_number, finalized_block_number);
}
std::cmp::min(v, finalized_block_number.as_u64())
} else {
Expand Down Expand Up @@ -305,7 +313,7 @@ impl BridgeNode {
};

if !self.validators.contains(&address) {
info!("Address not part of the validator set, {}", address);
info!("Address not part of the validator set, {:x}", address);
return Ok(());
}

Expand Down
12 changes: 9 additions & 3 deletions bridge-validators/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use crate::{ChainGateway, ValidatorManager};
use crate::{exceptions, ChainGateway, ValidatorManager};
use anyhow::Result;
use ethers::{
middleware::{MiddlewareBuilder, NonceManagerMiddleware, SignerMiddleware},
Expand Down Expand Up @@ -33,10 +33,13 @@ pub struct ChainClient {
pub wallet: LocalWallet,
pub chain_gateway_block_deployed: u64,
pub block_instant_finality: bool,
pub legacy_gas_estimation_percent: Option<u64>,
pub gas_estimation_percent: Option<u64>,
pub use_legacy_transactions: bool,
pub scan_behind_blocks: u64,
pub log_strategy: LogStrategy,
pub to_block_number: Option<u64>,
pub priority_fee_per_gas_max: Option<u64>,
pub except: exceptions::ExceptionProcessor,
}

impl fmt::Display for ChainClient {
Expand Down Expand Up @@ -102,10 +105,13 @@ impl ChainClient {
wallet,
chain_gateway_block_deployed: config.chain_gateway_block_deployed,
block_instant_finality: config.block_instant_finality.unwrap_or_default(),
legacy_gas_estimation_percent: config.legacy_gas_estimation_percent,
gas_estimation_percent: config.gas_estimation_percent,
use_legacy_transactions: config.use_legacy_transactions.unwrap_or(false),
scan_behind_blocks: config.scan_behind_blocks.unwrap_or_default(),
log_strategy: strategy,
to_block_number: config.to_block_number,
priority_fee_per_gas_max: config.priority_fee_per_gas_max,
except: exceptions::ExceptionProcessor::new(config, chain_id),
})
}
}
Expand Down
54 changes: 54 additions & 0 deletions bridge-validators/src/exceptions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use crate::{ChainConfig, Exception};
use ethers::types::{Log, H256, U256};
use std::collections::HashMap;
use tracing::warn;

/// The exception processor handles exceptions - these are txns which were issued in error, usually as a result
/// of a bug in the relayer contracts; their parameters are corrected here before being passed on to the rest of
/// the relayer logic for execution.
#[derive(Debug, Clone)]
pub struct ExceptionProcessor {
exceptions_by_txnhash: HashMap<H256, Exception>,
}

impl ExceptionProcessor {
pub fn new(config: &ChainConfig, chain_id: U256) -> Self {
let mut exceptions_by_txnhash = HashMap::new();
config.exceptions.iter().for_each(|v| {
v.iter().for_each(|i| {
if i.chain_id == chain_id {
exceptions_by_txnhash.insert(i.transaction_id, i.clone());
}
})
});
warn!(
"Loaded {0} exceptions for chain_id {1}",
exceptions_by_txnhash.len(),
chain_id
);
ExceptionProcessor {
exceptions_by_txnhash,
}
}

// We'll warn!() if we have to drop a log.
pub fn transform_log(&self, log: &Log) -> Option<Log> {
if let Some(hash) = log.transaction_hash {
if let Some(except) = self.exceptions_by_txnhash.get(&hash) {
if log
.block_number
.map_or(false, |x| x.as_u64() == except.block_number)
&& log.block_hash.map_or(false, |x| x == except.block_hash)
&& log.topics.len() == 2
{
let mut new_log = log.clone();
new_log.topics[1] = except.replacement_chainid;
new_log.data = except.replacement_bytes.clone();
warn!("Found a match for exception {except:?} with log {log:?} - replacing log data to form {new_log:?}");
return Some(new_log);
}
}
}
Some(log.clone())
}
}
33 changes: 31 additions & 2 deletions bridge-validators/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod bridge_node;
mod client;
mod crypto;
mod event;
mod exceptions;
mod message;
mod p2p_node;
mod signature;
Expand All @@ -12,9 +13,14 @@ use std::{fs, path::PathBuf};

use anyhow::Result;
use clap::Parser;
use ethers::{contract::abigen, types::Address};
use ethers::{
contract::abigen,
types::{Address, Bytes, H256, U256},
utils::hex,
};
use libp2p::{Multiaddr, PeerId};
use serde::Deserialize;
use serde::{de::Error, Deserializer};
use tracing::info;
use tracing_subscriber::EnvFilter;
use validator_node::ValidatorNodeConfig;
Expand All @@ -24,17 +30,40 @@ use crate::{crypto::SecretKey, p2p_node::P2pNode};
abigen!(ChainGateway, "abi/ChainGateway.json",);
abigen!(ValidatorManager, "abi/ValidatorManager.json");

#[derive(Debug, Clone, Deserialize)]
pub struct Exception {
pub transaction_id: H256,
pub block_hash: H256,
pub block_number: u64,
pub chain_id: U256,
#[serde(deserialize_with = "from_hex")]
pub replacement_bytes: Bytes,
pub replacement_chainid: H256,
}

fn from_hex<'de, D>(deserializer: D) -> Result<Bytes, D::Error>
where
D: Deserializer<'de>,
{
let s: String = Deserialize::deserialize(deserializer)?;
let some_bytes = hex::decode(s).map_err(D::Error::custom)?;
Ok(Bytes::from(some_bytes))
}

#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ChainConfig {
pub rpc_url: String,
pub chain_gateway_address: Address,
pub chain_gateway_block_deployed: u64,
pub block_instant_finality: Option<bool>,
pub legacy_gas_estimation_percent: Option<u64>,
pub gas_estimation_percent: Option<u64>,
pub use_legacy_transactions: Option<bool>,
pub scan_behind_blocks: Option<u64>,
pub use_get_transactions: Option<bool>,
pub to_block_number: Option<u64>,
pub priority_fee_per_gas_max: Option<u64>,
pub exceptions: Option<Vec<Exception>>,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down
Loading
Loading