-
Notifications
You must be signed in to change notification settings - Fork 3
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
Move overflow checks to int lib #17
Comments
I understand what you are saying, but there are conflicting goals here:
To be honest, just having the |
Got it, thanks @DavePearce I think having a math lib for common things like decimal precision to model and emulate protocols in dafny is a good pick for me now, as I am using Dafny to model and check economics, governance, config range inputs and calculations. So far I did this code below, please, let me know if you find the direction is good. The goal is to have a reusable DSMath in dafny. include "../../lib/evm-dafny/src/dafny/util/int.dfy"
include "../../lib/evm-dafny/libs/DafnyCrypto/src/dafny/util/math.dfy"
module DSMath {
import opened Int
import opened MathUtils
const WAD : u256 := MathUtils.Pow(10,18) as u256
const RAY : u128 := MathUtils.Pow(10,27) as u128
function Mul(x: u256, y: u256) : (z: u256)
requires MulOverflowCheck(x as int, y as int) {
x * y
}
/**
* Add with protected overflow
*/
function Add(x: u256, y: u256) : (z: u256)
requires AddOverflowCheck(x as int, y as int) {
x + y
}
/**
* Because we use modulus, to avoid div by zero we have to return
* true if x or y are zero, and overflow on x or y itself
* is already protected by the type u256
*/
predicate AddOverflowCheck(x: int, y: int) {
(x == 0) || (y == 0) || ((x + y) != 0 ==> ((x + y) % TWO_256) > x)
}
predicate MulOverflowCheck(x: int, y: int){
(y != 0 && x != 0) ==> ((x * y) % TWO_256) / y == x
}
} |
Yeah, definitely looks interesting! |
Thanks for the feedback, so I think we can close this issue. |
Let me suggest to make the overflow checks as
WrappedEther.dfy/src/WrappedEtherBinary_deposit.dfy
Line 114 in dc8a523
or
So we can have the EVM reverting as expected [as from solc 0.8.1] and avoid adding evm responsability into the contract transpilation. Makes sense ?
The text was updated successfully, but these errors were encountered: