Skip to content
This repository was archived by the owner on Jan 17, 2022. It is now read-only.
This repository was archived by the owner on Jan 17, 2022. It is now read-only.

Contract creation fails if "deploy" modifies memory #130

@geigerzaehler

Description

@geigerzaehler

The contract created by a pwasm module might be invalid if the deploy code modifies memory.

For example consider the following Wasm module.

(module
  (type (;0;) (func))
  (func $call (type 0))
  (func $deploy (type 0)
    i32.const 0
    i32.const -1
    i32.store
    )
  (memory (;0;) 1 16)
  (export "memory" (memory 0))
  (export "call" (func $call))
  (export "deploy" (func $deploy)))

Here the $deploy function modifies the memory at location 0..3 by setting all bytes to 0xff.

With wasm-build this code is transformed to

(module
  (type (;0;) (func))
  (type (;1;) (func (param i32 i32)))
  (import "env" "memory" (memory (;0;) 1 16))
  (import "env" "ret" (func (;0;) (type 1)))
  (func (;1;) (type 0)
    i32.const 0
    i32.const -1
    i32.store)
  (func (;2;) (type 0)
    call 1
    i32.const 0
    i32.const 52
    call 0)
  (export "call" (func 2))
  (data (;0;) (i32.const 0) "\00asm\01\00\00\00\01\04\01`\00\00\02\10\01\03env\06memory\02\01\01\10\03\02\01\00\07\08\01\04call\00\00\0a\04\01\02\00\0b"))

If this contract is deployed the same modification to the memory happens before ret is called (call 0). However the memory at 0..3 is part of the contract code that is returned and was initialized correctly with the data section to \00asm. After func 2 is called Parity Ethereum will read the memory at 0..51 and store this as the contract data. With the memory modification this now starts with \ff\ff\ff\ff and is not valid Wasm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions