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

pallet-revive: EXTCODEHASH to match EIP-1052 #6088

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ermalkaleci
Copy link
Contributor

@ermalkaleci ermalkaleci commented Oct 16, 2024

Description

Update ext_code_hash to match EIP-1052 specs. Since all possible results are written into output pointer then there's no need for a return value.

paritytech/revive#77

@ermalkaleci ermalkaleci changed the title update revive EXTCODEHASH to match EIP-1052 pallet-revive: EXTCODEHASH to match EIP-1052 Oct 16, 2024
@ermalkaleci ermalkaleci marked this pull request as ready for review October 16, 2024 14:04
Copy link
Member

@xermicus xermicus left a comment

Choose a reason for hiding this comment

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

The idea looks correct but it needs proper testing.

Comment on lines 2385 to 2386
// ALICE is not a contract and hence they do not have a code_hash
assert!(ctx.ext.code_hash(&ALICE_ADDR).is_none());
assert!(ctx.ext.code_hash(&ALICE_ADDR).is_zero());
Copy link
Member

Choose a reason for hiding this comment

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

The comment is wrong. Or the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is all mocked and easily to get confused. I was trying to minimise changes :)

// BOB is a contract and hence it has a code_hash
assert!(ctx.ext.code_hash(&BOB_ADDR).is_some());
assert!(!ctx.ext.code_hash(&BOB_ADDR).is_zero());
Copy link
Member

Choose a reason for hiding this comment

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

This should compare against an actual value. Not being zero means it can either be a non-contract account or a contract account

Copy link
Member

Choose a reason for hiding this comment

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

Should also aim for testing both cases

substrate/frame/revive/src/exec.rs Outdated Show resolved Hide resolved
@@ -1859,7 +1866,7 @@ mod tests {
) -> H256 {
Loader::mutate(|loader| {
// Generate code hashes as monotonically increasing values.
let hash = <Test as frame_system::Config>::Hash::from_low_u64_be(loader.counter);
let hash = <Test as frame_system::Config>::Hash::from_low_u64_be(loader.counter + 1);
Copy link
Member

@xermicus xermicus Oct 16, 2024

Choose a reason for hiding this comment

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

In the context of this PR it is obvious why this is needed. But out of context I don't think it's obvious too. Can you please update the comment above?

@xermicus xermicus added R0-silent Changes should not be mentioned in any release notes T7-smart_contracts This PR/Issue is related to smart contracts. labels Oct 16, 2024
@@ -244,11 +244,7 @@ pub trait HostFn: private::Sealed {
///
/// - `addr`: The address of the contract.
/// - `output`: A reference to the output data buffer to write the code hash.
///
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to instead explain the returned value here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add documentation on implementation level

Copy link
Member

@xermicus xermicus Oct 16, 2024

Choose a reason for hiding this comment

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

Documentation on there doesn't hurt. But why not accurately document the API? Also the error case was documented before. Now this is implied by the returned value. I don't understand why this is no longer documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add it here as well but I think this is documented well, it takes an address and reference to write output.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah please do. We don't want people to needlessly puzzle together the full picture of our API. The error was documented before.

Copy link
Member

Choose a reason for hiding this comment

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

Yes sure it writes output. Now the error is gone from the method signature. How are people supposed to know what output is written when the address was not a contract or doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T7-smart_contracts This PR/Issue is related to smart contracts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants