Skip to content

Conversation

d-xo
Copy link
Contributor

@d-xo d-xo commented Jul 1, 2025

@clonker and I put together a rough sketch of what the high level contract syntax would desugar into.

still todo:

  • constructors
  • storage
  • conditional logic for lifting the non payable check to the top if all methods on the contract are not payable.

@d-xo
Copy link
Contributor Author

d-xo commented Sep 4, 2025

found a fixed a couple of unrelated bugs. they're pushed here for now, but I'll pull them out into seperate prs against main to ease review.

@d-xo d-xo force-pushed the dispatch branch 2 times, most recently from 5e1f3c1 to cf1317a Compare September 9, 2025 12:26
d-xo and others added 18 commits September 9, 2025 14:39
std/dispatch.sol contains a rough sketch of what the high level contract
syntax would desugar into.

still todo:

  - constructors
  - storage
  - conditional logic for lifting the non payable check to the top if
    all methods on the contract are not payable.
Fixes the dispatch code to operate almost entirely on runtime values
instead of proxies (as previously used). This fixes the type checking
errors but still produces errors during codegen.
the wrapped yul dialect available in solidity assembly blocks does not
allow the usage of some important primitives that we need to implement
contract desugaring (e.g. memoryguard) so we migrate our default
compilation harness to use the pure yul pipeline and execute via hevm
instead.
Classic Solidity will lift the callvalue check to the top level if all
methods are non payable. We should match this behaviour at some point.

This commit removes a non functional attempt at the above feature for
the sake of progress. The previous version incorrectly assumed that the
default instance would be selected if constraints on all other instances
could not be entailed. The reality is that for now we only select the
default if there are no available non default instances that unify with
the type.

In the future we will need to either make default instance selection
more powerful or figure out how to match the classic solidity behaviour
without it.
This is needed when importing a file that contains pragma definitions
into another one. Pragmas are merged additively, with a catch all pragma
defintion taking precendence and forcing the check to be disabled for
all instances
The fv function was only including skolem vars in the free variable set
(not regular type variables). This was causing the bound variable check
to incorrectly accept instances that should have been rejected
d-xo added 4 commits September 9, 2025 14:55
return is used as both a surface level keyword and a yul level
function. This modifies the surface level parser to correctly handle
`return` in yul blocks.
bool matching seems to still need some work for emitting core
@d-xo
Copy link
Contributor Author

d-xo commented Sep 9, 2025

This is now finally working for method execution:

> ./runsol.sh std/dispatch.solc --calldata "add2(uint256,uint256)" 2 2
Processing: std/dispatch.solc
Compiling to core...
Warning: The package list for 'hackage.haskell.org' is 99 days old.
Run 'cabal update' to get the latest list of available packages.
Warning: Parsing the index cache failed (Data.Binary.Get.runGet at position
16: Non-matching structured hashes: d81bdd513f41b5d7ee4cd28455adadbe;
expected: f46da61e7afa58a5e8fd1d2b6fb79899). Trying to regenerate the index
cache...
Resolving dependencies...
Emitting core for contract C
Writing to output1.core
Generating Yul...
Warning: The package list for 'hackage.haskell.org' is 99 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
found main
writing output to dispatch.yul
Compiling to bytecode...
Hex output: dispatch.hex
Executing...
"Return: 0x0000000000000000000000000000000000000000000000000000000000000004"
Decoded: 4

Still to do:

  • fallback execution
  • split up this big PR into smaller independent ones

@d-xo
Copy link
Contributor Author

d-xo commented Sep 16, 2025

split into a bunch of smaller prs to make reviewing easier:

#196, #197, #199, #200, #201

@d-xo d-xo closed this Sep 16, 2025
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.

2 participants