-
Notifications
You must be signed in to change notification settings - Fork 2
std: add instances for contract dispatch desugaring #201
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
base: main
Are you sure you want to change the base?
Conversation
std/dispatch.solc
Outdated
|
||
// --- Preliminaries --- | ||
|
||
data Bool = True | False; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the builtin bool
type gave me a bunch of specializer errors I didn't understand. I'll try to find a minimal reproducer and submit a bug.
814fdef
to
b2c9d2e
Compare
This adds the core datatype definitions and class / instance definitions that allow us to desugar a surface level `contract` definition into a single entrypoint that dispatches to the contracts methods based on it's function selector hash. An example desugaring can be seen at the end of the file. Still to do: - receive() - move callvalue check to the top level if all methods are not payable - `public` / `external`
f88dd77
to
5023704
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record
- fails if a contract has more than one method
- problems with argumentless methods (e.g.
function one() -> uint256 { return uint256(1); }
It also would be good to split the library part from the example
This adds the core datatype definitions and class / instance definitions that allow us to desugar a surface level
contract
definition into a single entrypoint that dispatches to the contracts methods based on it's function selector hash.An example desugaring can be seen at the end of the file. At a high level each surface level
contract
object will have amain
generated that callsRunContract.exec
on an instance of theContract
datatype reflecting the structure of the given contract. The defined typeclass instances will handle the dispatch generation and abi encoding/decoding.Still to do:
public
/external
Pending a decision on our implementation of compile time eval it also relies on the desugaring stage to precompute the selector hash and insert that directly into the bytecode.
You can test the desugaring logic as follows. This will call the
add2
method with2
and3
abi encoded, and then display the result: