Skip to content

Commit

Permalink
contracts: Remove no longer enforced limits from the Schedule (pari…
Browse files Browse the repository at this point in the history
…tytech#3184)

When switching from the instrumented gas metering to the wasmi gas
metering we also removed all imposed limits regarding Wasm module
internals. All those things do not interact with the host and have to be
handled by wasmi. For example, Wasmi charges additional gas for
parameters to each function because as they incur some overhead.

Back then we took the opportunity to remove the dependency on the
deprecated `parity-wasm` which was used to enforce those limits.

This PR merely removes them from the `Schedule` they aren't enforced for
a while.
  • Loading branch information
athei authored Feb 8, 2024
1 parent 007158c commit 89c885b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 44 deletions.
39 changes: 0 additions & 39 deletions substrate/frame/contracts/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ use serde::{Deserialize, Serialize};
/// fn create_schedule<T: Config>() -> Schedule<T> {
/// Schedule {
/// limits: Limits {
/// globals: 3,
/// parameters: 3,
/// memory_pages: 16,
/// table_size: 3,
/// br_table_size: 3,
/// .. Default::default()
/// },
/// instruction_weights: InstructionWeights {
Expand Down Expand Up @@ -77,38 +73,9 @@ pub struct Limits {
/// The maximum number of topics supported by an event.
pub event_topics: u32,

/// Maximum number of globals a module is allowed to declare.
///
/// Globals are not limited through the linear memory limit `memory_pages`.
pub globals: u32,

/// Maximum number of locals a function can have.
///
/// As wasm engine initializes each of the local, we need to limit their number to confine
/// execution costs.
pub locals: u32,

/// Maximum numbers of parameters a function can have.
///
/// Those need to be limited to prevent a potentially exploitable interaction with
/// the stack height instrumentation: The costs of executing the stack height
/// instrumentation for an indirectly called function scales linearly with the amount
/// of parameters of this function. Because the stack height instrumentation itself is
/// is not weight metered its costs must be static (via this limit) and included in
/// the costs of the instructions that cause them (call, call_indirect).
pub parameters: u32,

/// Maximum number of memory pages allowed for a contract.
pub memory_pages: u32,

/// Maximum number of elements allowed in a table.
///
/// Currently, the only type of element that is allowed in a table is funcref.
pub table_size: u32,

/// Maximum number of elements that can appear as immediate value to the br_table instruction.
pub br_table_size: u32,

/// The maximum length of a subject in bytes used for PRNG generation.
pub subject_len: u32,

Expand Down Expand Up @@ -370,13 +337,7 @@ impl Default for Limits {
fn default() -> Self {
Self {
event_topics: 4,
globals: 256,
locals: 1024,
parameters: 128,
memory_pages: 16,
// 4k function pointers (This is in count not bytes).
table_size: 4096,
br_table_size: 256,
subject_len: 32,
payload_len: 16 * 1024,
runtime_memory: 1024 * 1024 * 128,
Expand Down
5 changes: 0 additions & 5 deletions substrate/frame/contracts/src/wasm/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,7 @@ mod tests {
let wasm = wat::parse_str($wat).unwrap().try_into().unwrap();
let schedule = Schedule {
limits: Limits {
globals: 3,
locals: 3,
parameters: 3,
memory_pages: 16,
table_size: 3,
br_table_size: 3,
.. Default::default()
},
.. Default::default()
Expand Down

0 comments on commit 89c885b

Please sign in to comment.