Skip to content

Commit 31ef20b

Browse files
authored
Merge pull request #4788 from namada-net/mergify/bp/maint-201.0/pr-4786
wasm init always alloc for initial data (backport #4786)
2 parents 29913d0 + 1680694 commit 31ef20b

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Always allocate for the initial data to allow to execute larger WASMs
2+
([\#4786](https://github.com/anoma/namada/pull/4786))

crates/vm/src/host_env.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ where
890890
.map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?;
891891
consume_tx_gas::<MEM, D, H, CA>(env, gas)?;
892892

893-
tracing::debug!("tx_update {}, {:?}", key, value);
893+
tracing::debug!("tx_update {}", key);
894894

895895
let key = Key::parse(key)?;
896896
if key.is_validity_predicate().is_some() {
@@ -930,7 +930,7 @@ where
930930
.map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?;
931931
consume_tx_gas::<MEM, D, H, CA>(env, gas)?;
932932

933-
tracing::debug!("tx_write_temp {}, {:?}", key, value);
933+
tracing::debug!("tx_write_temp {}", key);
934934

935935
let key = Key::parse(key)?;
936936

@@ -1119,10 +1119,9 @@ where
11191119
let state = env.state();
11201120
let value = vp_host_fns::read_pre(gas_meter, &state, &key)?;
11211121
tracing::debug!(
1122-
"vp_read_pre addr {}, key {}, value {:?}",
1122+
"vp_read_pre addr {}, key {}",
11231123
unsafe { env.ctx.address.get() },
11241124
key,
1125-
value,
11261125
);
11271126
Ok(match value {
11281127
Some(value) => {

crates/vm/src/wasm/run.rs

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -977,19 +977,12 @@ fn inject_alloc(module: elements::Module) -> Result<elements::Module> {
977977

978978
// Alloc fn in WAT:
979979
//
980-
// (func (;0;) (type 0) (param i32)
981-
// (local i32)
980+
// (func (;0;) (type 0) (param i32) (result i32)
982981
// block ;; label = @1
983982
// local.get 0
984-
// memory.size
985-
// i32.const 16
986-
// i32.shl
987-
// i32.gt_u
988-
// if (result i32) ;; label = @2
989-
// local.get 0
990-
// i32.const -65536
991-
// i32.gt_u
992-
// br_if 1 (;@1;)
983+
// i32.const -65536
984+
// i32.le_u
985+
// if ;; label = @2
993986
// local.get 0
994987
// i32.const 65535
995988
// i32.add
@@ -998,17 +991,14 @@ fn inject_alloc(module: elements::Module) -> Result<elements::Module> {
998991
// memory.grow
999992
// local.tee 0
1000993
// i32.const -1
1001-
// i32.eq
994+
// i32.ne
1002995
// br_if 1 (;@1;)
1003-
// local.get 0
1004-
// i32.const 16
1005-
// i32.shl
1006-
// else
1007-
// i32.const 0
1008996
// end
1009-
// return
997+
// unreachable
1010998
// end
1011-
// unreachable)
999+
// local.get 0
1000+
// i32.const 16
1001+
// i32.shl)
10121002

10131003
const MEMORY_IX: u8 = 0;
10141004
const WASM_PAGE_SIZE_LOG2: i32 = 16;
@@ -1017,16 +1007,10 @@ fn inject_alloc(module: elements::Module) -> Result<elements::Module> {
10171007
use Instruction::*;
10181008
vec![
10191009
Block(BlockType::NoResult),
1020-
GetLocal(0),
1021-
CurrentMemory(MEMORY_IX),
1022-
I32Const(WASM_PAGE_SIZE_LOG2),
1023-
I32Shl,
1024-
I32GtU,
1025-
If(BlockType::Value(ValueType::I32)),
1026-
GetLocal(0),
1010+
GetLocal(1),
10271011
I32Const(-WASM_PAGE_SIZE),
1028-
I32GtU,
1029-
BrIf(1),
1012+
I32LeU,
1013+
If(BlockType::NoResult),
10301014
GetLocal(0),
10311015
I32Const(WASM_PAGE_SIZE - 1),
10321016
I32Add,
@@ -1035,17 +1019,14 @@ fn inject_alloc(module: elements::Module) -> Result<elements::Module> {
10351019
GrowMemory(MEMORY_IX),
10361020
TeeLocal(0),
10371021
I32Const(-1),
1038-
I32Eq,
1022+
I32Ne,
10391023
BrIf(1),
1024+
End,
1025+
Unreachable,
1026+
End,
10401027
GetLocal(0),
10411028
I32Const(WASM_PAGE_SIZE_LOG2),
10421029
I32Shl,
1043-
Else,
1044-
I32Const(0),
1045-
End,
1046-
Return,
1047-
End,
1048-
Unreachable,
10491030
End,
10501031
]
10511032
};

0 commit comments

Comments
 (0)