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

Remove non-essential fields from ERC20 transfer structs #1789

Merged
merged 48 commits into from
Sep 6, 2023
Merged
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
9ec1833
Add Eth whitelist storage keys
sug0 Jul 11, 2023
ed2afb2
Add Eth whitelist key tests
sug0 Jul 11, 2023
6ca25fd
Add non-usable tokens for Ethereum bridge protocol bookkeeping
sug0 Jul 11, 2023
5208f3d
Add a VP for NUT transfers
sug0 Jul 11, 2023
9c14b65
Test NUT VP
sug0 Jul 12, 2023
4901296
Trigger the NUT native VP
sug0 Jul 12, 2023
9b6df79
Update ethbridge-rs to v0.19.0
sug0 Jul 12, 2023
b932890
Add transfer to Ethereum kinds (ERC20 or NUT)
sug0 Jul 12, 2023
8297842
Mint NUTs upon receiving non-whitelisted assets or exceeding token caps
sug0 Jul 12, 2023
82320aa
Add helper fn to whitelist tokens in tests
sug0 Jul 12, 2023
1a70c4f
Fix unit tests requiring token whitelist checks
sug0 Jul 12, 2023
339e18a
Fix refunding and burning of NUTs
sug0 Jul 12, 2023
d115bb0
Rework DAI minting unit tests to account for NUTs
sug0 Jul 13, 2023
d26e983
Test burning NUTs
sug0 Jul 13, 2023
8de897d
Check NUT escrow in Bridge pool VP
sug0 Jul 14, 2023
a839866
Test NUTs in the Bridge pool
sug0 Jul 14, 2023
180c986
Add NUT cmdline flag for Bridge pool transfers
sug0 Jul 12, 2023
7732e24
Update ethbridge-rs to v0.20.0
sug0 Jul 13, 2023
92bb87f
Remove whitelist Ethereum events from the ledger
sug0 Jul 13, 2023
a1213c7
Add whitelisted ERC20 tokens to the genesis file
sug0 Jul 13, 2023
4777038
Update ethbridge-rs to v0.21.0
sug0 Jul 15, 2023
cde9503
Move ethbridge-rs deps to the workspace
sug0 Jul 31, 2023
20044d0
Add changelog entry for the Ethereum token whitelist
sug0 Jul 31, 2023
2ae23fb
Add helper methods to EthAssetMint
sug0 Aug 1, 2023
f1be3f9
Use EthAssetMint helper methods
sug0 Aug 1, 2023
6ef086f
Refactor redeem_native_token to use update::amount
sug0 Aug 1, 2023
f1bd957
Vet Ethereum bridge config of the native token
sug0 Aug 1, 2023
69037fb
Harden Bridge pool VP against wNAM NUT transfers
sug0 Aug 1, 2023
a26de50
Update wNAM supplies when acting on Ethereum events
sug0 Aug 1, 2023
c67a656
Allow null pre-balances during Bridge pool escrow checks
sug0 Aug 1, 2023
d3a4906
Flow control of NAM transferred to Ethereum
sug0 Aug 2, 2023
99fe477
Replace ERC20 supply RPC query with atomic read of all flow control data
sug0 Aug 2, 2023
2861e46
Refactor get_erc20_flow_control to use EthBridgeQueries
sug0 Aug 2, 2023
14556d7
Add test_wnam_doesnt_mint_nuts() unit test
sug0 Aug 2, 2023
7efe3c2
Fix test_wrapped_nam_not_burned() unit test
sug0 Aug 2, 2023
a714fb3
Fix test_redeem_native_token() unit test
sug0 Aug 2, 2023
0655085
Test that wrapped NAM is never minted
sug0 Aug 3, 2023
7a53732
Fix test_act_on_changes_storage_for_transfers_to_eth() unit test
sug0 Aug 2, 2023
c0b0ed5
Refactor Bridge pool tests to allow modifying pending transfer
sug0 Aug 2, 2023
d704d86
Add `asset` field to Balance
sug0 Aug 3, 2023
d90a5ea
New Bridge pool VP unit tests for wrapped NAM
sug0 Aug 3, 2023
75cf448
Fix wNAM edge cases in Bridge pool VP unit tests
sug0 Aug 3, 2023
fd1bf4d
Add invalidate_wnam_over_cap_tx() unit test
sug0 Aug 8, 2023
161cf43
Add changelog for #1781
sug0 Aug 3, 2023
b30a877
Update ethbridge-rs to v0.22.0
sug0 Aug 3, 2023
1a63f01
Fix compilation errors to support new `ethbridge-rs`
sug0 Aug 3, 2023
91b2fef
Test pending transfers and events have the same ABI encoding
sug0 Aug 7, 2023
5678ee7
Changelog for #1789
sug0 Aug 7, 2023
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
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/1290-token-whitelist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Implement Ethereum token whitelist.
([\#1290](https://github.com/anoma/namada/issues/1290))
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/1781-cap-wnam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Control the flow of NAM over the Ethereum bridge
([\#1781](https://github.com/anoma/namada/pull/1781))
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/1789-update-ethbridge-rs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Update ethbridge-rs to v0.22.0
([\#1789](https://github.com/anoma/namada/pull/1789))
24 changes: 12 additions & 12 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ directories = "4.0.1"
ed25519-consensus = "1.2.0"
escargot = "0.5.7"
ethabi = "18.0.0"
ethbridge-bridge-contract = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.22.0"}
ethbridge-bridge-events = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.22.0"}
ethbridge-events = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.22.0"}
ethbridge-governance-contract = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.22.0"}
ethbridge-governance-events = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.22.0"}
ethbridge-structs = { git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.22.0" }
ethers = "2.0.0"
expectrl = "0.7.0"
eyre = "0.6.5"
Expand Down
6 changes: 3 additions & 3 deletions apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ derivative.workspace = true
directories.workspace = true
ed25519-consensus.workspace = true
ethabi.workspace = true
ethbridge-bridge-events = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.18.0"}
ethbridge-events = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.18.0"}
ethbridge-governance-events = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.18.0"}
ethbridge-bridge-events.workspace = true
ethbridge-events.workspace = true
ethbridge-governance-events.workspace = true
eyre.workspace = true
fd-lock.workspace = true
ferveo-common.workspace = true
Expand Down
8 changes: 8 additions & 0 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,7 @@ pub mod args {
pub const NET_ADDRESS: Arg<SocketAddr> = arg("net-address");
pub const NAMADA_START_TIME: ArgOpt<DateTimeUtc> = arg_opt("time");
pub const NO_CONVERSIONS: ArgFlag = flag("no-conversions");
pub const NUT: ArgFlag = flag("nut");
pub const OUT_FILE_PATH_OPT: ArgOpt<PathBuf> = arg_opt("out-file-path");
pub const OUTPUT_FOLDER_PATH: ArgOpt<PathBuf> =
arg_opt("output-folder-path");
Expand Down Expand Up @@ -2787,6 +2788,7 @@ pub mod args {
impl CliToSdk<EthereumBridgePool<SdkTypes>> for EthereumBridgePool<CliTypes> {
fn to_sdk(self, ctx: &mut Context) -> EthereumBridgePool<SdkTypes> {
EthereumBridgePool::<SdkTypes> {
nut: self.nut,
tx: self.tx.to_sdk(ctx),
asset: self.asset,
recipient: self.recipient,
Expand All @@ -2809,6 +2811,7 @@ pub mod args {
let fee_amount = FEE_AMOUNT.parse(matches).amount;
let fee_payer = FEE_PAYER.parse(matches);
let code_path = PathBuf::from(TX_BRIDGE_POOL_WASM);
let nut = NUT.parse(matches);
Self {
tx,
asset,
Expand All @@ -2818,6 +2821,7 @@ pub mod args {
fee_amount,
fee_payer,
code_path,
nut,
}
}

Expand Down Expand Up @@ -2852,6 +2856,10 @@ pub mod args {
"The Namada address of the account paying the fee.",
),
)
.arg(NUT.def().help(
"Add Non Usable Tokens (NUTs) to the Bridge pool. These \
are usually obtained from invalid transfers to Namada.",
))
}
}

Expand Down
12 changes: 11 additions & 1 deletion apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,10 +909,13 @@ pub fn genesis(
}
#[cfg(any(test, feature = "dev"))]
pub fn genesis(num_validators: u64) -> Genesis {
use namada::ledger::eth_bridge::{Contracts, UpgradeableContract};
use namada::ledger::eth_bridge::{
Contracts, Erc20WhitelistEntry, UpgradeableContract,
};
use namada::types::address::{
self, apfel, btc, dot, eth, kartoffel, nam, schnitzel, wnam,
};
use namada::types::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS;
use namada::types::ethereum_events::EthAddress;

use crate::wallet;
Expand Down Expand Up @@ -1115,6 +1118,13 @@ pub fn genesis(num_validators: u64) -> Genesis {
gov_params: GovernanceParameters::default(),
pgf_params: PgfParameters::default(),
ethereum_bridge_params: Some(EthereumBridgeConfig {
erc20_whitelist: vec![Erc20WhitelistEntry {
token_address: DAI_ERC20_ETH_ADDRESS,
token_cap: token::DenominatedAmount {
amount: token::Amount::max(),
denom: 18.into(),
},
}],
eth_start_height: Default::default(),
min_confirmations: Default::default(),
contracts: Contracts {
Expand Down
121 changes: 46 additions & 75 deletions apps/src/lib/node/ledger/ethereum_oracle/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ pub mod eth_events {
};
use ethbridge_events::{DynEventCodec, Events as RawEvents};
use ethbridge_governance_events::{
GovernanceEvents, NewContractFilter, UpdateBridgeWhitelistFilter,
UpgradedContractFilter, ValidatorSetUpdateFilter,
GovernanceEvents, NewContractFilter, UpgradedContractFilter,
ValidatorSetUpdateFilter,
};
use namada::core::types::ethereum_structs;
use namada::eth_bridge::ethers::contract::EthEvent;
use namada::types::address::Address;
use namada::types::ethereum_events::{
EthAddress, EthereumEvent, TokenWhitelist, TransferToEthereum,
TransferToNamada, Uint,
EthAddress, EthereumEvent, TransferToEthereum, TransferToNamada, Uint,
};
use namada::types::hash::Hash;
use namada::types::keccak::KeccakHash;
use namada::types::token::Amount;
use num256::Uint256;
Expand Down Expand Up @@ -106,31 +106,6 @@ pub mod eth_events {
NewContractFilter::name().into(),
));
}
RawEvents::Governance(
GovernanceEvents::UpdateBridgeWhitelistFilter(
UpdateBridgeWhitelistFilter {
nonce,
tokens,
token_cap,
},
),
) => {
let mut whitelist = vec![];

for (token, cap) in
tokens.into_iter().zip(token_cap.into_iter())
{
whitelist.push(TokenWhitelist {
token: token.parse_eth_address()?,
cap: cap.parse_amount()?,
});
}

EthereumEvent::UpdateBridgeWhitelist {
nonce: nonce.parse_uint256()?,
whitelist,
}
}
RawEvents::Governance(
GovernanceEvents::UpgradedContractFilter(
UpgradedContractFilter { name: _, addr: _ },
Expand Down Expand Up @@ -178,24 +153,33 @@ pub mod eth_events {
};
}

/// Trait to add parsing methods to foreign types.
trait Parse: Sized {
parse_method! { parse_eth_address -> EthAddress }
parse_method! { parse_address -> Address }
parse_method! { parse_amount -> Amount }
parse_method! { parse_u32 -> u32 }
parse_method! { parse_uint256 -> Uint }
parse_method! { parse_bool -> bool }
parse_method! { parse_string -> String }
parse_method! { parse_keccak -> KeccakHash }
parse_method! { parse_amount_array -> Vec<Amount> }
parse_method! { parse_eth_address_array -> Vec<EthAddress> }
parse_method! { parse_address_array -> Vec<Address> }
parse_method! { parse_string_array -> Vec<String> }
parse_method! { parse_transfer_to_namada_array -> Vec<TransferToNamada> }
parse_method! { parse_transfer_to_namada -> TransferToNamada }
parse_method! { parse_transfer_to_eth_array -> Vec<TransferToEthereum> }
parse_method! { parse_transfer_to_eth -> TransferToEthereum }
macro_rules! trait_parse_def {
($($name:ident -> $type:ty;)*) => {
/// Trait to add parsing methods to foreign types.
trait Parse: Sized {
$( parse_method!($name -> $type); )*
}
}
}

trait_parse_def! {
parse_address -> Address;
parse_address_array -> Vec<Address>;
parse_amount -> Amount;
parse_amount_array -> Vec<Amount>;
parse_bool -> bool;
parse_eth_address -> EthAddress;
parse_eth_address_array -> Vec<EthAddress>;
parse_hash -> Hash;
parse_keccak -> KeccakHash;
parse_string -> String;
parse_string_array -> Vec<String>;
parse_transfer_to_eth -> TransferToEthereum;
parse_transfer_to_eth_array -> Vec<TransferToEthereum>;
parse_transfer_to_namada -> TransferToNamada;
parse_transfer_to_namada_array -> Vec<TransferToNamada>;
parse_u32 -> u32;
parse_uint256 -> Uint;
}

impl Parse for ethabi::Address {
Expand All @@ -217,7 +201,13 @@ pub mod eth_events {

impl Parse for ethabi::Uint {
fn parse_amount(self) -> Result<Amount> {
Ok(Amount::from(self.as_u64()))
let uint = {
use namada::core::types::uint::Uint as NamadaUint;
let mut num_buf = [0; 32];
self.to_little_endian(&mut num_buf);
NamadaUint::from_little_endian(&num_buf)
};
Amount::from_uint(uint, 0).map_err(|e| Error::Decode(e.to_string()))
}

fn parse_u32(self) -> Result<u32> {
Expand All @@ -239,6 +229,10 @@ pub mod eth_events {
fn parse_keccak(self) -> Result<KeccakHash> {
Ok(KeccakHash(self))
}

fn parse_hash(self) -> Result<Hash> {
Ok(Hash(self))
}
}

impl Parse for Vec<ethabi::Uint> {
Expand Down Expand Up @@ -298,17 +292,13 @@ pub mod eth_events {
fn parse_transfer_to_eth(self) -> Result<TransferToEthereum> {
let asset = self.from.parse_eth_address()?;
let receiver = self.to.parse_eth_address()?;
let sender = self.sender.parse_address()?;
let amount = self.amount.parse_amount()?;
let gas_payer = self.fee_from.parse_address()?;
let gas_amount = self.fee.parse_amount()?;
let checksum = self.namada_data_digest.parse_hash()?;
Ok(TransferToEthereum {
asset,
amount,
sender,
receiver,
gas_amount,
gas_payer,
checksum,
})
}
}
Expand All @@ -332,7 +322,7 @@ pub mod eth_events {
use ethabi::ethereum_types::{H160, U256};
use ethbridge_events::{
TRANSFER_TO_ERC_CODEC, TRANSFER_TO_NAMADA_CODEC,
UPDATE_BRIDGE_WHITELIST_CODEC, VALIDATOR_SET_UPDATE_CODEC,
VALIDATOR_SET_UPDATE_CODEC,
};
use namada::eth_bridge::ethers::abi::AbiEncode;

Expand Down Expand Up @@ -526,10 +516,8 @@ pub mod eth_events {
ethereum_structs::Erc20Transfer {
from: H160([1; 20]),
to: H160([2; 20]),
sender: address.clone(),
amount: 0u64.into(),
fee_from: address.clone(),
fee: 0u64.into(),
namada_data_digest: [0; 32],
};
2
],
Expand All @@ -542,11 +530,6 @@ pub mod eth_events {
bridge_validator_set_hash: [1; 32],
governance_validator_set_hash: [2; 32],
};
let whitelist = UpdateBridgeWhitelistFilter {
nonce: 0u64.into(),
tokens: vec![H160([0; 20]); 2],
token_cap: vec![0u64.into(); 2],
};
assert_eq!(
{
let decoded: TransferToNamadaFilter =
Expand Down Expand Up @@ -582,18 +565,6 @@ pub mod eth_events {
},
update
);
assert_eq!(
{
let decoded: UpdateBridgeWhitelistFilter =
UPDATE_BRIDGE_WHITELIST_CODEC
.decode(&get_log(whitelist.clone().encode()))
.expect("Test failed")
.try_into()
.expect("Test failed");
decoded
},
whitelist
);
}

/// Return an Ethereum events log, from the given encoded event
Expand Down
Loading