-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Conversation
ethcore/vm/src/schedule.rs
Outdated
/// Wasm cost table | ||
pub struct WasmCosts { | ||
/// Arena allocator cost, per byte | ||
pub alloc: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why usize
? usize
should only be used for representing memory area sizes. Hence the name. u64
should prevent any unexpected issues on 32-bit platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And why all ethereum Schedule
members are usize?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea, but I think it needs to be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh this is because of that, gas counter for evm uses different size across platforms
i don't use it, so i might stick to u64
ethcore/wasm/src/runtime.rs
Outdated
@@ -102,6 +103,13 @@ pub struct RuntimeContext { | |||
pub value: U256, | |||
} | |||
|
|||
macro_rules! charge { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not a simple function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of double borrowing of self
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh, ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like a fn charge<F>(&mut self, f: F) where F: FnOnce(&Schedule) -> u64
would work in all cases here
ethcore/wasm/src/runtime.rs
Outdated
@@ -369,13 +412,17 @@ impl<'a, 'b> Runtime<'a, 'b> { | |||
-> Result<Option<interpreter::RuntimeValue>, InterpreterError> | |||
{ | |||
let amount = context.value_stack.pop_as::<i32>()? as u32; | |||
|
|||
charge!(self, self.ext.schedule().wasm.alloc * amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depending on the alloc cost, this seems like it could easily overflow a u32 when allocating just a few MB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's super easy operation with arena allocator, so it should not be priced more than memory opcodes
and memory limit for wasm is just 16mb
i will change to u64 anyway though to be uniform
ethcore/wasm/src/runtime.rs
Outdated
@@ -211,6 +249,9 @@ impl<'a, 'b> Runtime<'a, 'b> { | |||
|
|||
let code = self.memory.get(code_ptr, code_len as usize)?; | |||
|
|||
charge!(self, self.ext.schedule().create_gas as u32); | |||
charge!(self, (self.ext.schedule().create_data_gas * code.len()) as u32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, using u32 for gas here seems a little flaky. In the EVM code we use u64 in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not fully familiar with the context of this pr, but it looks good to me. Just one minor (irrelevant) grumble.
); | ||
|
||
let data_section_length = contract_module.data_section() | ||
.map(|section| section.entries().iter().fold(0, |sum, entry| sum + entry.value().len())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using
map(|entry| entry.value().len()).sum()
would be more idiomatic
this actually closes the WASM MVP #6056, since proper gas metering is all that left there
WASM itself can be parameterized by much broader range of opcode types, but seems like they all have roughly the same cpu costs