Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
748 changes: 375 additions & 373 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,11 @@ op-revm = { git = "https://github.com/bluealloy/revm.git", rev = "409c2b3" }
# solar-interface = { git = "https://github.com/paradigmxyz/solar.git", branch = "main" }
# solar-sema = { git = "https://github.com/paradigmxyz/solar.git", branch = "main" }
# solar-data-structures = { git = "https://github.com/paradigmxyz/solar.git", branch = "main" }

# Uncomment to test against local checkout of polkadot-sdk
# [patch."https://github.com/paritytech/polkadot-sdk"]
# polkadot-sdk = { path = "../polkadot-sdk/umbrella" }
# pallet-revive = { path = "../polkadot-sdk/substrate/frame/revive" }
# pallet-revive-eth-rpc = { path = "../polkadot-sdk/substrate/frame/revive/rpc" }
# revive-dev-runtime = { path = "../polkadot-sdk/substrate/frame/revive/dev-node/runtime" }
# sp-runtime-interface = { path = "../polkadot-sdk/substrate/primitives/runtime-interface" }
16 changes: 7 additions & 9 deletions crates/anvil-polkadot/src/substrate_node/service/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use polkadot_sdk::{
sc_consensus::BlockImportParams,
sc_consensus_aura::CompatibleDigestItem,
sc_consensus_manual_seal::{ConsensusDataProvider, Error},
sp_api::StorageProof,
sp_consensus_aura::ed25519::AuthoritySignature,
sp_consensus_babe::Slot,
sp_inherents::InherentData,
sp_runtime::{Digest, DigestItem, traits::Block as BlockT},
sp_runtime::{traits::Block as BlockT, Digest, DigestItem},
};
use std::marker::PhantomData;

