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

Implement seal_is_contract and seal_caller_is_origin #1129

Merged
merged 20 commits into from
Feb 23, 2022

Conversation

agryaznov
Copy link
Contributor

Follow-up for paritytech/substrate#10789.

Needed for #804.

@agryaznov agryaznov changed the title Implement 'seal_is_contract and seal_caller_is_origin` Implement seal_is_contract and seal_caller_is_origin Feb 9, 2022
@athei athei linked an issue Feb 9, 2022 that may be closed by this pull request
@xgreenx
Copy link
Collaborator

xgreenx commented Feb 9, 2022

Hmm, I didn't notice the initial PR in the substrate so I didn't comment there. But maybe better to implement the function that returns origin. Like seal_origin and if the user wants to check he can compare it with caller.

Copy link
Contributor

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

It looks like it works, but needs a bit of cleanup

crates/env/src/backend.rs Outdated Show resolved Hide resolved
crates/lang/src/env_access.rs Show resolved Hide resolved
crates/lang/src/env_access.rs Show resolved Hide resolved
examples/is-contract/.gitignore Outdated Show resolved Hide resolved
examples/is-contract/Cargo.toml Outdated Show resolved Hide resolved
examples/is-contract/lib.rs Outdated Show resolved Hide resolved
examples/is-contract/lib.rs Outdated Show resolved Hide resolved
examples/is-contract/lib.rs Outdated Show resolved Hide resolved
crates/env/src/engine/on_chain/ext.rs Outdated Show resolved Hide resolved
crates/env/src/engine/on_chain/ext.rs Outdated Show resolved Hide resolved
@agryaznov
Copy link
Contributor Author

It looks like it works, but needs a bit of cleanup

@HCastano thanks for your review! Here comes the cleaned-up version

@athei
Copy link
Contributor

athei commented Feb 15, 2022

Some notes:

  • It is best to not force push your branch once you asked for reviews. It makes it hard to find out which parts you already reviewed.
  • Please make sure to satisfy the CI (except waterfall).

@athei
Copy link
Contributor

athei commented Feb 17, 2022

Hmm, I didn't notice the initial PR in the substrate so I didn't comment there. But maybe better to implement the function that returns origin. Like seal_origin and if the user wants to check he can compare it with caller.

I think we should have both functions.

@xgreenx
Copy link
Collaborator

xgreenx commented Feb 17, 2022

I think we should have both functions.

Agree. When is possible we will use cheaperseal_caller_is_origin, else seal_origin.

@HCastano
Copy link
Contributor

Please make sure to satisfy the CI (except waterfall).

Please do fix any ink-waterfall issues, we fixed the CI staged a week or two ago 😄

@athei
Copy link
Contributor

athei commented Feb 17, 2022

Please make sure to satisfy the CI (except waterfall).

Please do fix any ink-waterfall issues, we fixed the CI staged a week or two ago 😄

But I think the node version used might be too old if the new features are used in the examples? How do I update the node there? It appears to be installed in the CI image?

@cmichi
Copy link
Collaborator

cmichi commented Feb 17, 2022

But I think the node version used might be too old if the new features are used in the examples? How do I update the node there? It appears to be installed in the CI image?

The substrate-contracts-node in the CI's Docker image is updated nightly: /~https://github.com/paritytech/scripts/blob/master/dockerfiles/contracts-ci-linux/Dockerfile#L53-L56. So should be fine. And CI on this PR already fails earlier.

@cmichi
Copy link
Collaborator

cmichi commented Feb 17, 2022

@agryaznov You should see the CI output if you click on "Details" right of the failed jobs. You can also reproduce it locally, this list here should give some hints: /~https://github.com/paritytech/ink/blob/master/CONTRIBUTING.md#checklist (it might be a bit outdated though, so better ask before trying to figure out why something isn't working).

@athei
Copy link
Contributor

athei commented Feb 17, 2022

But I think the node version used might be too old if the new features are used in the examples? How do I update the node there? It appears to be installed in the CI image?

The substrate-contracts-node in the CI's Docker image is updated nightly: /~https://github.com/paritytech/scripts/blob/master/dockerfiles/contracts-ci-linux/Dockerfile#L53-L56. So should be fine. And CI on this PR already fails earlier.

Is it build with contracts-unstable-interface?

@cmichi
Copy link
Collaborator

cmichi commented Feb 17, 2022

But I think the node version used might be too old if the new features are used in the examples? How do I update the node there? It appears to be installed in the CI image?

The substrate-contracts-node in the CI's Docker image is updated nightly: /~https://github.com/paritytech/scripts/blob/master/dockerfiles/contracts-ci-linux/Dockerfile#L53-L56. So should be fine. And CI on this PR already fails earlier.

Is it build with contracts-unstable-interface?

