Skip to content

Commit

Permalink
validate that fee contract is provided for fee upgrade (#2050)
Browse files Browse the repository at this point in the history
* validate that fee contract is provided for fee upgrade

* added a validation check and test if the fee contract address is address(0) for an upgrade
  • Loading branch information
alysiahuggins authored Sep 26, 2024
1 parent 67eac10 commit f30ef38
Showing 1 changed file with 131 additions and 2 deletions.
133 changes: 131 additions & 2 deletions sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use anyhow::Context;
use espresso_types::{
v0_3::ChainConfig, FeeAccount, FeeAmount, GenesisHeader, L1BlockInfo, Upgrade, UpgradeType,
};
use ethers::providers::{Http, Provider};
use ethers::{
providers::{Http, Provider},
types::H160,
};
use sequencer_utils::deployer::is_proxy_contract;
use serde::{Deserialize, Serialize};
use vbs::version::Version;
Expand Down Expand Up @@ -91,9 +94,15 @@ impl Genesis {
match &upgrade.upgrade_type {
UpgradeType::Fee { chain_config } | UpgradeType::Marketplace { chain_config } => {
if let Some(fee_contract_address) = chain_config.fee_contract {
if !is_proxy_contract(provider.clone(), fee_contract_address).await? {
if fee_contract_address == H160::zero() {
anyhow::bail!("Fee contract cannot use the zero address");
} else if !is_proxy_contract(provider.clone(), fee_contract_address).await?
{
anyhow::bail!("Fee contract's address is not a proxy");
}
} else {
// The Fee Contract address has to be provided for an upgrade so return an error
anyhow::bail!("Fee contract's address for the upgrade is missing");
}
}
}
Expand Down Expand Up @@ -662,6 +671,126 @@ mod test {
}
}

#[async_std::test]
async fn test_genesis_missing_fee_contract_with_upgrades() {
let toml = toml! {
base_version = "0.1"
upgrade_version = "0.2"

[stake_table]
capacity = 10

[chain_config]
chain_id = 12345
max_block_size = 30000
base_fee = 1
fee_recipient = "0x0000000000000000000000000000000000000000"

[header]
timestamp = 123456

[l1_finalized]
number = 42

[[upgrade]]
version = "0.2"
start_proposing_view = 5
stop_proposing_view = 15

[upgrade.fee]

[upgrade.fee.chain_config]
chain_id = 12345
max_block_size = 30000
base_fee = 1
fee_recipient = "0x0000000000000000000000000000000000000000"

[[upgrade]]
version = "0.3"
start_proposing_view = 5
stop_proposing_view = 15

[upgrade.marketplace]
[upgrade.marketplace.chain_config]
chain_id = 999999999
max_block_size = 3000
base_fee = 1
fee_recipient = "0x0000000000000000000000000000000000000000"
bid_recipient = "0x0000000000000000000000000000000000000000"
fee_contract = "0xa15bb66138824a1c7167f5e85b957d04dd34e468" //not a proxy
}
.to_string();

let genesis: Genesis = toml::from_str(&toml).unwrap_or_else(|err| panic!("{err:#}"));
let rpc_url = "https://ethereum-sepolia.publicnode.com";

// validate the fee_contract address
let result = genesis.validate_fee_contract(rpc_url.to_string()).await;

// check if the result from the validation is an error
if let Err(e) = result {
// assert that the error message contains "Fee contract's address is not a proxy"
assert!(e
.to_string()
.contains("Fee contract's address for the upgrade is missing"));
} else {
panic!("Expected the fee contract to be missing, but the validation succeeded");
}
}

#[async_std::test]
async fn test_genesis_upgrade_fee_contract_address_is_zero() {
let toml = toml! {
base_version = "0.1"
upgrade_version = "0.2"

[stake_table]
capacity = 10

[chain_config]
chain_id = 12345
max_block_size = 30000
base_fee = 1
fee_recipient = "0x0000000000000000000000000000000000000000"

[header]
timestamp = 123456

[l1_finalized]
number = 42

[[upgrade]]
version = "0.2"
start_proposing_view = 5
stop_proposing_view = 15

[upgrade.fee]
[upgrade.fee.chain_config]
chain_id = 12345
max_block_size = 30000
base_fee = 1
fee_recipient = "0x0000000000000000000000000000000000000000"
fee_contract = "0x0000000000000000000000000000000000000000"
}
.to_string();

let genesis: Genesis = toml::from_str(&toml).unwrap_or_else(|err| panic!("{err:#}"));
let rpc_url = "https://ethereum-sepolia.publicnode.com";

// validate the fee_contract address
let result = genesis.validate_fee_contract(rpc_url.to_string()).await;

// check if the result from the validation is an error
if let Err(e) = result {
// assert that the error message contains "Fee contract's address is not a proxy"
assert!(e
.to_string()
.contains("Fee contract cannot use the zero address"));
} else {
panic!("Expected the fee contract to complain about the zero address but the validation succeeded");
}
}

#[test]
fn test_genesis_from_toml_units() {
let toml = toml! {
Expand Down

0 comments on commit f30ef38

Please sign in to comment.