-
Notifications
You must be signed in to change notification settings - Fork 5
dynamic gas cost instructions #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cb87418 to
de82267
Compare
d921fdb to
4fdc4b0
Compare
| // is negative, and if the spec is followed exactly, those instructions may take | ||
| // very long to trap with a negative argument. |
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.
What if we just treat them as unsigned? I.e., just charge a lot of gas?
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.
(if it's an i32, that is).
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.
That can get all kinds of messy with overflows, but I can dabble with that idea for a bit
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.
So apparently I64ExtendI32U already extends with all zero bits (so -1 becomes 0x00000000_ffffffff), so we can just do that and be fine.
You can see that with this demo: https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Control_flow/call
Put this as js:
var url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(
fetch(url),
{
env: {
greet: function(v) {
console.log(v);
}
}
}
);And this as wat
(module
(import "env" "greet" (func $greet (param i64)))
(func
i32.const -1
i64.extend_i32_u
call $greet
)
(start 1)
)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.
Yeah, there's a separate instruction for sign extending (I64ExtendI32I).
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.
Actually, are you sure this is signed? Wasm usually doesn't distinguish between the two.
| InstructionCost::Linear(base, cost_per) => { | ||
| // Enforce that cost per unit fits in 31 bits | ||
| if cost_per.get() >= 0x8000_0000 { | ||
| return Err(anyhow!("cost per unit excedes the 0x80000000 limit")); |
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.
Ah, I guess 32 bits plus 31 bits because our gas is technically signed (although I'd like to remove that...). But yeah, this is reasonable.
7a72fa3 to
49670b5
Compare
|
(rebased on master) |
On top of #10
Rewrite of #4
This PR makes it possible to define much more advanced gas cost rules