diff --git a/std/dispatch.solc b/std/dispatch.solc index bd83901c5..473f4fedc 100644 --- a/std/dispatch.solc +++ b/std/dispatch.solc @@ -82,11 +82,8 @@ forall name payability args rets fn => instance Method(name,payability,args,rets,fn):Selector { function compute(prx : Proxy(Method(name,payability,args,rets,fn))) -> bytes4 { // let hash : word = keccakLit(sigStr(prx)); - let hash = keccakLit(sigStr(Proxy:Proxy(name)) + "(" + sigStr(Proxy:Proxy(args)) + ")"); - let res : word; - assembly { res := shr(224, hash) } - - return bytes4(res); + let hash = keccakLit(sigStr(Proxy:Proxy(name)) + "(" + sigStr(Proxy:Proxy(args)) + ")"); + return bytes4(bshrWord(224, hash)); } } diff --git a/std/std.solc b/std/std.solc index b97115e88..453bafb88 100644 --- a/std/std.solc +++ b/std/std.solc @@ -49,6 +49,12 @@ export { bytes, bytes4(*), bytes32(*), + bandWord, + borWord, + bxorWord, + bnotWord, + bshlWord, + bshrWord, calldata(*), concatLit, eqWord, @@ -411,6 +417,60 @@ function subWord(l: word, r: word) -> word { return rw; } +// Bitwise AND +function bandWord(x: word, y: word) -> word { + let res: word; + assembly { + res := and(x, y) + } + return res; +} + +// Bitwise OR +function borWord(x: word) -> word { + let res: word; + assembly { + res := or(x) + } + return res; +} + +// Bitwise XOR +function bxorWord(x: word) -> word { + let res: word; + assembly { + res := xor(x) + } + return res; +} + +// Bitwise NOT +function bnotWord(x: word) -> word { + let res: word; + assembly { + res := not(x) + } + return res; +} + +// Bitwise SHL +function bshlWord(x: word, y: word) -> word { + let res: word; + assembly { + res := shl(x, y) + } + return res; +} + +// Bitwise SHR +function bshrWord(x: word, y: word) -> word { + let res: word; + assembly { + res := shr(x, y) + } + return res; +} + instance word:Eq { function eq(x:word, y:word) -> bool { return eqWord(x, y); @@ -1123,9 +1183,7 @@ instance bool:ABIEncode { } function round_up_to_mul_of_32(value:word) -> word { - let result : word; - assembly { result := and(add(value, 31), not(31)) } - return result; + return bandWord(value + 31, bnotWord(31)); } function encodeIntoFromBytesLike(srcPtr:word, basePtr:word, offset:word, tail:word) -> word {