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

Add initial transaction format #6

Merged
merged 3 commits into from
Nov 27, 2020
Merged

Conversation

adlerjohn
Copy link
Contributor

@adlerjohn adlerjohn commented Nov 26, 2020

There are a few minor additions/changes we'd like to see to the format proposed here, reserved for future work:

  1. A new output type for conditional contract creation. Depending on the execution, a contract may or may not be created, with different parameters.
  2. A change output type with witness-based amount.

@adlerjohn adlerjohn added the enhancement New feature or request label Nov 26, 2020
@adlerjohn adlerjohn self-assigned this Nov 26, 2020
shahankhatch added a commit to FuelLabs/fuel-core that referenced this pull request Nov 26, 2020
@adlerjohn adlerjohn marked this pull request as ready for review November 27, 2020 18:12
@adlerjohn adlerjohn merged commit e9ade96 into master Nov 27, 2020
@adlerjohn adlerjohn deleted the adlerjohn-initial_tx_format branch November 27, 2020 18:15
@adlerjohn adlerjohn added the comp:FVM Component: FuelVM label Feb 18, 2021
vlopes11 pushed a commit to FuelLabs/fuel-vm that referenced this pull request Jun 3, 2021
vlopes11 added a commit to FuelLabs/fuel-vm that referenced this pull request Jun 3, 2021
* Initial commit

* Update README.md

* Fuel VM in Rust

merging files from original repo

refactor

impl ethcall

completed todos

refactor program into interpreter mod

carry create2 programs through callframes

impl create2

impl codesize based on callframes

impl fuel tx init and data handling

refactor

update init code width

impl eth ops

impl fuel ops

define eth and fuel ops

Adding init field to eth tx format

define eth account and tx types

impl rotate ops

sign extend from u16 to u64

impl subi op

Sign extend imm val for arithmetic op

fix and style

impl of srav and sra

impl of sltiu and sltu

remove unnecessary refs

working tx handler

define op for data ld and test for tx exec

first step of tx execution impl

impl addtl tx types

minor refactor

initial tx format

moving from usize to u8 for size types

defining serder of eth opcodes

advancing notes

updating notes

cleaner style

base impl for all opcodes

implement malloc/free, local var, and stack opcodes

working call and return architecture

improving architecture and execution

some code improvements

improved stack handling thru mutable references

intermediate commit with some types and methods and cleanup

intermediate commit for stackframes

initial stack impl

using values in registers for computations

Run programs in loop to completion

Update notes

Adding tests for u32 bit manipulation

Change opcode instructions to 32 bits wide

change immediate values to 16-bit wide

minor edits

tidy

completing a few opcode implementations including beq

bug fix for tuple return

Starting to implement opcodes

intermediate commit with opcode deser

intermediate commit with opcode ser

Update status

Adding simple unit tests to memory after execution

Working simple execution with memory dump

Removing unused const

updating notes

updating notes

refactor u64 funcs to file

applying unit tests to serder

initial working serder of ADD opcode in program

AND serialization and refactoring

minor cleanup

Adding some indexed methods

Initial bit manipulation for opcode ser

Intermediate commit to opcode serder

Starting trait impl for Opcodes

Implement bit manipulation for u64

Enable basic architecture for tests

intermediate commit with restructured types for vm components

Working memory with hi register

splitting out base types

adding binary that matches Cargo.toml

adding binary that matches Cargo.toml

running instance, more cleanup pending

next step towards initial commit

next step towards initial commit

Fuel VM in Rust

* Adding new tx format based on FuelLabs/fuel-specs#6

* lifting utxo_id into parent struct

* working base ftx test

* working new tx format

* Adding `stateWitnessIndex` to OutputContract

* Working extended Fuel tx contract subtype

* impl sha256

Set $of flag in div and mod by 0

Rename of uf flags

Rename of uf flags

j jr tests

xor xori tests

sub subi tests

sll sllv srl srlv tests

or ori tests

mult multi test

updates to match spec #0d39f49

impl kecakk op

Add convenience functions

* jump ops

memory copy and compare ops

impl state opcodes using hashmap

refactor overflow into distinct register

impl sha256

Set $of flag in div and mod by 0

Rename of uf flags

Rename of uf flags

j jr tests

xor xori tests

sub subi tests

sll sllv srl srlv tests

or ori tests

mult multi test

updates to match spec #0d39f49

impl kecakk op

Add convenience functions

* cleanup

jnzi test

jnz test

jump ops

memory copy and compare ops

impl state opcodes using hashmap

refactor overflow into distinct register

impl sha256

Set $of flag in div and mod by 0

Rename of uf flags

Rename of uf flags

j jr tests

xor xori tests

sub subi tests

sll sllv srl srlv tests

or ori tests

mult multi test

updates to match spec #0d39f49

impl kecakk op

Add convenience functions

* slight adjustment to hashmap access

* added very basic gas

* ecrecover op

* Cfe and Cfs callframe stack opcodes

* Add test and format CI (#12)

* Add test and format CI.

* fmt

* Remove test suite unneeded.

* Update test CI (#13)

* Add private keys for dependencies.

* Use minimal toolchain profile.

* Use nightly toolchain.

* Update opcodes list (#9)

* Update opcodes list

The opcodes list was outdated and needed to be resync with the specs.

https:/FuelLabs/fuel-specs/blob/master/specs/vm/opcodes.md

Also, the previous implementation didn't consider the different sizes of
immediate values, treating everything as u16.

The API still need to improve to prevent users from allocating invalid
register values with overflow.

Resolves #8

* Update interpreter to latest specs

The interpreter is not fully sync with the specs.

Also, the functionality scope can be split into different modules to
facilitate maintenance of the routines.

* Implement interpreter mem and crypto functions

Some of the functions contains particularities such as the ecrecover
that uses a special encoding regarding the recovery id. These are not
native to the public libraries and must be manually handled.

* Add test case for keccak256

This new test case is symmetric to the sha256 test case with the crypto
primitive as difference.

* Add Transaction structure

The transaction will define the VM initialization as well as the
underlying input/output/contract types.

* Implement recoverable secp256k1 signature

The EcRecover scheme may benefit from a compression that can save an
additional byte of storage.

This crypto primitive is implemented using rusk-secp256k1 as backend.

* Add MemClearI operation

* Rename 32-byte storage ops to "quad word"

* Rename opcodes to fit in 4 chars

* Add serialization for all tx types

* Change VM init to copy tx to stack

The initialization of the VM should copy the hash of the transaction,
its size and the serialized bytes to the stack area so the execution of
the program can access it when required.

* Update IO according to specs

The specs points that every number should be stored as u64 and the
arrays of bytes should be padded to multiples of 8.

* Change `crypto::hash` to encapsulate primitive

The underlying default hash function of the crypto module should not
impact the API and any change in the primitive should be transparent to
the users of the interpreter.

* Add Log opcode

This opcode will perform a naive dump of the selected registers ignoring
the zeroed indices.

This is a primitive implementation to a more complex log/event/topic
tracing system.

* Add binary interpreter

This binary executes transactions and output the log opcodes.

* Add tracing to interpreter execution

* Add debug to registers

The mutated registers should be print if the log level is set to debug.

* Update memcopy to non-overlapping

THe `MCP` operation should fail if the memory segments are overlapping.

This will allow the internals to benefit from `memcopy` instead of
`memmove`.

* Add `is_valid` function for all transaction types

* Add Tx validation to VM initialization

The VM initialization must validate the transaction before the registers
and memory are prepared for execution.

The TX validation is critical and most of the edge cases must have test
coverage.

* Optimize code and remove redundant checks

* Add Call, CallFrame and MemoryRange

The memory range tuples in the VM are expected to behave as start/size
pairs. However, Rust uses start/end patterns. The `MemoryRange` type is
an abstraction to interface with the values provided by the bytecode
operations and Rust memory scheme.

The `Call` and `CallFrame` structures will heavily depend on that
because they have internal references to owned memory regions.

* Add Call opcode implementation

The call frames structure and the reflection of a call in the registers
and memory is critical to the system and must be broadly tested.

This commit introduces the update of the program counter.

* Update dependencies to use fuel-* libs

The transaction and opcode structs were split into their own libraries.

This commit introduces the usage of these libraries as dependencies.

* Update ECR to clear err

In case of failure, ECRecover should set the recovered public-key to
`0` and turn the `err` flag on.

In case of success, `$rA` will be set with the recovered public-key and
the error flag will be cleared.

* Add predicate verification for tx create coin

* Add predicate verification

Predicate verification should initialize the VM in a special state and
execute the opcodes under special constraints defined in the specs.

* Remove Travis config. (#14)

* Add helper methods for VM executors (#17)

* Change LW and SW to multiple of a Word immediate (#16)

To maintain consistency with the high-level language, the LW and SW
immediate values will be used as word-multiple values instead of raw
memory addresses.

* Mint and burn (#18)

* Add CALL and CCP implementation

Both call and ccp relies on contract deployment over the blockchain.
These should be included with a refactor over the call frames structure
to correctly point to a contract code after a call frame is pushed to
the stack.

* Fix memory boundaries ownership check

The memory ranges are exclusive in the upper bound. This way, the
ownership check must reflect that standard for range checks.

* Add Mint and Burn opcode execution

* Update SW and LW to take imm as words

* Update LW and SW to mul word imm with explicit op

* Add function to encapsulate external const check

* Rename crate to `fuel-core` (#19)

`fuel-vm-rust` don't reflect the repo name and this may be confusing
under certain contexts. Also, there is no particular reason on why these
two names should diverge.

* Add data backend traits

The VM must be agnostic to the data backend, and this should comply only
with a non-restrictive trait.

This commit introduces the `Storage` trait. Some of the interpreter
functionality will specify implementation requirements for a given
Key/Value concrete pair.

* Use wrapper type for key structs

* Rename to fuel-vm

Co-authored-by: John Adler <[email protected]>
Co-authored-by: Shahan Khatchadourian <[email protected]>
goldenpath1109 added a commit to goldenpath1109/fuel-core that referenced this pull request Sep 7, 2024
crypto523 added a commit to crypto523/fuel-core that referenced this pull request Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:FVM Component: FuelVM enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants