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

[WIP] Allow constants access through contract names #3214

Closed
wants to merge 5 commits into from

Conversation

kseo
Copy link
Contributor

@kseo kseo commented Nov 16, 2017

Fixes #1290.

@chriseth
Copy link
Contributor

Thanks, that's a very good start!

@kseo
Copy link
Contributor Author

kseo commented Nov 16, 2017

@chriseth What other places do I need to change besides TypeType::nativeMembers?

@axic
Copy link
Member

axic commented Nov 16, 2017

@kseo you could add test cases first and see what is not working and/or what was broken by the change and track it down from there

@ekpyron ekpyron self-assigned this Apr 5, 2018
@ekpyron ekpyron force-pushed the constants-access branch from aeaa6bb to 2d25b91 Compare April 5, 2018 12:35
axic
axic previously requested changes Apr 5, 2018
Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

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

At the minimum this needs tests and changelog entry.

@axic
Copy link
Member

axic commented Apr 5, 2018

Since constant can contain expressions (which are copied and evaluated a the place they are used) and refer to other constants it probably makes sense to have a complex test case, such as:

contract C {
  uint constant a = 33 * b + 4; // can also mix keccak256(b) into this
  uint constant b = 44;
}

contract D {
  uint constant b = 66;
  function f() returns (uint) {
    return C.a;
  }
}

The goal here is to ensure that b is looked up from the correct contract when evaluating the constant expression.

@axic
Copy link
Member

axic commented Apr 5, 2018

This reminds me (it is not strictly related to this PR), but we could add tests for storage constant and memory constant.

@ekpyron ekpyron force-pushed the constants-access branch 2 times, most recently from b43eaf9 to dea1ae2 Compare April 6, 2018 12:21
@ekpyron ekpyron changed the title [WIP] Allow constants access through contract names (issue #1290) Allow constants access through contract names (issue #1290) Apr 6, 2018
@ekpyron ekpyron dismissed axic’s stale review April 6, 2018 12:37

PR updated.

@axic axic requested a review from chriseth April 11, 2018 19:48
@axic
Copy link
Member

axic commented Apr 11, 2018

@chriseth this needs to be reviewed

Copy link
Contributor

@chriseth chriseth left a comment

Choose a reason for hiding this comment

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

Please add a test for

  • cross-contract cycle checks

compileAndRun(sourceCode, 0, "Test");
ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1456)));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any other weird cases we have to test? Is it somehow possible to use super or this in that context?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to access constants via super? If yes, does that work correctly if that constant is accessed from another contract?

Copy link
Member

Choose a reason for hiding this comment

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

Access via super is not allowed so far - I think it'd be better to have to use the name of the base explicitly instead. I can change that, though, if you think otherwise. In any case I added a test (for now with the expectation that access through super is not possible).

@ekpyron ekpyron changed the title Allow constants access through contract names (issue #1290) [WIP] Allow constants access through contract names (issue #1290) Apr 12, 2018
@ekpyron
Copy link
Member

ekpyron commented Apr 12, 2018

@chriseth I added some more test cases, but indeed cross-contract cycle detection does not currently work. Since this PR was not originally planned for 0.4.22, I suggest that I first continue to review the other PRs and then get back to this, unless you definitely want this in the current release.

@ekpyron ekpyron changed the title [WIP] Allow constants access through contract names (issue #1290) Allow constants access through contract names (issue #1290) Apr 12, 2018
@ekpyron ekpyron force-pushed the constants-access branch 2 times, most recently from 2290134 to 9012398 Compare April 12, 2018 19:32
@ekpyron
Copy link
Member

ekpyron commented Apr 13, 2018

Cross contract cycle detection should work now and this is ready for review.

@chriseth
Copy link
Contributor

Please add a test case for

contract A {
    function f() pure returns (uint) { return 1; }
}
contract B is A {
    uint constant x = super.f();
}
contract Y {
    function f() pure returns (uint) { return 2; }
    
}
contract X is Y {
    uint constant a = B.x;
}

and check what the value of a is.

@chriseth
Copy link
Contributor

Note that we currently still allow non-compile-time-constant constants - we only add a warning. Because of that I would say this is too dangerous to include in the release.

@chriseth
Copy link
Contributor

Did we test accessing address x = address(this) from different contracts?

@ekpyron ekpyron force-pushed the constants-access branch from 9012398 to 8f6df55 Compare May 2, 2018 08:23
@ekpyron ekpyron changed the title Allow constants access through contract names (issue #1290) [WIP] Allow constants access through contract names (issue #1290) May 2, 2018
@ekpyron ekpyron force-pushed the constants-access branch 3 times, most recently from fe4cb56 to 6cdd5aa Compare May 2, 2018 11:53
@ekpyron
Copy link
Member

ekpyron commented May 2, 2018

I updated the PR to include @chriseth's test (before the latest changes the test contract would cause a fatal compiler error; now the expected value of a is 1).

However:

  • In the meantime I agree that this PR should be postponed as long as non-compile-time-constant constants are possible.
  • One might actually argue that in the new cross_contract_constants_super_call test the value of a should be 2 and not 1, so this has to be discussed. In general I think it may be a good idea to postpone this PR until e.g. Constant expression evaluation at compile time #3157 is settled.

}
contract X is Y {
uint constant a = B.x;
function g() pure returns (uint) { return a; }
Copy link
Member

Choose a reason for hiding this comment

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

@ekpyron why would you argue it would be reasonable to have this return 2?

Copy link
Member

Choose a reason for hiding this comment

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

@axic I would definitely expect 1 here, but then I might also expect

BOOST_AUTO_TEST_CASE(super)

to either result in 11 or 13 and not in 15... in that test super traverses the entire inheritance graph of the context from which it is first invoked - if I think about it that way, than I might expect it to prefer X's context, even if it occurs in B...

I would still want the result here to be 1, but I thought it might be good to discuss this wrt consistency issues anyways.

@ekpyron ekpyron changed the title [WIP] Allow constants access through contract names (issue #1290) [WIP] Allow constants access through contract names May 9, 2018
@ekpyron ekpyron force-pushed the constants-access branch from 6cdd5aa to 952bb6f Compare May 14, 2018 10:37
@axic
Copy link
Member

axic commented Jul 25, 2018

What is the status of this? I am kind of lost.

@ekpyron
Copy link
Member

ekpyron commented Aug 1, 2018

@axic The current status of this is "postponed". We could think about re-evaluating this now, though.

@chriseth
Copy link
Contributor

chriseth commented Dec 5, 2018

Closing because it got stale and there are still discussions about the underlying feature.

@chriseth chriseth closed this Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants