Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Unnecessary wasm validation error "Smart contract data segments must lie in first 64KiB" #5604

Open
liamcurry opened this issue Sep 11, 2018 · 6 comments
Labels
CONSENSUS Introduces a change that may modify consensus protocol rules on an existing blockchain. dev experience enhancement

Comments

@liamcurry
Copy link
Contributor

While working on Rust bindings I ran into this error: https://github.com/EOSIO/eos/blob/master/libraries/chain/wasm_eosio_validation.cpp#L28

Smart contract data segments must lie in first 64KiB

It seems to be caused by this line in the .wast file:

(data (i32.const 1048576) "Hello World")

If I change 1048576 to something much smaller like 555 then it works as expected.

According to @tbfleming on Telegram:

That check stopped a bug which no longer exists. Removing it would take revalidation, plus a hard fork.

@taokayan
Copy link
Contributor

taokayan commented Sep 11, 2018

The 64KB limit serves as a gatekeeper to ensure blockchain is healthy and secure. Changing this limit will result in hardfork or causing more delays on contract loading which introduces blackholes for hackers. Alternatively you can use multi_index table to store const string data, which takes about same amount of memory.

@spoonincode
Copy link
Contributor

The reason this occurs for rust is because rust’s compiler, be default, wants 1MB of “stack” to work with. You can reduce this, for example, by
rustc +nightly --target wasm32-unknown-unknown -O hello.rs -Clink-args='-z stack-size=8192'
The above example may or may not work I'm not sure how much stack rust needs to float.

@liamcurry
Copy link
Contributor Author

Thanks @spoonincode! Reducing the stack size worked. FYI for anyone else tinkering with Rust, I ended up adding this to my .cargo/config file:

[target.wasm32-unknown-unknown]
rustflags = [
  "-C", "link-args=-z stack-size=48000"
]

@taokayan taokayan removed the Support label Nov 2, 2018
@arhag arhag added CONSENSUS Introduces a change that may modify consensus protocol rules on an existing blockchain. and removed HARDFORK labels Mar 22, 2019
@seeseesee
Copy link

seeseesee commented Aug 29, 2019

Hi @taokayan, I build a contract with static libsecp256k1, with DATA larger than 64KB. Is there a better way to do? Since get data from table is quite slow when DATA is big.

@cmadh
Copy link

cmadh commented Dec 16, 2020

After the update to EOSIO.CDT v1.8.0-RC1 and EOSIO v2.1.0-RC1 I'm getting this error, too, with a pretty large contract. I previously used EOSIO.CDT v.1.7.0 and EOSIO v2.0.7 and have not had any problems. Is there a way solve this? (like setting -stack-size or so?)

@cmadh
Copy link

cmadh commented Dec 19, 2020

After the update to EOSIO.CDT v1.8.0-RC1 and EOSIO v2.1.0-RC1 I'm getting this error, too, with a pretty large contract. I previously used EOSIO.CDT v.1.7.0 and EOSIO v2.0.7 and have not had any problems. Is there a way solve this? (like setting -stack-size or so?)

Tried setting -stack-size to something small and -fno-stack-first, both without success.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CONSENSUS Introduces a change that may modify consensus protocol rules on an existing blockchain. dev experience enhancement
Projects
None yet
Development

No branches or pull requests

8 participants