Skip to content
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

[evm] fix GetHash function #2998

Merged
merged 4 commits into from
Jan 18, 2022
Merged

[evm] fix GetHash function #2998

merged 4 commits into from
Jan 18, 2022

Conversation

dustinxie
Copy link
Member

No description provided.

@dustinxie dustinxie requested a review from a team as a code owner January 15, 2022 19:23
@codecov
Copy link

codecov bot commented Jan 15, 2022

Codecov Report

Merging #2998 (41f58ee) into master (5689e41) will increase coverage by 0.00%.
The diff coverage is 25.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2998   +/-   ##
=======================================
  Coverage   61.54%   61.54%           
=======================================
  Files         192      192           
  Lines       21680    21688    +8     
=======================================
+ Hits        13342    13347    +5     
- Misses       6661     6665    +4     
+ Partials     1677     1676    -1     
Impacted Files Coverage Δ
action/protocol/context.go 38.13% <0.00%> (-0.33%) ⬇️
action/protocol/execution/evm/evm.go 45.89% <27.27%> (-0.69%) ⬇️
db/trie/mptrie/branchnode.go 84.31% <0.00%> (+1.30%) ⬆️
db/trie/mptrie/extensionnode.go 71.65% <0.00%> (+1.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5689e41...41f58ee. Read the comment docs.

require.NoError(err)
acHash7, err := addOneBlock(contract, 7, zero, gasLimit, gasPrice, getBlockHash(6)) // equal to genesis block
require.NoError(err)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move into for loop to make the code more clean

@Liuhaai
Copy link
Member

Liuhaai commented Jan 15, 2022

Could we test opBlockhash in solidity?

@dustinxie
Copy link
Member Author

Could we test opBlockhash in solidity?

yes, the test deploys a contract which end up calling opBlockhash in solidity: https:/iotexproject/iotex-core/pull/2998/files#diff-376031ecf84904d1ad817660ba4a12fcf9143faed75224a178fdad3ebcefd63eL621-L634

Copy link
Collaborator

@CoderZhi CoderZhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dustinxie
Copy link
Member Author

https:/ethereum/go-ethereum/blob/b1e72f7ea998ad662166bcf23705ca59cf81e925/core/vm/instructions.go#L442-L454

yes, that's EVM internal implementation, it checks if the requested number is within last 256 blocks, if yes, call GetHash(), otherwise set to all-0
so what is the specific thing to do/change?

@Liuhaai
Copy link
Member

Liuhaai commented Jan 17, 2022

Could you check why is time fixed in L647
blockTime := time.Unix(1546329600, 0)

hash, err := getBlockHash(stateDB.blockHeight - n)
if err != nil {
hash, err := getBlockHash(n)
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err != nil {
}
return

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for clarity would rather keep it same as current code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. Could you file a new issue to correct the style here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think it's necessary? we have lots of if err == nil in the codebase

return common.BytesToHash(hash[:])
}
return common.Hash{}
}
} else {
case featureCtx.FixGetHashFnHeight:
getHashFn = func(n uint64) common.Hash {
hash, err := getBlockHash(stateDB.blockHeight - (n + 1))
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

}
for _, test := range tests {
r, err := dao.GetReceiptByActionHash(test.acHash, test.commitHeight)
h, err := addOneBlock(contract, nonce, zero, gasLimit, gasPrice, getBlockHash(int64(test.getHashHeight)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name getBlockHash is confusing. It is actually the data of the tx

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is the data of tx, but what the tx does is to getBlockHash, so i think it's fine?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. the name getBlockHash is expected to return a hash. But it returns []byte.
I'd prefer calldata

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in 3rd commit

{11, 1},
{12, 4},
{13, 0},
{14, 100},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add one more test {15, 15}?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in 2nd commit

@dustinxie dustinxie merged commit bc2d3ea into iotexproject:master Jan 18, 2022
@dustinxie dustinxie deleted the check branch January 18, 2022 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants