Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions ethcore/wasm/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,14 @@ impl<'a> Runtime<'a> {
/// Intuition about the return value sense is to aswer the question 'are we allowed to continue?'
fn charge_gas(&mut self, amount: u64) -> bool {
let prev = self.gas_counter;
if prev + amount > self.gas_limit {
// exceeds gas
false
} else {
self.gas_counter = prev + amount;
true
match prev.checked_add(amount) {
// gas charge overflow protection
None => false,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will protect if someone charges gas manually and causes overflow

Some(val) if val > self.gas_limit => false,
Some(_) => {
self.gas_counter = prev + amount;
true
}
}
}

Expand Down Expand Up @@ -548,13 +550,13 @@ impl<'a> Runtime<'a> {

fn debug(&mut self, args: RuntimeArgs) -> Result<()>
{
let msg_ptr: u32 = args.nth_checked(0)?;
let msg_len: u32 = args.nth_checked(1)?;

let msg = String::from_utf8(self.memory.get(msg_ptr, msg_len as usize)?)
.map_err(|_| Error::BadUtf8)?;
trace!(target: "wasm", "Contract debug message: {}", {
let msg_ptr: u32 = args.nth_checked(0)?;
let msg_len: u32 = args.nth_checked(1)?;

trace!(target: "wasm", "Contract debug message: {}", msg);
String::from_utf8(self.memory.get(msg_ptr, msg_len as usize)?)
Copy link
Copy Markdown
Contributor Author

@NikVolf NikVolf Mar 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will evaluate argument only when traces are on

.map_err(|_| Error::BadUtf8)?
});

Ok(())
}
Expand Down