Expand All @@ -16,23 +17,20 @@ use std::marker::PhantomData;
/// forking from an assethub chain, we expect an assethub runtime based on AURA,
/// which will pick the author based on the slot given through the digest, which will
/// also result in picking the AURA authority from index 0.
pub struct SameSlotConsensusDataProvider<B, P> {
_phantom: PhantomData<(B, P)>,
pub struct SameSlotConsensusDataProvider<B> {
_phantom: PhantomData<B>,
}

impl<B, P> SameSlotConsensusDataProvider<B, P> {
impl<B> SameSlotConsensusDataProvider<B> {
pub fn new() -> Self {
Self { _phantom: PhantomData }
}
}

impl<B, P> ConsensusDataProvider<B> for SameSlotConsensusDataProvider<B, P>
impl<B> ConsensusDataProvider<B> for SameSlotConsensusDataProvider<B>
where
B: BlockT,
P: Send + Sync,
{
type Proof = P;

fn create_digest(
&self,
_parent: &B::Header,
Expand All @@ -50,7 +48,7 @@ where
_parent: &B::Header,
_params: &mut BlockImportParams<B>,
_inherents: &InherentData,
_proof: Self::Proof,
_proof: StorageProof,
) -> Result<(), Error> {
Ok(())
}
Expand Down
40 changes: 28 additions & 12 deletions crates/revive-strategy/src/cheatcodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use tracing::warn;
use alloy_eips::eip7702::SignedAuthorization;
use polkadot_sdk::{
pallet_revive::{
AccountInfo, AddressMapper, BalanceOf, BytecodeType, Code, ContractInfo, DebugSettings,
ExecConfig, Pallet, evm::CallTrace,
self, AccountInfo, AddressMapper, BalanceOf, BytecodeType, Code,
ContractInfo, DebugSettings, ExecConfig, Pallet, ResourceMeter, evm::CallTrace,
},
polkadot_sdk_frame::prelude::OriginFor,
sp_core::{self, H160, H256},
Expand Down Expand Up @@ -738,7 +738,11 @@ fn select_revive(ctx: &mut PvmCheatcodeInspectorStrategyContext, data: Ecx<'_, '
Pallet::<Runtime>::account_id(),
code_bytes.clone(),
code_type,
u64::MAX.into(),
&mut ResourceMeter::new(pallet_revive::TransactionLimits::WeightAndDeposit {
weight_limit: Weight::from_parts(10_000_000_000_000, 100_000_000),
deposit_limit: BalanceOf::<Runtime>::MAX,
})
.unwrap(),
&ExecConfig::new_substrate_tx(),
);
match upload_result {
Expand Down Expand Up @@ -776,7 +780,11 @@ fn select_revive(ctx: &mut PvmCheatcodeInspectorStrategyContext, data: Ecx<'_, '
Pallet::<Runtime>::account_id(),
code_bytes.clone(),
BytecodeType::Evm,
u64::MAX.into(),
&mut ResourceMeter::new(pallet_revive::TransactionLimits::WeightAndDeposit {
weight_limit: Weight::from_parts(10_000_000_000_000, 100_000_000),
deposit_limit: BalanceOf::<Runtime>::MAX,
})
.unwrap(),
&ExecConfig::new_substrate_tx_without_bump(),
);
match upload_result {
Expand Down Expand Up @@ -1016,9 +1024,10 @@ impl foundry_cheatcodes::CheatcodeInspectorStrategyExt for PvmCheatcodeInspector
Pallet::<Runtime>::bare_instantiate(
origin,
evm_value,
Weight::MAX,
// TODO: fixing.
BalanceOf::<Runtime>::MAX,
pallet_revive::TransactionLimits::WeightAndDeposit {
weight_limit: Weight::from_parts(10_000_000_000_000, 100_000_000),
deposit_limit: BalanceOf::<Runtime>::MAX,
},
code,
data,
salt,
Expand All @@ -1038,7 +1047,8 @@ impl foundry_cheatcodes::CheatcodeInspectorStrategyExt for PvmCheatcodeInspector
// Only record gas cost if gas metering is not paused.
// When paused, the gas counter should remain frozen.
if !state.gas_metering.paused {
let _ = gas.record_cost(res.gas_required.ref_time());
let _ =
gas.record_cost(res.gas_consumed.min(u64::MAX.into()).try_into().unwrap());
}

let outcome = if result.result.did_revert() {
Expand Down Expand Up @@ -1165,9 +1175,14 @@ impl foundry_cheatcodes::CheatcodeInspectorStrategyExt for PvmCheatcodeInspector
origin,
target,
evm_value,
Weight::MAX,
// TODO: fixing.
BalanceOf::<Runtime>::MAX,
pallet_revive::TransactionLimits::WeightAndDeposit {
weight_limit: Weight::from_parts(10_000_000_000_000, 100_000_000),
deposit_limit: if call.is_static {
0
} else {
BalanceOf::<Runtime>::MAX / 2
},
},
call.input.bytes(ecx).to_vec(),
exec_config,
)
Expand All @@ -1184,7 +1199,8 @@ impl foundry_cheatcodes::CheatcodeInspectorStrategyExt for PvmCheatcodeInspector
// Only record gas cost if gas metering is not paused.
// When paused, the gas counter should remain frozen.
if !state.gas_metering.paused {
let _ = gas.record_cost(res.gas_required.ref_time());
let _ =
gas.record_cost(res.gas_consumed.min(u64::MAX.into()).try_into().unwrap());
}

let outcome = if result.did_revert() {
Expand Down
14 changes: 9 additions & 5 deletions crates/revive-strategy/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use alloy_primitives::{Address, B256, Bytes, FixedBytes, U256};
use alloy_primitives::{Address, Bytes, FixedBytes, B256, U256};
use foundry_cheatcodes::{Ecx, Error, Result};
use polkadot_sdk::{
pallet_revive::{
self, AccountInfo, AddressMapper, BalanceOf, BytecodeType, ContractInfo, ExecConfig,
Executable, Pallet,
Executable, Pallet, ResourceMeter,
},
sp_core::{self, H160, H256},
sp_externalities::Externalities,
sp_io::TestExternalities,
sp_weights::Weight,
};
use revive_env::{AccountId, BlockAuthor, ExtBuilder, Runtime, System, Timestamp};
use std::{
Expand Down Expand Up @@ -161,11 +162,14 @@ impl TestEnv {
origin_account,
code,
code_type,
BalanceOf::<Runtime>::MAX,
&mut ResourceMeter::new(pallet_revive::TransactionLimits::WeightAndDeposit {
weight_limit: Weight::from_parts(10_000_000_000_000, 100_000_000),
deposit_limit: BalanceOf::<Runtime>::MAX,
})
.unwrap(),
&ExecConfig::new_substrate_tx(),
)
.map_err(|_| <&str as Into<Error>>::into("Could not upload PVM code"))?
.0;
.map_err(|_| <&str as Into<Error>>::into("Could not upload PVM code"))?;

let mut contract_info = if let Some(contract_info) =
AccountInfo::<Runtime>::load_contract(&target_address)
Expand Down
7 changes: 3 additions & 4 deletions crates/revive-strategy/src/tracing/call_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use polkadot_sdk::{
pallet_revive,
pallet_revive::tracing::Tracing,
sp_core::{H160, U256},
sp_weights::Weight,
};

#[derive(Debug)]
Expand All @@ -24,11 +23,11 @@ impl Tracing for ExpectedCallTracer {
&mut self,
_from: H160,
to: H160,
_is_delegate_call: bool,
_delegate_call: Option<H160>,
_is_read_only: bool,
value: U256,
input: &[u8],
_gas: Weight,
_gas_limit: U256,
) {
if !self.is_create
&& let Some(expected_calls_for_target) = self.data.get_mut(&Address::from(to.0))
Expand All @@ -53,7 +52,7 @@ impl Tracing for ExpectedCallTracer {
}
}
}
fn exit_child_span(&mut self, _output: &pallet_revive::ExecReturnValue, _gas_left: Weight) {
fn exit_child_span(&mut self, _output: &pallet_revive::ExecReturnValue, _gas_used: U256) {
self.is_create = false;
}
fn instantiate_code(
Expand Down
13 changes: 6 additions & 7 deletions crates/revive-strategy/src/tracing/expect_create.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use alloy_primitives::{B256, Bytes, U256 as RU256, hex};
use alloy_primitives::{hex, Bytes, B256, U256 as RU256};
use foundry_cheatcodes::ExpectedCreate;
use foundry_compilers::resolc::dual_compiled_contracts::DualCompiledContracts;
use itertools::Itertools;
use polkadot_sdk::{
pallet_revive::{AccountInfo, Code, Pallet, tracing::Tracing},
pallet_revive::{tracing::Tracing, AccountInfo, Code, Pallet},
sp_core::{H160, U256},
sp_weights::Weight,
};
use revive_env::Runtime;
use revm::context::CreateScheme;
Expand Down Expand Up @@ -51,11 +50,11 @@ impl Tracing for CreateTracer {
&mut self,
_from: H160,
to: H160,
_is_delegate_call: bool,
_delegate_call: Option<H160>,
_is_read_only: bool,
_value: U256,
_input: &[u8],
_gas: Weight,
_gas_limit: U256,
) {
self.call_types.push(if let Some((_, salt)) = self.is_create.take() {
Type::Create { salt }
Expand All @@ -65,13 +64,13 @@ impl Tracing for CreateTracer {
if self.calls.is_empty() {
self.calls.push(_from);
}
self.calls.push(if _is_delegate_call { self.current_addr() } else { to });
self.calls.push(if _delegate_call.is_some() { self.current_addr() } else { to });
}

fn exit_child_span(
&mut self,
_output: &polkadot_sdk::pallet_revive::ExecReturnValue,
_gas_left: Weight,
_gas_used: U256,
) {
let addr = self.calls.pop().unwrap_or_default();

Expand Down
Loading
Loading