Move blockhash from block.blockhash to global level.#3646
Conversation
| - ``assert(bool condition)``: abort execution and revert state changes if condition is ``false`` (use for internal error) | ||
| - ``require(bool condition)``: abort execution and revert state changes if condition is ``false`` (use for malformed input or error in external component) | ||
| - ``revert()``: abort execution and revert state changes | ||
| - ``blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent blocks |
There was a problem hiding this comment.
I think all these values should be sorted somehow...
There was a problem hiding this comment.
Do you have a strong opinion on how they should be sorted? Otherwise I'd probably sort them by variable in alphabetical order.
There was a problem hiding this comment.
Yes, alphabetically, but that can be a separate PR.
| Global Variables | ||
| ================ | ||
|
|
||
| - ``block.blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent blocks |
There was a problem hiding this comment.
Please keep the old one and mark it as deprecated.
| Block and Transaction Properties | ||
| -------------------------------- | ||
|
|
||
| - ``block.blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent blocks excluding current |
There was a problem hiding this comment.
Were the two leading -- here on purpose?
There was a problem hiding this comment.
Did you check if they have any effect?
docs/units-and-global-variables.rst
Outdated
|
|
||
| .. note:: | ||
| Do not rely on ``block.timestamp``, ``now`` and ``block.blockhash`` as a source of randomness, | ||
| Do not rely on ``block.timestamp`` and ``now`` as a source of randomness, |
| but the only guarantee is that it will be somewhere between the timestamps of two | ||
| consecutive blocks in the canonical chain. | ||
|
|
||
| .. note:: |
There was a problem hiding this comment.
It probably does not hurt to have all the warnings in both places.
| break; | ||
| case Type::Category::Magic: | ||
| // we can ignore the kind of magic and only look at the name of the member | ||
| if (member != "data" && member != "sig" && member != "blockhash") |
| return MemberList::MemberMap({ | ||
| {"coinbase", make_shared<IntegerType>(160, IntegerType::Modifier::Address)}, | ||
| {"timestamp", make_shared<IntegerType>(256)}, | ||
| {"blockhash", make_shared<FunctionType>(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)}, |
There was a problem hiding this comment.
Please only remove it if pragma experimental "v0.5.0" is set.
| } | ||
| )"; | ||
| compileAndRun(sourceCode); | ||
| BOOST_CHECK_EQUAL(callContractFunction("a()").empty(), false); |
There was a problem hiding this comment.
Please use ABI_CHECK(callContractFunction(...), encodeArgs(0))
There was a problem hiding this comment.
Ah sorry, I misunderstood this. I think it is easier to read if you just use
BOOST_CHECK(!callContractFunction("a()").empty()), or perhaps even BOOST_CHECK_EQUAL(callContractFunction("a()").length(), 32);
| char const* text = R"( | ||
| contract test { | ||
| function blockhash() pure public returns (bytes32) {} | ||
| } |
There was a problem hiding this comment.
Maybe add another function to the test contract that calls the local blockhash and checks whether the compiler resolves it correctly, e.g. by using a return type that is incompatible to the return type of global blackhash and assigning the result of the function call to a variable?
There was a problem hiding this comment.
I think it's better to have a function with identical signature (including return type) and use an EndToEnd test to check.
|
Updated |
|
Tests are failing: blockhash_not_available_in_block and blockhash_shadow |
|
Sorry, merged the other one first ;) |
| char const* text = R"( | ||
| contract Test { | ||
| function a() public returns (bytes32) { | ||
| return block.blockhash(0); |
There was a problem hiding this comment.
This should only fail if v050 mode is selected.
| vector<string> view{ | ||
| "block.coinbase", | ||
| "block.timestamp", | ||
| "block.blockhash(7)", |
There was a problem hiding this comment.
These shouldn't be removed (in v050 mode).
|
@ekpyron I will have a look into your suggestion regarding deprecation of |
|
The list of commits looks a little bit messed up :) |
|
@chriseth Yep, I accidentally messed it up. Should be fine now :) There's just this one comment about deprecating |
|
Ready for review. |
|
There are still two consecutive commits with the same description. |
docs/miscellaneous.rst
Outdated
| ================ | ||
|
|
||
| - ``block.blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent blocks | ||
| - ``block.blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent blocks - deprecated in version 0.4.21 and to be replaced by ``blockhash(uint blockNumber)``. |
There was a problem hiding this comment.
Please update the version to 0.4.22
|
@chriseth I've change the version number mentioned in your last comment and also checked the additional |
libsolidity/ast/Types.cpp
Outdated
| {"number", make_shared<IntegerType>(256)}, | ||
| {"gaslimit", make_shared<IntegerType>(256)} | ||
| }); | ||
| { |
There was a problem hiding this comment.
In case-statements the { usually have the same indentation level as the case keyword itself.
There was a problem hiding this comment.
Did you actually change anything here?
There was a problem hiding this comment.
No. In the end I did not change anything. These braces are leftovers from a previous commit and I'll remove them.
chriseth
left a comment
There was a problem hiding this comment.
Only the small formatting issue left in my opinion.
|
@chriseth Fixed the formatting |
|
@axic please merge if you are fine with this PR. |
|
Sorting out the rebase. |
|
Tests are passing. Can be merged in my opinion. |
| Block and Transaction Properties | ||
| -------------------------------- | ||
|
|
||
| - ``block.blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent blocks excluding current |
There was a problem hiding this comment.
Can't comment inline, but the note below still uses block.blockhash, should be updated, since the copy of that note in miscellaneous does the same.
docs/miscellaneous.rst
Outdated
| ================ | ||
|
|
||
| - ``block.blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent blocks | ||
| - ``block.blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent blocks - deprecated in version 0.4.22 and to be replaced by ``blockhash(uint blockNumber)``. |
|
Improved documentation. Should be ready to merge. |
e4b7644 to
c5b6a2e
Compare
Closes #2970