Yup: /~https://github.com/paritytech/substrate-contracts-node/blob/main/runtime/Cargo.toml#L58-L63.

@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2022

Codecov Report

Merging #1129 (7d463d6) into master (07a8ed9) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1129   +/-   ##
=======================================
  Coverage   78.69%   78.69%           
=======================================
  Files         252      252           
  Lines        9395     9395           
=======================================
  Hits         7393     7393           
  Misses       2002     2002           
Impacted Files Coverage Δ
crates/env/src/api.rs 36.36% <ø> (ø)
crates/env/src/backend.rs 80.64% <ø> (ø)
...tes/env/src/engine/experimental_off_chain/impls.rs 53.70% <ø> (ø)
crates/env/src/engine/off_chain/impls.rs 41.88% <ø> (ø)
crates/lang/src/env_access.rs 12.00% <ø> (ø)

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 07a8ed9...7d463d6. Read the comment docs.

@paritytech-cicd-pr
Copy link

paritytech-cicd-pr commented Feb 18, 2022

🦑 📈 ink! Example Contracts ‒ Changes Report 📉 🦑

These are the results when building the examples/* contracts from this branch with cargo-contract 0.17.0-ab41bd9 and comparing them to ink! master:

Δ Optimized Size Δ Used Gas Total Optimized Size Total Used Gas
accumulator 1.28 K
adder 2.23 K
contract-terminate 1.23 K 215_704
contract-transfer 8.37 K 15_704
delegator 6.26 K 33_142
dns 9.64 K 47_112
erc1155 27.71 K 94_224
erc20 9.12 K 47_112
erc721 14.40 K 125_632
flipper 1.57 K 15_704
incrementer 1.49 K 15_704
multisig 26.38 K 103_006
proxy 2.98 K 32_082
rand-extension 4.40 K 15_704
subber 2.24 K
trait-erc20 9.39 K 47_112
trait-flipper 1.35 K 15_704
trait-incrementer 1.45 K 31_408

Link to the run | Last update: Wed Feb 23 12:27:29 CET 2022

@agryaznov
Copy link
Contributor Author

CI issues seem to be fixed now.
Have to suppress wrong_self_convention clippy check or to rename is_contract function.
The first option is chosen for now.

crates/env/src/api.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@cmichi cmichi left a comment

Choose a reason for hiding this comment

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

I've got only some nitpicks, looks good besides that, we can merge after those are fixed.

Could you click "Resolve conversation" for the comments by reviewers which were resolved? That makes it easier to follow what's going on. Thanks!

@HCastano
Copy link
Contributor

Will take a look at this again today, sorry!

@agryaznov
Copy link
Contributor Author

I'm not sure why ink-waterfall ci now fails.

It began to fall with an error starting from this commit which changes nothing apart from comment typos.

@cmichi
Copy link
Collaborator

cmichi commented Feb 22, 2022

I'm not sure why ink-waterfall ci now fails.

It began to fall with an error starting from this commit which changes nothing apart from comment typos.

It's not your fault, it's because we currently don't use fixed nightly versions anywhere in CI. Since yesterday the Rust nightly version contains a bug which makes cargo-contract fail. You can also see it if you take a look at the CI on master for ink and cargo-contract. Today a commit was merged into Rust which I hope will fix this, so if we're lucky the master CI should work everywhere again tomorrow (every night there is an automatic run of the CI's on master with the latest Rust nightly).

For this PR we can ignore the ink-waterfall for now.

Copy link
Collaborator

@cmichi cmichi left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

Copy link
Contributor

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

Couple small things, but looks good!

My take on resolving comments: as a reviewer I want to be the one to mark comments as resolved. That way I'm able to get a refresher on what comments I've made, and judge whether or not they were actually resolved correctly

Comment on lines +861 to +863
/// pub fn is_contract(&mut self, account_id: AccountId) -> bool {
/// self.env().is_contract(&account_id)
/// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// pub fn is_contract(&mut self, account_id: AccountId) -> bool {
/// self.env().is_contract(&account_id)
/// }
/// pub fn is_contract(&mut self, account_id: &AccountId) -> bool {
/// self.env().is_contract(account_id)
/// }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, no, this won't work as Ink messages can't take references as params.

crates/env/src/api.rs Outdated Show resolved Hide resolved
crates/env/src/engine/off_chain/impls.rs Outdated Show resolved Hide resolved
crates/env/src/engine/experimental_off_chain/impls.rs Outdated Show resolved Hide resolved
Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
@athei
Copy link
Contributor

athei commented Feb 23, 2022

The other tests need to be green, though :)

Copy link
Contributor

@athei athei left a comment

Choose a reason for hiding this comment

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

LGTM. You can merge once the CI is green.

@agryaznov agryaznov merged commit ff5add1 into use-ink:master Feb 23, 2022
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.

Is there a way to check if an AccountId is a contract?
7 participants