Skip to content

Commit

Permalink
Merge branch 'tiago/bp-client-validation' (#1957)
Browse files Browse the repository at this point in the history
* origin/tiago/bp-client-validation:
  Changelog for #1957
  Validate Bridge pool client transfers
  Make ERC20 flow control fields public
  Check ERC20 token caps
  Add new SDK error types
  Factor out validate_bridge_pool_tx()
  Factor out submit_bridge_pool_tx()
  • Loading branch information
Fraccaman committed Oct 23, 2023
2 parents 3c7ecf8 + bbab1c4 commit a7fb040
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 74 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/SDK/1957-bp-client-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Validate Bridge pool transfers before submitting them to the network
([\#1957](https://github.com/anoma/namada/pull/1957))
26 changes: 2 additions & 24 deletions apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use color_eyre::eyre::Result;
use namada::types::io::Io;
use namada_sdk::tx::dump_tx;
use namada_sdk::{signing, Namada, NamadaImpl};
use namada_sdk::{Namada, NamadaImpl};

use crate::cli;
use crate::cli::api::{CliApi, CliClient};
Expand Down Expand Up @@ -220,28 +219,7 @@ impl CliApi {
client.wait_until_node_is_synced(io).await?;
let args = args.to_sdk(&mut ctx);
let namada = ctx.to_sdk(&client, io);
let tx_args = args.tx.clone();
let (mut tx, signing_data, _epoch) =
args.clone().build(&namada).await?;

signing::generate_test_vector(&namada, &tx).await?;

if args.tx.dump_tx {
dump_tx::<IO>(io, &args.tx, tx);
} else {
tx::submit_reveal_aux(
&namada,
tx_args.clone(),
&args.sender,
)
.await?;

namada
.sign(&mut tx, &tx_args, signing_data)
.await?;

namada.submit(tx, &tx_args).await?;
}
tx::submit_bridge_pool_tx(&namada, args).await?;
}
Sub::TxUnjailValidator(TxUnjailValidator(mut args)) => {
let client = client.unwrap_or_else(|| {
Expand Down
20 changes: 20 additions & 0 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ pub async fn submit_reveal_aux<'a>(
Ok(())
}

pub async fn submit_bridge_pool_tx<'a, N: Namada<'a>>(
namada: &N,
args: args::EthereumBridgePool,
) -> Result<(), error::Error> {
let tx_args = args.tx.clone();
let (mut tx, signing_data, _epoch) = args.clone().build(namada).await?;

signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
tx::dump_tx(namada.io(), &args.tx, tx);
} else {
submit_reveal_aux(namada, tx_args.clone(), &args.sender).await?;
namada.sign(&mut tx, &tx_args, signing_data).await?;
namada.submit(tx, &tx_args).await?;
}

Ok(())
}

pub async fn submit_custom<'a, N: Namada<'a>>(
namada: &N,
args: args::TxCustom,
Expand Down
13 changes: 13 additions & 0 deletions sdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use namada_core::proto::Tx;
use namada_core::types::address::Address;
use namada_core::types::dec::Dec;
use namada_core::types::ethereum_events::EthAddress;
use namada_core::types::storage;
use namada_core::types::storage::Epoch;
use prost::EncodeError;
Expand Down Expand Up @@ -324,6 +325,18 @@ pub enum EthereumBridgeError {
/// Invalid Bridge pool nonce error.
#[error("The Bridge pool nonce is invalid")]
InvalidBpNonce,
/// Invalid fee token error.
#[error("An invalid fee token was provided: {0}")]
InvalidFeeToken(Address),
/// Not whitelisted error.
#[error("ERC20 is not whitelisted: {0}")]
Erc20NotWhitelisted(EthAddress),
/// Exceeded token caps error.
#[error("ERC20 token caps exceeded: {0}")]
Erc20TokenCapsExceeded(EthAddress),
/// Transfer already in pool error.
#[error("An identical transfer is already present in the Bridge pool")]
TransferAlreadyInPool,
}

/// Checks if the given error is an invalid viewing key
Expand Down
Loading

0 comments on commit a7fb040

Please sign in to comment.