-
Notifications
You must be signed in to change notification settings - Fork 187
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
Gate certain features behind a context
object.
#558
Comments
This looks good as far as I can tell. |
Currently we can read the address of the contract via To avoid any confusion I would say that they should all become context methods: Thoughts? |
I'm also leaning towards I think any value that is not determined purely by the contract's code and past transactions should fall in the category of So, for example, say you deploy a contract and invoke some |
Capturing from discord: With #601 and #603, we're getting close to being able to define this in fe. Stuff like
|
What is wrong?
One of the main objectives of Fe is to be explicit and easy to audit. The EVM exposes certain features such as writing logs, creating contracts or obtaining the current block number and it should be easy to determine from the signature of a function whether the function has the capabilities to use such features or not.
This is currently not the case, e.g we might currently have a function such as the following which - from it's signature - looks pure when in reality it does modify the blockchain (by emitting a log).
The
Context
objectWe propose to introduce a
Context
object which gates access to features such as:The
Context
object needs to be passed as a parameter to the function e.g. the example above would be rewritten as:Similar, creating a contract via
create
/create2
would also require to have access to theContext
object:As well does reading block chain information such as the current block number.
There are a few special rules about the context object:
The
Context
object has a defined location in the parameter list. It either is the first parameter if the function does not takeself
(e.g.pub fn foo(context:Context)
) or it comes second if the function does takeself
(e.g.pub fn foo(self, context:Context)
). Any other index in the parameter list is a compile time error.The
Context
object is automatically injected when a function is called externally but it has to be passed explicitly when the function is called from another Fe function e.g.Taking
mut Context
vsContext
As the eagle-eyed reader might have noticed the examples above either use
mut Context
orContext
. This proposal can be implemented independent of having support formut
in Fe but it would naturally benefit from havingmut
support because all functionality that modifies the blockchain such as creating logs or contracts would require to obtain amut Context
reference whereas readonly access such asctx.blocknumber()
does not need require a mutable reference to the context.ABI conformity
The proposed system works nicely with the existing function categories in the ABI but offers even tighter rules for added clarity.
self
and therefore has no access to things that would make it impurefoo(val: u256)
pure
foo(self)
view
foo(mut self)
payable
ornonpayable
foo(ctx: Context)
view
foo(ctx: mut Context)
payable
ornonpayable
foo(self, ctx:Context)
view
foo(self, ctx: mut Context)
view
foo(mut self, ctx: Context)
payable
ornonpayable
foo(mut self, ctx: mut Context)
payable
ornonpayable
With the proposed system Fe would have nine different categories that can be derived from the function signatures that map to four different ABI types.
This brain dump is based on the PR discussion in #527 which offers more detailed reasoning and is worth a read.
The text was updated successfully, but these errors were encountered: