Add CREATE, CLONE and BYTECODE_HASH opcodes. Add bytecode typerep and datatype #211

Merged
zxq9 merged 5 commits from factories into master 2021-03-31 16:45:57 +09:00
zxq9 commented 2021-03-10 21:33:58 +09:00 (Migrated from gitlab.com)

Created by: radrow

cc @gorbak25 @hanssv

There are 2 main points of this PR:

New opcodes

I am adding 4 new opcodes to the FATE assembly language: CREATE, CLONE, CLONE_G and BYTECODE_HASH. The gas prices are to be discussed.

CREATE

This dude is supposed to deploy a new contract from given serialized code of the new fate_code datatype. It also takes initial call value and type representation of init arguments. The args for init will be placed on stack. The return type is contract. The result is put on the stack as this instruction ends with a jump.

One of the key things is to make it expensive compared to other instructions in order to prevent "create spam". I was even thinking of increasing the price geometrically of this opcode for a single execution.

CLONE

Similar to CREATE but uses code of an existing contract by its address. Should be significantly cheaper though as it would make bytecode reuse easier. Can be protected similarly to a remote call. The result is put on the stack as this instruction ends with a jump.

CLONE_G

Essentially CLONE but takes additional parameter that limits gas for init execution.

BYTECODE_HASH

Will be used in validation. Takes a contract and returns hash of its bytecode. Wraps the result in Some or returns None on fail. The result is put on the first argument to the opcode.

New data

This PR adds new boxed datatype contract_bytearray along with its typerep. It wraps up a binary representing serialized FATE code. It is already used in create TX, just making it a valid value in FATE.

Misc

I have changed BLOCKHASH to return variant as this is actually true.

I have added our version of rebar3 because the previously used one was doing some strange shit with the opcode generator

*Created by: radrow* cc @gorbak25 @hanssv There are 2 main points of this PR: ## New opcodes I am adding 4 new opcodes to the FATE assembly language: `CREATE`, `CLONE`, `CLONE_G` and `BYTECODE_HASH`. The gas prices are to be discussed. ### `CREATE` This dude is supposed to deploy a new contract from given **serialized code** of the new `fate_code` datatype. It also takes initial call value and type representation of `init` arguments. The args for `init` will be placed on stack. The return type is `contract`. The result is put on the `stack` as this instruction ends with a jump. One of the key things is to make it expensive compared to other instructions in order to prevent "create spam". I was even thinking of increasing the price geometrically of this opcode for a single execution. ### `CLONE` Similar to `CREATE` but uses code of an existing contract by its address. Should be significantly cheaper though as it would make bytecode reuse easier. Can be protected similarly to a remote call. The result is put on the `stack` as this instruction ends with a jump. ### `CLONE_G` Essentially `CLONE` but takes additional parameter that limits gas for `init` execution. ### `BYTECODE_HASH` Will be used in validation. Takes a contract and returns hash of its **bytecode**. Wraps the result in `Some` or returns `None` on fail. The result is put on the first argument to the opcode. ## New data This PR adds new boxed datatype `contract_bytearray` along with its typerep. It wraps up a binary representing serialized FATE code. It is already used in create TX, just making it a valid value in FATE. ## Misc I have changed `BLOCKHASH` to return `variant` as this is actually true. I have added our version of `rebar3` because the previously used one was doing some strange shit with the opcode generator
gorbak25 (Migrated from gitlab.com) approved these changes 2021-03-10 21:33:58 +09:00
zxq9 commented 2021-03-25 22:44:29 +09:00 (Migrated from gitlab.com)

Created by: cytadela8

Review: Approved

*Created by: cytadela8* **Review:** Approved
gorbak25 commented 2021-03-31 16:44:56 +09:00 (Migrated from gitlab.com)

approved this merge request

approved this merge request
zxq9 commented 2021-03-31 16:45:57 +09:00 (Migrated from gitlab.com)

Merged by: radrow at 2021-03-31 07:45:57 UTC

*Merged by: radrow at 2021-03-31 07:45:57 UTC*
Sign in to join this conversation.
No description provided.