diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-06-14 06:23:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-14 06:23:02 +0800 |
commit | c99c1c76f7ce2963b1401b53676ca3bbb0eadbea (patch) | |
tree | e808847b8c1b31a4cb268fc92c85651015ad45da | |
parent | d3f4c97c533b2f64dda9fe7bdf5848f6c8bbb300 (diff) | |
parent | 3299c479b6d8f90a13c6464acc0cb2e7db012ab0 (diff) | |
download | dexon-solidity-c99c1c76f7ce2963b1401b53676ca3bbb0eadbea.tar.gz dexon-solidity-c99c1c76f7ce2963b1401b53676ca3bbb0eadbea.tar.zst dexon-solidity-c99c1c76f7ce2963b1401b53676ca3bbb0eadbea.zip |
Merge pull request #2354 from benjaminion/patch-2
LLL: fix handling of "sha3" expression
-rw-r--r-- | liblll/CompilerState.cpp | 2 | ||||
-rw-r--r-- | test/liblll/EndToEndTest.cpp | 37 |
2 files changed, 38 insertions, 1 deletions
diff --git a/liblll/CompilerState.cpp b/liblll/CompilerState.cpp index 006929e4..b990ecac 100644 --- a/liblll/CompilerState.cpp +++ b/liblll/CompilerState.cpp @@ -56,10 +56,10 @@ void CompilerState::populateStandard() "(def 'msg (to data) { [0]:data (msg allgas to 0 0 32) })" "(def 'create (value code) { [0]:(msize) (create value @0 (lll code @0)) })" "(def 'create (code) { [0]:(msize) (create 0 @0 (lll code @0)) })" + "(def 'sha3 (loc len) (keccak256 loc len))" "(def 'sha3 (val) { [0]:val (sha3 0 32) })" "(def 'sha3pair (a b) { [0]:a [32]:b (sha3 0 64) })" "(def 'sha3trip (a b c) { [0]:a [32]:b [64]:c (sha3 0 96) })" - "(def 'keccak256 (loc len) (sha3 loc len))" "(def 'return (val) { [0]:val (return 0 32) })" "(def 'returnlll (code) (return 0 (lll code 0)) )" "(def 'makeperm (name pos) { (def name (sload pos)) (def name (v) (sstore pos v)) } )" diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index c8e7adf1..7f1924c2 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -291,6 +291,43 @@ BOOST_AUTO_TEST_CASE(zeroarg_macro) BOOST_CHECK(callFallback() == encodeArgs(u256(0x1234))); } +BOOST_AUTO_TEST_CASE(keccak256_32bytes) +{ + char const* sourceCode = R"( + (returnlll + (seq + (mstore 0x00 0x01) + (return (keccak256 0x00 0x20)))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs( + fromHex("b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6"))); +} + +BOOST_AUTO_TEST_CASE(sha3_two_args) +{ + char const* sourceCode = R"( + (returnlll + (seq + (mstore 0x00 0x01) + (return (sha3 0x00 0x20)))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs( + fromHex("b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6"))); +} + +BOOST_AUTO_TEST_CASE(sha3_one_arg) +{ + char const* sourceCode = R"( + (returnlll + (return (sha3 0x01))) + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callFallback() == encodeArgs( + fromHex("b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6"))); +} + BOOST_AUTO_TEST_SUITE_END() } |