Skip to content

Commit 889def9

Browse files
0xKitsunedecofe
andauthored
fix(evm): disable dex on zones (#367)
* feat: disable dex on zones * style: fix import ordering in precompiles test Co-Authored-By: 0xKitsune <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-019d6b05-2eed-7515-8ff0-eb19e482ce36 --------- Co-authored-by: Derek Cofausper <[email protected]>
1 parent 2599135 commit 889def9

3 files changed

Lines changed: 55 additions & 25 deletions

File tree

crates/tempo-zone/src/evm.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44
//! [`TempoStateReader`](crate::l1_state::TempoStateReader) precompile at
55
//! [`TEMPO_STATE_READER_ADDRESS`](crate::abi::TEMPO_STATE_READER_ADDRESS).
66
7-
use std::sync::Arc;
8-
7+
use crate::{
8+
abi::{TEMPO_STATE_READER_ADDRESS, ZONE_TX_CONTEXT_ADDRESS},
9+
executor::ZoneBlockExecutor,
10+
l1_state::{L1StateProvider, PolicyProvider, SharedL1StateCache, TempoStateReader},
11+
precompiles::{
12+
AES_GCM_DECRYPT_ADDRESS, AesGcmDecrypt, CHAUM_PEDERSEN_VERIFY_ADDRESS, ChaumPedersenVerify,
13+
ZONE_TIP20_FACTORY_ADDRESS, ZONE_TIP403_PROXY_ADDRESS, ZoneTip20Token,
14+
ZoneTip403ProxyRegistry, ZoneTokenFactory,
15+
},
16+
tx_context::ZoneTxContext,
17+
};
918
use alloy_evm::{
1019
Database, Evm, EvmEnv, EvmFactory,
1120
block::{BlockExecutorFactory, BlockExecutorFor},
@@ -19,6 +28,7 @@ use reth_evm::{
1928
execute::{BlockAssembler, BlockAssemblerInput},
2029
};
2130
use reth_primitives_traits::{SealedBlock, SealedHeader};
31+
use std::sync::Arc;
2232
use tempo_alloy::TempoNetwork;
2333
use tempo_chainspec::TempoChainSpec;
2434
use tempo_evm::{
@@ -27,20 +37,14 @@ use tempo_evm::{
2737
evm::{TempoEvm, TempoEvmFactory},
2838
};
2939
use tempo_payload_types::TempoExecutionData;
30-
use tempo_primitives::{Block, TempoHeader, TempoPrimitives, TempoReceipt, TempoTxEnvelope};
31-
32-
use crate::executor::ZoneBlockExecutor;
33-
34-
use crate::{
35-
abi::{TEMPO_STATE_READER_ADDRESS, ZONE_TX_CONTEXT_ADDRESS},
36-
l1_state::{L1StateProvider, PolicyProvider, SharedL1StateCache, TempoStateReader},
37-
precompiles::{
38-
AES_GCM_DECRYPT_ADDRESS, AesGcmDecrypt, CHAUM_PEDERSEN_VERIFY_ADDRESS, ChaumPedersenVerify,
39-
ZONE_TIP20_FACTORY_ADDRESS, ZONE_TIP403_PROXY_ADDRESS, ZoneTip20Token,
40-
ZoneTip403ProxyRegistry, ZoneTokenFactory,
41-
},
42-
tx_context::ZoneTxContext,
40+
use tempo_precompiles::{
41+
ACCOUNT_KEYCHAIN_ADDRESS, NONCE_PRECOMPILE_ADDRESS, STABLECOIN_DEX_ADDRESS,
42+
TIP_FEE_MANAGER_ADDRESS, VALIDATOR_CONFIG_ADDRESS, VALIDATOR_CONFIG_V2_ADDRESS,
43+
account_keychain::AccountKeychain, nonce::NonceManager, tip_fee_manager::TipFeeManager,
44+
tip20::is_tip20_prefix, validator_config::ValidatorConfig,
45+
validator_config_v2::ValidatorConfigV2,
4346
};
47+
use tempo_primitives::{Block, TempoHeader, TempoPrimitives, TempoReceipt, TempoTxEnvelope};
4448

4549
type TempoCtx<DB> = <TempoEvmFactory as EvmFactory>::Context<DB>;
4650

@@ -109,15 +113,6 @@ impl ZoneEvmFactory {
109113
// static map via `apply_precompile` and take priority over this.
110114
let zone_cfg = cfg.clone();
111115
precompiles.set_precompile_lookup(move |address: &alloy_primitives::Address| {
112-
use tempo_precompiles::{
113-
ACCOUNT_KEYCHAIN_ADDRESS, NONCE_PRECOMPILE_ADDRESS, STABLECOIN_DEX_ADDRESS,
114-
TIP_FEE_MANAGER_ADDRESS, VALIDATOR_CONFIG_ADDRESS, VALIDATOR_CONFIG_V2_ADDRESS,
115-
account_keychain::AccountKeychain, nonce::NonceManager,
116-
stablecoin_dex::StablecoinDEX, tip_fee_manager::TipFeeManager,
117-
tip20::is_tip20_prefix, validator_config::ValidatorConfig,
118-
validator_config_v2::ValidatorConfigV2,
119-
};
120-
121116
if is_tip20_prefix(*address) {
122117
Some(ZoneTip20Token::create(
123118
*address,
@@ -128,7 +123,9 @@ impl ZoneEvmFactory {
128123
} else if *address == TIP_FEE_MANAGER_ADDRESS {
129124
Some(TipFeeManager::create_precompile(&zone_cfg))
130125
} else if *address == STABLECOIN_DEX_ADDRESS {
131-
Some(StablecoinDEX::create_precompile(&zone_cfg))
126+
// StablecoinDEX is disabled on zones, calls to this address
127+
// fall through to `None` and revert as an empty account.
128+
None
132129
} else if *address == NONCE_PRECOMPILE_ADDRESS {
133130
Some(NonceManager::create_precompile(&zone_cfg))
134131
} else if *address == VALIDATOR_CONFIG_ADDRESS {

crates/tempo-zone/tests/it/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod deposit;
55
mod e2e;
66
mod enable_token;
77
mod l1_e2e;
8+
mod precompiles;
89
mod private_rpc;
910
mod private_rpc_e2e;
1011
mod restart_e2e;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//! Tests for zone-specific precompile availability.
2+
3+
use tempo_precompiles::PATH_USD_ADDRESS;
4+
5+
use crate::utils::{
6+
DEFAULT_TIMEOUT, STABLECOIN_DEX_ADDRESS, TestStablecoinDEX, start_local_zone_with_fixture,
7+
};
8+
9+
/// The StablecoinDEX precompile should be disabled on zones — any call to
10+
/// it must revert.
11+
#[tokio::test(flavor = "multi_thread")]
12+
async fn test_dex_disabled_on_zone() -> eyre::Result<()> {
13+
reth_tracing::init_test_tracing();
14+
15+
let (zone, mut fixture) = start_local_zone_with_fixture(10).await?;
16+
17+
// Inject an empty block so the zone is alive and processing.
18+
fixture.inject_empty_block(zone.deposit_queue());
19+
zone.wait_for_tempo_block_number(1, DEFAULT_TIMEOUT).await?;
20+
21+
// Attempt to call createPair on the DEX — should revert because the
22+
// precompile is not registered on the zone.
23+
let dex = TestStablecoinDEX::new(STABLECOIN_DEX_ADDRESS, zone.provider());
24+
let result = dex.createPair(PATH_USD_ADDRESS).call().await;
25+
26+
assert!(
27+
result.is_err(),
28+
"StablecoinDEX should be disabled on zones — createPair must revert"
29+
);
30+
31+
Ok(())
32+
}

0 commit comments

Comments
 (0)