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

pallet-contracts Configuration when ED is zero #5957

Open
Ali-Usama opened this issue Oct 7, 2024 · 0 comments
Open

pallet-contracts Configuration when ED is zero #5957

Ali-Usama opened this issue Oct 7, 2024 · 0 comments

Comments

@Ali-Usama
Copy link
Contributor

I’m working on implementing a Substrate-based chain using zero Existential Deposit, similar to the Polkadot-dropIt configuration. However, despite having configured zero gas fees and deposits, I am encountering a DispatchError: NoProviders error when trying to instantiate contracts. The error occurs during contract instantiation, and I suspect it’s related to the account existence requirements (providers) not being properly handled in the configuration.

cargo contract instantiate --constructor new --args "false" --suri //Alice --salt $(date +%s) -x
Result DispatchError: NoProviders
          Gas Consumed Weight { ref_time: 0, proof_size: 0 }
          Gas Required Weight { ref_time: 0, proof_size: 0 }
 Storage Total Deposit StorageDeposit::Charge(0)
ERROR: DispatchError: NoProviders

Description of the Problem:

I have followed the zero Existential Deposit configuration used in the Polkadot DropIt repository for both balances and contracts, where all relevant fees and deposits are set to zero. While the balance pallet seems configured correctly, I encounter the NoProviders error when instantiating contracts.

  • This is my configuration for pallet-balances with the insecure-zero-ed feature enabled:
pub const EXISTENTIAL_DEPOSIT: Balance = 0;
pub const ZERO_DEPOSIT: Balance = 0;

parameter_types! {
    pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
}

impl pallet_balances::Config for Runtime {
    type RuntimeEvent = RuntimeEvent;
    type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
    type Balance = Balance;
    type DustRemoval = ();
    type ExistentialDeposit = ExistentialDeposit;
    type AccountStore = System;
    type ReserveIdentifier = [u8; 8];
    type RuntimeHoldReason = RuntimeHoldReason;
    type FreezeIdentifier = ();
    type MaxLocks = ConstU32<50>;
    type MaxReserves = ConstU32<50>;
    type MaxFreezes = ConstU32<0>;
    type RuntimeFreezeReason = RuntimeFreezeReason;
}
  • Configuration for pallet-contracts:
parameter_types! {
    pub const DepositPerItem: Balance = ZERO_DEPOSIT;
    pub const DepositPerByte: Balance = ZERO_DEPOSIT;
    pub const DefaultDepositLimit: Balance = ZERO_DEPOSIT;
    pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
    pub CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30);
}

impl pallet_contracts::Config for Runtime {
    type Time = Timestamp;
    type Randomness = RandomnessCollectiveFlip;
    type Currency = Balances;
    type RuntimeEvent = RuntimeEvent;
    type RuntimeCall = RuntimeCall;
    type RuntimeHoldReason = RuntimeHoldReason;
    type CallFilter = frame_support::traits::Nothing;
    type WeightPrice = pallet_transaction_payment::Pallet<Self>;
    type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
    type ChainExtension = ();
    type Schedule = Schedule;
    type CallStack = [pallet_contracts::Frame<Self>; 5];
    type DepositPerByte = DepositPerByte;
    type DefaultDepositLimit = DefaultDepositLimit;
    type DepositPerItem = DepositPerItem;
    type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
    type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
    type MaxCodeLen = ConstU32<{ 123 * 1024 }>;
    type MaxStorageKeyLen = ConstU32<128>;
    type MaxDelegateDependencies = ConstU32<32>;
    type UnsafeUnstableInterface = ConstBool<false>;
    type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>;
    type UploadOrigin = frame_system::EnsureSigned<Self::AccountId>;
    type InstantiateOrigin = frame_system::EnsureSigned<Self::AccountId>;
}
  • Configuration for pallet-transaction-payment:
parameter_types! {
    pub FeeMultiplier: Multiplier = Multiplier::one();
    pub TransactionByteFee: Balance = ZERO_DEPOSIT;
}

pub struct ConstantFee<T>(sp_std::marker::PhantomData<T>);

impl<T> frame_support::weights::WeightToFee for ConstantFee<T>
where
    T: sp_arithmetic::traits::BaseArithmetic + From<u32> + Copy + sp_arithmetic::traits::Unsigned
{
    type Balance = T;

    fn weight_to_fee(_weight: &Weight) -> Self::Balance {
        0u32.into()
    }
}

impl pallet_transaction_payment::Config for Runtime {
    type RuntimeEvent = RuntimeEvent;
    type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
    type WeightToFee = ConstantFee<Balance>;
    type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
    type FeeMultiplierUpdate = ConstFeeMultiplier<FeeMultiplier>;
    type OperationalFeeMultiplier = ConstU8<5>;
}

I've ensured that the ExistentialDeposit and all storage-related deposits are explicitly set to zero, and also verified that the account used to instantiate the contract has sufficient balance to cover the operation (though no deposit or gas fees should apply).

Problem:

The error NoProviders still occurs during contract instantiation, indicating that the system is likely expecting the presence of an account provider despite all balances and deposits being set to zero. I suspect this is related to how the chain handles accounts with zero balance or the system’s requirement for providers.

Questions:

  1. Is there any additional configuration I need to modify to handle zero-provider accounts in the same way that zero Existential Deposit is handled?
  2. How can I prevent the system from requiring providers for accounts that interact with contracts when gas fees and deposits are explicitly zero?

Any advice or insight into what could be missing or conflicting in the configuration would be greatly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant