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

Top-level blockchain-specific declarations #3

Closed
adlerjohn opened this issue Jan 29, 2021 · 9 comments
Closed

Top-level blockchain-specific declarations #3

adlerjohn opened this issue Jan 29, 2021 · 9 comments
Assignees
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@adlerjohn
Copy link
Contributor

To support all the functionality of the transaction format supported with Fuel v2 I suggest the following top-level declarations:

  1. contract: defines a list of externally-callable functions that will be part of the contract's ABI, and a list of internally callable functions that are not part of the ABI. The ABI essentially replaces a main function with a giant switch statement to call different functions. Contracts will persist in the FuelVM's state.
contract {}
  1. script: defines a single function that operates at the transaction level. Scripts exist only for the duration of a transaction.
script (input) -> output {}
  1. predicate: defines a single function that must return a bool that operates at the input level. Predicates only exist for the duration of verifying the unlocking condition of an input.
predicate (input) -> bool {}

Smart contract developers will only use the first for writing their contract. Wallet and surrounding tooling can develop scripts and predicates using the latter two. But integration within a single language is important so that calls between them (say, a contract's function being called by a script) are type-safe, etc.

@sezna
Copy link
Contributor

sezna commented Jan 31, 2021

This makes sense, I can add this to the todo list.

@SilentCicero
Copy link
Member

SilentCicero commented Jan 31, 2021 via email

@adlerjohn
Copy link
Contributor Author

Ethereum contracts don't have a main function.

@SilentCicero
Copy link
Member

SilentCicero commented Feb 1, 2021 via email

@sezna
Copy link
Contributor

sezna commented Feb 18, 2021

Should script be a top level block or should anything not within a predicate or contract be considered a script?

@adlerjohn
Copy link
Contributor Author

adlerjohn commented Feb 18, 2021

You could say that technically anything that isn't a predicate or a contract can be part of the script, but that feels...messy? Because then your imports and pragmas and whatever are all part of the same scope as the predicate's body. Adding a predicate {} doesn't seem like much more work (correct me if I'm wrong) and adds clarity.

@sezna
Copy link
Contributor

sezna commented Feb 18, 2021

I was just thinking if you are writing a small script it may feel superfluous to wrap it in a script {} block. I've implemented script {}, contract {}, and predicate {} blocks in the parser already, so we can definitely stick with that for now. Maybe we can see what the community thinks upon release and tweak it if it's an issue.

@sezna
Copy link
Contributor

sezna commented Mar 16, 2021

update: there is now also a library {} for code intended to be used only as a library import

@adlerjohn adlerjohn added the compiler General compiler. Should eventually become more specific as the issue is triaged label May 12, 2021
@sezna
Copy link
Contributor

sezna commented Aug 4, 2021

@digorithm

mitchmindtree pushed a commit to mitchmindtree/sway that referenced this issue Mar 28, 2022
Added "modulo" function so the % operator works

Very simple implementation to all the other functions just wrapping the mod opcode
mitchmindtree pushed a commit to mitchmindtree/sway that referenced this issue Mar 28, 2022
mitchmindtree added a commit that referenced this issue Mar 29, 2022
* Initial commit

* Initial commit

* initial commit

* intial commit

* update manifest to use git core dependency

* add README

* Add README

* Fix link to forc (#1)

* Fix link to forc (#1)

* Add basic build CI workflow (#2)

* Add basic build CI workflow.

* Remove installation and use of fuel-core.

* Implement Modulo (#3)

Added "modulo" function so the % operator works

Very simple implementation to all the other functions just wrapping the mod opcode

* .gitattributes to highlight .sw syntax as rust (#3)

* .gitattributes to highlight .sw syntax as rust (#5)

* Add Result type (#6)

* Add Result type.

* Fix syntax.

* Add basic build CI workflow. (#8)

* Add in rsh and lsh operations (#6)

* Update ops.sw

* Weird spacing thing

* ec-recover (#5)

* Add ecr lib

* Add todo comment

* Add recover_pubkey and refactor ecr

* Fixup

* Update comments

* Add comments to ec-recover asm block

* Modify asm

* Clean up asm

* Fix B512 field assignment

* Fix ordering of lib deps

* Remove ec_recover, to be added in separate PR

* Clean up comments

* Adding the missing `ec_recover`functionality (#18)

* Add todo comment

* Add working ec_recover implementation

* Format manifest file. (#10)

* Adding the `mint` and `burn` token operations. (#26)

* Add token lib

* Add todo comment

* Rename token_id to asset_id

* Rename token_id to asset_id

* Rename token_id to asset_id

* Fix register names in asm block

* Fixup

* Refactor ugly  while loop

* Fixup

* Remove ecr from branch

* Fix review issues

* Modify type definition to silence warning re losing precision via type-cast

* Fix asm block registers

* Add only the mint function

* Ad burn to token lib

* "fix toml file"

* Split `eq` out of `Ord` and put it in `Eq` (#9)

* Moved eq into its own trait (Eq)

Moved eq into it's own trait (Eq) and then added all the implementations for u64, u32, u16, u8, and b256

* Forgot to delete u16's old Eq implementation

* Move le to a test implementation

* Fixed ge, le, and neq to not use eq and instead use inline assembly

* Update ops.sw

* Formatting changes

* Adding the force_transfer function to the token lib. (#27)

* Add force_transfer function to token lib

* Add import of ContractID type

* Implement the Eq trait for Address (#25)

* Impl Ord for Address

* Fix todo comment

* Fix toml formatting

* Add comment to use meq

* Impl Eq for Address

* Fix formatting

* Remove todo

* Add more methods to Result. (#16)

* Add more methods to Result.

* Don't use catch all.

* Use catch up, but fix typo.

* Fix return type.

* Compile workarounds.

* fmt

* Remove todo comments.

* fmt

* Make Result public.

* Add Option type & is_some/is_none methods (#31)

* Feat:Add Option type & is_some/is_none methods

* Doc:Improve module-level docs

* Fix:Add generic type T to match

* Simplify the B512 (and therefore ECR) code. (#33)

* Simplify the B512 (and therefore ECR) code.

Instead of 2 b256 fields in a struct we can use a 2 element array
instead.

I found that both the assumptions about memory layout and all the
copying was producing brittle code, and simplifying the ASM blocks as
much as possible is a good thing.

* Do a `forc fmt`.

* Adding the transfer_to_output function to token library (#32)

* Add force_transfer function to token lib

* Add import of ContractID type

* Add transfer_to_output function to token lib

* Add imports and temp remove constants

* Add else clause to if branch

* Add better comment

* Add final else clause to if branch

* Add semicolons to if-else

* style: add a comment and remove trailing semicolon from if statement in return position

* fix: make some comments internal

* fix: re-enable constants

* fix: change OUTPUT_LENGTH_LOCATION from 48 to 56

* fix: clean up assembly and incorporate PR review feedback

* docs: fix comments to reflect change to OUTPUT_LENGTH_LOCATION

* fix: remove redundent local variable assignment

* refactor: split asm blocks to avoid a second usage of the xos opcode

* style: forc fmt

* fix:change offset to 40 for getting amount

* Implementing an initial version of a msg_sender function (#30)

* Add module level docstring description

* Rearrange lib.sw order

* Use result type and add Sender type

* Improve function documentation

* refactor: improve clarity by removing the ! operator

* refactor: pass in constants to asm blocks

* fix: remove redundent `dep address;` from lib.sw

* fix: switch consts to enum

* refactor: revert to using constants for now but added TODO

* Minimal viable test harness for the stdlib (#37)

* config:update gitignore to ignore all tagket dirs

* feat:add working demo of test harness

* fix:add modules

* Add new demo_script_test project

* build:update dep versions in manifest files

* fix:update code in mod and main

* fix:change author email

* fixup

* fix:use local path to ttest current stdlib

* test:remove dummy test

* cleanup:remove dummy tests in prep for merge

* style:cargo fmt

* Porting token ops tests to the new stdlib test harness (#42)

* test:add token-ops tests

* test:update structure

* test:add more test

* test:adds more comments to failing tests

* test:remove failing tests from PR

* style:cargo fmt

* stle:forc fmt

* style:fix formatting I missed

* test:cleanup and remove logs

* bugfix: remove second register from gm opcode (#46)

* fix:remove second register from gm opcode

* docs:add link to gm opcode spec

* Add out directory to gitignore. (#50)

* Implement Square Root into the Standard Library (#49)

* Implement Square Root Function for uint types

* Update math.sw

* Update lib.sw

* Update math.sw

* Update math.sw

* Update math.sw

* Add Square Trait to uint

* Fix fmt

* Update math.sw

* Update math.sw

* Bump test dependencies. (#52)

* Bump test dependencies.

* Remove patch version.

* Use `t` instead of `T` for `Result` matches. (#53)

* Use t instead of T for Result matches.

* Update option.sw

* change author to authors in Forc.toml (#11)

* change author to authors in Forc.toml files (#56)

* switch from matches to if lets for enum destructuring (#62)

* switch from matches to if lets

* fmt

* Temporarily remove the Option and Result implementations (#63)

* fix:temp removal of result & option implementations

* fix:remove option & result from lib.sw

* fix:remove import of Result & change return type of msg_sender temporarily

* Fix return types of context::contract_id & context::msg_asset_id (#59)

* style:fix weird forc fmt issue

* fix:correct the return type for context module funcs

* test:add contract and json abi file

* test:add module to harness

* build:add manifest file

* test:add tests for context module

* style:forc fmt

* style:cargo fmt

* style:formatting

* fix:remove context test_project, coming in follow-up PR

* style:forc fmt

* Update token ops tests (#64)

* cleanup:remove duplicate abi

* build:update deps for sdk

* build:bump fuels-rs versions

* fix:remove salt field

* test:update to use newest syntax

* style:cargo fmt

* Adding a registers.sw module (#61)

* feat:add bare module registers

* feat:add registers.sw to expose16 reserved registers

* test:add new test project "registers"

* build:update forc manifest file

* test:add contract and abi.json

* test:add test file and empty tests

* test:temp disable ret & retl, add simple tests

* test:enable ret & retl again

* build:update manifest authors field

* build:remove redundant abi file

* fix:remove unneeded zero and one functions

* fix:remove zero and one funcs from abi and contract

* test:remove tests for zero and one & updates paths to abi file

* test:fix expected values and function calls

* style:forc fmt

* fix: add dep registers to context.sw

* style: forc fmt

* build:bump sdk version and add fuels-signers as a dep

* update tests to use new syntax

* style:cargo fmt & forc fmt

* Avoid implicit cast warning (#65)

* avoid implicit cast warning

* minor variable naming change

Co-authored-by: Mohammad <mohammad@Mohammads-MacBook-Pro.local>

* Fix test formatting. (#51)

* Ignore Forc lockfile (#69)

* Use new contract call syntax. (#70)

* Use new contract call syntax.

* Missed one

* Make core branch explicit (#71)

* Make core branch explicit

* Update Forc.toml

* fix:correct inline docs for registers.sw (#72)

* Fix some `path`s in the test project dependencies (#73)

The `path`s of dependencies should be point to the directory containing
the dependency's `Forc.toml` (not the `src`). This commit fixes the
`Forc.toml`s of the test projects to account for this.

There was also a spuriuos Forc.toml at `tests/Forc.toml` which has been
removed.

* Rename param in the ContractId::into() implementation (#76)

* fix:rename param

* docs:update comment and link tracking issue

* fixup

* Prefer `https` over `http` for forc git dependency URLs (#77)

This helps to resolve some dependency double-ups pending a proper
solution fix in `forc`.

See #931 and FuelLabs/fuels-rs#150 (comment)

* Add `out` and `Forc.lock` to gitignore (#13)

* Bump SDK version (#78)

* build:bump SDK and dep versions

* test;update tests to use new SDK version syntax

* style:cargo fmt

* build:add fule-vm as a dep

* test:add an is_within_range() function to avoid hardcoded vals

* style:cargo fmt

* Rename ETH_ID to NATIVE_ASSET_ID (#79)

* b256 -> contractId params for context functions which get balance from a contract (this or other) (#81)

* hotfix:complete param type changes (#82)

* Implement the `EQ` trait for `ContractId` (#83)

* feat:impl eq for ContractId

* test:add test project for contractId eq implementation

* test:wip on sscript test

* test:add script call draft

* test: finish script test

* test:finish test for contractId eq impl

* fix: remove comment

* style: cargo fmt

* build:remove core as unneeded dep

* Change `[project]` name from `lib-std` to `std` (#80)

See #977 for motivation.

* bump sdk to 0.7. Use test-helpers to cut down on boilerplate (#84)

* Cleanup stdlib tests (#85)

* cleanup: remove compiler warnings

* style: cargo fmt

* Adding a call_frames module (#66)

* test:add new test project call_frames

* test:add bare call_frames module

* feat:add initial call_frames.sw module

* feat:add new call frame access constants

* feat:add call_frames.sw and refactor context mod

* fix:reorder lib.sw

* style:cleanup comments'

* style:forc fmt

* refactor:reorganize functions by module and expose under context namespace

* cleanup:remove unneeded files from test project

* test:add initial draft test

* test:add first test

* temp:remove use of constants

* test:setup test project and artifact for call_frames

* test:outline primary tests

* test:fix test assertions

* cleanup:remove helper functions from call_frames until they can be tested

* style:cargo fmt & forc fmt

* test:cleanup forc tomls

* test:use new contract call syntax

* fix:update return types for call_frames functions

* test:update to SDK v 0.6

* test:update tests

* style: cargo fmt

* fix:rename var to satisfy compiler

* style: forc fmt

* cleanup: remove unused CONSTs until needed

* build: remove core as a dep

* Disable default features from fuel-core (#86)

* Implement Eq for bool (#14)

* Re-add Option and Result. (#68)

* Re-add Option and Result.

* Re-add to auth.

* fmt

* Fix option and result, and add tests.

* Remove redundant gitignores.

* Fix tests.

* Fix to actually compile.

* Fix function naming.

* Fix test.

* Add missing semicolon.

* move option dep up

* Add `Result.unwrap()` (#90)

* Refactor panic into separate library.

* Update tests to use new panic.

* Implement unwrap.

* Add test.

* Add Option.unwrap() (#91)

* Bump fuels-rs to v0.8 (#92)

* Refactor the context module & port tests to SDK (#89)

* test:add new context test project

* test:add context module to harness

* test:add context testing contract and abi

* test:add context_testing_abi

* test:add the first tests

* test:fix contract path

* refactor:context.sw balance functions now use a common balance func

* test:add context_caller_contract to test_artifacts

* temp:ignore failing tests

* reorg:remove tests which belong elsewhere

* build:fix manifest fields

* test:add get_global_gas to context contract

* test:update context_testing_abi

* test:update context_caller abi & contract

* test:add and fix tests for context

* fix:fix types in context module

* build:cleanup/fix forc toml files

* test:cleanup types & contract calls

* build:update deps in cargo toml

* fix:update types in token_ops

* test:update to new sdk version

* test:update import paths to use .bin files

* test:update more tests to use new build path and comparison values

* test:cleanup

* fix:update contract call in caller contract

* test:fix test call to use correct contract

* build: bump SDK to 7

* style: forc fmt

* style: forc fmt

* test: refactor & bump to SDK 7

* style: cargo fmt

* test: update SDK usage to use latest features

* test:work on fixing tests

* improvement: rename contract_id to target

* fix: rename balance() and refactor imports

* style: use multi import syntax

* test: refactor test helper funcs

* test: fix function call names

* refactor: rename functions for clarity

* test: remove use of helper funcs bc/ContractNotFound

* style: cargo fmt

* fix: add gas param to all inter-contract calls

* test: refactor helper to share provider

* fix: update abis and contracts

* test: fix balance test

* fix: remove minting from contract functions

* test: add minting step to tests

* test: cleanup tests

* test: get all tests passing

* test:remove failing duplicate test

* style: cargo fmt && forc fmt

* build: remove core as a dep

* refactor: balance reg & balance_of funcs

* fix: update function names in contracts

* style: forc fmt

* test: fix tests by removing call_params

* style: cargo fmt

* cleanup: remove all compiler warnings

* Walk git dependency repo to discover nested forc dependencies

Closes #952.

This should be complete for the most part, though depends on implementing #977 first.

* Remove implied pkg from names of pkg discovery fns

* Update `Cargo.lock` for the addition of `walkdir`

`walkdir` is used to traverse the git repository when searching for
dependency packages.

* Change `std`'s `core` dep to use the local path

Yet to test whether `forc` can handle `path` dependencies within
dependencies. In theory I these should work provided that the `path` is
relative and points to a location within the same git repository. If
this *does* work, the behaviour should be discussed, documented and
enforced by `forc`.

* Update examples `std` dependency declarations to use local `path`

* Update all tests to depend on `std` via local `path`

This should assist in ensuring that all tests must always pass for any
change to `sway`, `lib-core`, `lib-std` or `forc`.

* Build sway-lib-core and sway-lib-std under unique CI jobs

* Add successful `sway-lib-core` and `sway-lib-std` reqs for publish

* Add tx module. (#93)

* Add tx module.

* Add functions.

* Clean up.

* Add skeleton test artifact project.

* Use hard-coded constants since compiler can't handle consts.

* Fill in skeleton.

* Make untested get typed script data non-pub.

* Add output functions.

* Comment out unreachable.

* Improve name.

* Add remaining functions.

* Fix name.

* Register tests to harness.

* Add tests.

* Fix script start offset test.

* Fix script start offset get.

* Fix test with todo.

* Add non-working test for input coin owner.

* Return wallet.

* Fix test.

* Update transfer to output (#94)

* fixing transfer_to_output

* Update transfer_to_output

* Improving a comment

* fmt

* Auth method 3 (#54)

* Add changes from prior work

* Remove import of ops

* Cleanup and format

* Rename functions to match opcode naming

* Re-order lib.sw

* Fix types to use ContractId

* Refactor and cleanup

* Reorder lib.sw

* Clean up comments and types

* FIx lib deps ordering

* cleanup

* congig:update gitignore

* Commit stashed changes with get_coin_owner WIP

* Fix:cleanup merge conflict resolution mistake

* Clean up a bit and use Result.

* General cleanup.

* Improve comment.

* Fix a bunch of type errors.

* Add missed assert.

* Fix order to make compile.

* Refactor.

* fix

* Fix build errors.

* Update offsets for 255 max inputs.

* Remove warnings.

* Improve error name.

* Fix some asm.

* Fix more asm

* space

* Fix comment

* Fix offsets.

* Refactor to use new tx module.

* test: add auth test project

* test: register auth tests

* test: add tests to mod.rs

* test: add auth testing abi & contract

* test: add auth caller contract & script

* test: fix enum variant name

* test: fix import of result

* test: refactor types to workaround MissingData error from SDK

* test: fix number of args passed

* test: ignore script test

* style: forc fmt

* style: cargo fmt

* test: work on script test

* Remove redundant assert.

* Clean up tests, not working yet.

* Fix test for some reason.

* Fix test.

Co-authored-by: Nick Furfaro <nfurfaro33@gmail.com>

* Update path to assert (#97)

* test: update path to assert

* Delete build.sh

Added by accident.

* test: remove redundant test (#99)

* Update examples and tests for chain::assert -> assert::assert

* Update newly merged test for chain::assert -> assert::assert

Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: ControlCplusControlV <44706811+ControlCplusControlV@users.noreply.github.com>
Co-authored-by: wolflo <33909953+wolflo@users.noreply.github.com>
Co-authored-by: Nick Furfaro <nfurfaro33@gmail.com>
Co-authored-by: Toby Hutton <toby@grusly.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Mohammad <mohammad@Mohammads-MacBook-Pro.local>
Co-authored-by: Simon Roberts <46566889+simonr0204@users.noreply.github.com>
Co-authored-by: Brandon Kite <brandonkite92@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
Archived in project
Development

No branches or pull requests

3 participants