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

Implement OVM backend #2416

Merged
merged 10 commits into from
Aug 25, 2021
Merged

Implement OVM backend #2416

merged 10 commits into from
Aug 25, 2021

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Aug 13, 2021

What I did

Implement #2171. It can be used with any evm version by adding the --ovm flag on the command line. I only added the option to the CLI for now.

How I did it

Replace opcodes which need to call into the OVM execution manager with a jump to a newly created ovm subroutine section. For instance, sstore(x, y) turns into _sstore_exit_1 x y jump(ovm_sstore) (label _sstore_exit_1). ovm_sstore calls the execution manager ovmSSTORE(x, y) and then jumps back to _sstore_exit_1. I did this to minimize the bloat to the generated code - each OVM instruction gets about 7 bytes of overhead in the bytecode instead of inlining the whole procedure to call ovmSSTORE (which takes about a gajillion instructions), which is appended at the end as a code block shared between every invocation of sstore. For more details see the explanation in vyper/ovm/spec.py

How to verify it

Compile a couple simple contracts.

$ vyper --ovm -f ir /dev/stdin <<EOF
> foo: public(int256)
> 
> @internal
> def bar() -> int256:
>     return self.foo
> EOF
[seq,
  [seq,
    [return,
      0,
      [lll,
        [seq,
          [seq,
            [if, [lt, calldatasize, 4], [goto, fallback]],
            [mstore, 28, [calldataload, 0]],
            [with,
              _func_sig,
              [mload, 0],
              [seq,
                [assert, [iszero, [seq_unchecked, _sym_callvalue1, [goto, _ovm_callvalue], [label, callvalue1]]]],
                [if,
                  [eq, _func_sig, 3264763256],
                  [seq,
                    pass,
                    pass,
                    [mstore,
                      0,
                      [seq_unchecked, _sym_sload1, 0, [goto, _ovm_sload], [label, sload1]]],
                    [seq_unchecked, pass, [return, 0, 32]],
                    pass,
                    stop]]]],
            [seq_unchecked,
              [label, fallback],
              [seq_unchecked, _sym_revert1, 0, 0, [goto, _ovm_revert], [label, revert1]]],
            [label, priv_4273672062],
            pass,
            [mstore, 320, pass],
            pass,
            [mstore,
              0,
              [seq_unchecked, _sym_sload2, 0, [goto, _ovm_sload], [label, sload2]]],
            [seq_unchecked, [mload, 0], pass, [jump, [mload, 320]]],
            pass,
            stop],
          [label, _ovm_callvalue],
          [seq_unchecked,
            [with,
              buf,
              msize,
              [seq_unchecked,
                [mstore, buf, 2831468012],
                seq,
                pass,
                [ovm_exec, [add, 28, buf], 4, buf, 32],
                pass,
                [seq_unchecked, [mload, [add, buf, 0]]],
                [calldatacopy, buf, calldatasize, [sub, msize, buf]]]],
            [swap1, pass, pass],
            [jump, pass]],
          [label, _ovm_sload],
          [seq_unchecked,
            [with,
              key,
              pass,
              [with,
                buf,
                msize,
                [seq_unchecked,
                  [mstore, buf, 546726408],
                  seq,
                  pass,
                  [ovm_exec, [add, 28, buf], 36, buf, 32],
                  pass,
                  [seq_unchecked, [mload, [add, buf, 0]]],
                  [calldatacopy, buf, calldatasize, [sub, msize, buf]]]]],
            [swap1, pass, pass],
            [jump, pass]],
          [label, _ovm_revert],
          [seq_unchecked,
            [with,
              reason_ofst,
              pass,
              [with,
                reason_len,
                pass,
                [with,
                  buf,
                  msize,
                  [seq_unchecked,
                    [mstore, buf, 707427035],
                    [seq, [mstore, [add, buf, 32], 32]],
                    [seq,
                      [mstore, [add, 64, buf], [add, 68, reason_len]],
                      [ovm_copy, reason_ofst, reason_len, [add, buf, 68], reason_len]],
                    [ovm_exec, [add, 28, buf], [add, 68, reason_len], buf, 0],
                    pass,
                    seq_unchecked,
                    [calldatacopy, buf, calldatasize, [sub, msize, buf]]]]]],
            [jump, pass]]],
        [seq, 0]]]]]
(vyper) charles@cmc-thinkpad ~/vyper $ vyper --ovm -f ir /dev/stdin <<EOF
> interface Foo:
>     def foo(x: Bytes[32]) -> (Bytes[64], int256): view
> 
> @external
> def call_foo():
>     Foo(msg.sender).foo(slice(msg.data, 0, 32))
> EOF
[seq,
  [seq,
    [return,
      0,
      [lll,
        [seq,
          [seq,
            [if, [lt, calldatasize, 4], [goto, fallback]],
            [mstore, 28, [calldataload, 0]],
            [with,
              _func_sig,
              [mload, 0],
              [seq,
                [assert, [iszero, [seq_unchecked, _sym_callvalue1, [goto, _ovm_callvalue], [label, callvalue1]]]],
                [if,
                  [eq, _func_sig, 1309411251],
                  [seq,
                    pass,
                    pass,
                    [assert,
                      [seq_unchecked,
                        _sym_staticcall1,
                        160,
                        800,
                        100,
                        [with,
                          _poz,
                          32,
                          [seq,
                            [mstore, 608, 818467290],
                            [mstore, 640, _poz],
                            [with,
                              _s,
                              [with,
                                _start,
                                0,
                                [with,
                                  _length,
                                  32,
                                  [with,
                                    _opos,
                                    [add, 448, [mod, _start, 32]],
                                    [seq,
                                      [assert,
                                        [le,
                                          [add, _start, _length],
                                          [mload,
                                            [seq,
                                              [assert, [le, 32, calldatasize]],
                                              [mstore, 320, 32],
                                              [calldatacopy, 352, 0, 32],
                                              320]]]],
                                      [with,
                                        _l,
                                        64,
                                        [pop,
                                          [seq_unchecked,
                                            _sym_call1,
                                            _l,
                                            480,
                                            _l,
                                            [add,
                                              [seq,
                                                [assert, [le, 32, calldatasize]],
                                                [mstore, 320, 32],
                                                [calldatacopy, 352, 0, 32],
                                                320],
                                              [add, [sub, _start, [mod, _start, 32]], 32]],
                                            0,
                                            4,
                                            gas,
                                            [goto, _ovm_call],
                                            [label, call1]]]],
                                      [mstore, _opos, _length],
                                      _opos]]]],
                              [seq,
                                [with,
                                  _source,
                                  _s,
                                  [with,
                                    _sz,
                                    [add, 32, [mload, _source]],
                                    [assert,
                                      [seq_unchecked,
                                        _sym_call2,
                                        _sz,
                                        [add, 640, _poz],
                                        _sz,
                                        _source,
                                        0,
                                        4,
                                        gas,
                                        [goto, _ovm_call],
                                        [label, call2]]]]],
                                pass]],
                            636]],
                        caller,
                        gas,
                        [goto, _ovm_staticcall],
                        [label, staticcall1]]],
                    [assert, [gt, returndatasize, 95]],
                    [assert, [lt, [mload, [add, [mload, 800], 800]], 65]],
                    [with,
                      src,
                      800,
                      [with,
                        src_loc,
                        src,
                        [seq,
                          [with,
                            src,
                            [add, src, [mload, src_loc]],
                            [with,
                              src_loc,
                              src,
                              [seq,
                                [with,
                                  _source,
                                  src_loc,
                                  [with,
                                    _sz,
                                    [add, 32, [mload, _source]],
                                    [assert,
                                      [seq_unchecked,
                                        _sym_call3,
                                        _sz,
                                        960,
                                        _sz,
                                        _source,
                                        0,
                                        4,
                                        gas,
                                        [goto, _ovm_call],
                                        [label, call3]]]]]]]],
                          [set, src_loc, [add, src_loc, 32]],
                          [with,
                            src,
                            src_loc,
                            [with, src_loc, src, [seq, [mstore, 1088, [mload, src_loc]]]]]]]],
                    0,
                    960,
                    pass,
                    stop]]]],
            [seq_unchecked,
              [label, fallback],
              [seq_unchecked, _sym_revert1, 0, 0, [goto, _ovm_revert], [label, revert1]]]],
          [label, _ovm_callvalue],
          [seq_unchecked,
            [with,
              buf,
              msize,
              [seq_unchecked,
                [mstore, buf, 2831468012],
                seq,
                pass,
                [ovm_exec, [add, 28, buf], 4, buf, 32],
                pass,
                [seq_unchecked, [mload, [add, buf, 0]]],
                [calldatacopy, buf, calldatasize, [sub, msize, buf]]]],
            [swap1, pass, pass],
            [jump, pass]],
          [label, _ovm_call],
          [seq_unchecked,
            [with,
              gas,
              pass,
              [with,
                addr,
                pass,
                [with,
                  value,
                  pass,
                  [with,
                    args_ofst,
                    pass,
                    [with,
                      args_len,
                      pass,
                      [with,
                        ret_ofst,
                        pass,
                        [with,
                          ret_len,
                          pass,
                          [with,
                            buf,
                            msize,
                            [seq_unchecked,
                              [mstore, buf, 1536807365],
                              [seq,
                                [mstore, [add, buf, 32], gas],
                                [mstore, [add, buf, 64], addr],
                                [mstore, [add, buf, 96], value],
                                [mstore, [add, buf, 128], 128]],
                              [seq,
                                [mstore, [add, 160, buf], [add, 164, args_len]],
                                [ovm_copy, args_ofst, args_len, [add, buf, 164], args_len]],
                              [ovm_exec, [add, 28, buf], [add, 164, args_len], buf, [add, 96, ret_len]],
                              [ovm_copy, buf, [sub, returndatasize, 96], ret_ofst, ret_len],
                              [seq_unchecked, [mload, [add, buf, 0]]],
                              pass]]]]]]]]],
            [swap1, pass, pass],
            [jump, pass]],
          [label, _ovm_staticcall],
          [seq_unchecked,
            [with,
              gas,
              pass,
              [with,
                addr,
                pass,
                [with,
                  args_ofst,
                  pass,
                  [with,
                    args_len,
                    pass,
                    [with,
                      ret_ofst,
                      pass,
                      [with,
                        ret_len,
                        pass,
                        [with,
                          buf,
                          msize,
                          [seq_unchecked,
                            [mstore, buf, 2619552176],
                            [seq,
                              [mstore, [add, buf, 32], gas],
                              [mstore, [add, buf, 64], addr],
                              [mstore, [add, buf, 96], 96]],
                            [seq,
                              [mstore, [add, 128, buf], [add, 132, args_len]],
                              [ovm_copy, args_ofst, args_len, [add, buf, 132], args_len]],
                            [ovm_exec, [add, 28, buf], [add, 132, args_len], buf, [add, 96, ret_len]],
                            [ovm_copy, buf, [sub, returndatasize, 96], ret_ofst, ret_len],
                            [seq_unchecked, [mload, [add, buf, 0]]],
                            pass]]]]]]]],
            [swap1, pass, pass],
            [jump, pass]],
          [label, _ovm_revert],
          [seq_unchecked,
            [with,
              reason_ofst,
              pass,
              [with,
                reason_len,
                pass,
                [with,
                  buf,
                  msize,
                  [seq_unchecked,
                    [mstore, buf, 707427035],
                    [seq, [mstore, [add, buf, 32], 32]],
                    [seq,
                      [mstore, [add, 64, buf], [add, 68, reason_len]],
                      [ovm_copy, reason_ofst, reason_len, [add, buf, 68], reason_len]],
                    [ovm_exec, [add, 28, buf], [add, 68, reason_len], buf, 0],
                    pass,
                    seq_unchecked,
                    [calldatacopy, buf, calldatasize, [sub, msize, buf]]]]]],
            [jump, pass]]],
        [seq, 0]]]]]

Description for the changelog

Add experimental OVM backend

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@codecov-commenter
Copy link

codecov-commenter commented Aug 13, 2021

Codecov Report

Merging #2416 (4208a2e) into master (d6e3997) will decrease coverage by 0.87%.
The diff coverage is 63.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2416      +/-   ##
==========================================
- Coverage   85.49%   84.62%   -0.88%     
==========================================
  Files          91       94       +3     
  Lines        9059     9423     +364     
  Branches     2158     2205      +47     
==========================================
+ Hits         7745     7974     +229     
- Misses        809      939     +130     
- Partials      505      510       +5     
Impacted Files Coverage Δ
vyper/compiler/phases.py 87.25% <50.00%> (-7.26%) ⬇️
vyper/utils.py 85.29% <50.00%> (+0.96%) ⬆️
vyper/ovm/asm.py 56.52% <56.52%> (ø)
vyper/ovm/spec.py 63.97% <63.97%> (ø)
vyper/lll/compile_lll.py 93.42% <71.42%> (-0.48%) ⬇️
vyper/cli/vyper_compile.py 75.22% <100.00%> (+0.22%) ⬆️
vyper/compiler/__init__.py 85.71% <100.00%> (ø)
vyper/ovm/__init__.py 100.00% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d6e3997...4208a2e. Read the comment docs.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Aug 13, 2021

This pull request introduces 5 alerts when merging e0fb487 into 31dd776 - view on LGTM.com

new alerts:

  • 3 for Wrong number of arguments in a call
  • 1 for Suspicious unused loop iteration variable
  • 1 for Variable defined multiple times

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Aug 13, 2021

This pull request introduces 2 alerts when merging 82bda5c into 31dd776 - view on LGTM.com

new alerts:

  • 1 for Variable defined multiple times
  • 1 for Wrong number of arguments in a call

@charles-cooper
Copy link
Member Author

This produces bytecode now. I'm going to clean up the commit history and then it should be more or less ready for review

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Aug 13, 2021

This pull request introduces 2 alerts when merging a92bc51 into 31dd776 - view on LGTM.com

new alerts:

  • 1 for Variable defined multiple times
  • 1 for Wrong number of arguments in a call

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Aug 14, 2021

This pull request introduces 2 alerts when merging 7b32577 into 31dd776 - view on LGTM.com

new alerts:

  • 1 for Variable defined multiple times
  • 1 for Wrong number of arguments in a call

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Aug 14, 2021

This pull request introduces 2 alerts when merging e296ae6 into 31dd776 - view on LGTM.com

new alerts:

  • 1 for Variable defined multiple times
  • 1 for Wrong number of arguments in a call

@charles-cooper
Copy link
Member Author

charles-cooper commented Aug 14, 2021

I manually went through an example "subroutine" to make sure the stack behaves as expected

(seq
 (label _ovm_sload)
 (seq_unchecked
  (with
   key
   pass
   (with
    buf
    msize
    (seq_unchecked
     (mstore buf 2180116536)
     (seq (mstore (add buf 32) key))
     pass
     ; omitted for brevity: (ovm_exec (add 28 buf) 36 buf 32)
     pass
     (seq_unchecked (mload (add buf 0))) ; load output to stack
      (calldatacopy buf calldatasize (sub msize buf)))))
      (swap1 pass pass) ; swap output with return_pc
      (jump pass)) ; consume return_pc, jump, stack now just has output
 )

emits the following (generated by vyper-lll and hand annotated by me)

_sym__ovm_sload 
JUMPDEST 
# subroutine entry point
# STACK: return_pc, key (input)
MSIZE                 # return_pc, key, buf
PUSH4 129 241 240 56  # return_pc, key, buf, method_id
DUP2                  # return_pc, key, buf, method_id, buf
MSTORE                # return_pc, key, buf
DUP2                  # return_pc, key, buf, key
PUSH1 32              # return_pc, key, buf, key, 32
DUP3                  # return_pc, key, buf, key, 32, buf
ADD                   # return_pc, key, buf, key, buf+32
MSTORE                # return_pc, key, buf
# OVM_EXEC string
PUSH1 0               # return_pc, key, buf, 0
DUP2                  # return_pc, key, buf, 0, buf
ADD                   # return_pc, key, buf, buf
MLOAD                 # return_pc, key, buf, value
DUP2                  # return_pc, key, buf, value, buf
MSIZE                 # return_pc, key, buf, value, buf, new_mem
SUB                   # return_pc, key, buf, value, new_mem - buf
CALLDATASIZE          # return_pc, key, buf, value, new_mem - buf, calldatasize
DUP4                  # return_pc, key, buf, value, new_mem - buf, calldatasize, buf
CALLDATACOPY          # return_pc, key, buf, value
SWAP1                 # return_pc, key, value, buf
POP                   # return_pc, key, value
SWAP1                 # return_pc, value, key
POP                   # return_pc, value
SWAP1                 # value, return_pc
JUMP                  # value

vyper/compiler/__init__.py Outdated Show resolved Hide resolved

if use_ovm:
for opcodes_for_evm_version in evm._evm_opcodes.values():
ovm.monkey_patch_evm_opcodes(opcodes_for_evm_version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ovm.monkey_patch_evm_opcodes(opcodes_for_evm_version)
ovm.monkeypatch_evm_opcodes(opcodes_for_evm_version)

Comment on lines +59 to +65
_revert0_string = ["_sym_revert0", "JUMPDEST", "PUSH1", 0, "DUP1", "REVERT"]
if use_ovm:
_revert0_string = ["_sym_revert0", "JUMPDEST", "PUSH1", 0, "DUP1"] + [
"_sym_ovm_revert",
"JUMP",
]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can _revert0_string be named differently?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions? It was already in there ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so esoteric, I'm not sure what to suggest

@@ -0,0 +1,2 @@
from .asm import rewrite_asm_for_ovm
from .spec import monkey_patch_evm_opcodes, rewrite_lll_for_ovm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can spec module be renamed to something clearer? Maybe transpile?

Comment on lines +5 to +8
# https://community.optimism.io/docs/protocol/protocol.html#execution-contracts
# * The CALLER, CALL, and REVERT opcodes are also disallowed, except in the special case that they appear as part of one of the following strings of bytecode: # noqa: 501
# CALLER PUSH1 0x00 SWAP1 GAS CALL PC PUSH1 0x0E ADD JUMPI RETURNDATASIZE PUSH1 0x00 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x00 REVERT JUMPDEST RETURNDATASIZE PUSH1 0x01 EQ ISZERO PC PUSH1 0x0a ADD JUMPI PUSH1 0x01 PUSH1 0x00 RETURN JUMPDEST # noqa: 501
# CALLER POP PUSH1 0x00 PUSH1 0x04 GAS CALL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# https://community.optimism.io/docs/protocol/protocol.html#execution-contracts
# * The CALLER, CALL, and REVERT opcodes are also disallowed, except in the special case that they appear as part of one of the following strings of bytecode: # noqa: 501
# CALLER PUSH1 0x00 SWAP1 GAS CALL PC PUSH1 0x0E ADD JUMPI RETURNDATASIZE PUSH1 0x00 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x00 REVERT JUMPDEST RETURNDATASIZE PUSH1 0x01 EQ ISZERO PC PUSH1 0x0a ADD JUMPI PUSH1 0x01 PUSH1 0x00 RETURN JUMPDEST # noqa: 501
# CALLER POP PUSH1 0x00 PUSH1 0x04 GAS CALL
# https://community.optimism.io/docs/protocol/protocol.html#execution-contracts
# NOTE: The CALLER, CALL, and REVERT opcodes are also disallowed, except in the special
# case that they appear as part of one of the following sequences of bytecode:
# * `ALLOWED_EXEC_SEQ` (see below)
# * `ALLOWED_COPY_SEQ` (see below)

Comment on lines +32 to +39
ALLOWED_EXEC_STRING = "CALLER PUSH1 0x00 SWAP1 GAS CALL PC PUSH1 0x0E ADD JUMPI RETURNDATASIZE PUSH1 0x00 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x00 REVERT JUMPDEST RETURNDATASIZE PUSH1 0x01 EQ ISZERO PC PUSH1 0x0a ADD JUMPI PUSH1 0x01 PUSH1 0x00 RETURN JUMPDEST" # noqa: 501
OVM_EXEC_ASM = [parse_asm_item(x) for x in ALLOWED_EXEC_STRING.split(" ")]

# Call the identity precompile.
# this expects the last 4 args of identity precompile already on the stack:
# args_loc, args_len, return_loc, return_len
ALLOWED_COPY_STRING = "CALLER POP PUSH1 0x00 PUSH1 0x04 GAS CALL"
OVM_COPY_ASM = ALLOWED_COPY_STRING.split(" ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ALLOWED_EXEC_STRING = "CALLER PUSH1 0x00 SWAP1 GAS CALL PC PUSH1 0x0E ADD JUMPI RETURNDATASIZE PUSH1 0x00 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x00 REVERT JUMPDEST RETURNDATASIZE PUSH1 0x01 EQ ISZERO PC PUSH1 0x0a ADD JUMPI PUSH1 0x01 PUSH1 0x00 RETURN JUMPDEST" # noqa: 501
OVM_EXEC_ASM = [parse_asm_item(x) for x in ALLOWED_EXEC_STRING.split(" ")]
# Call the identity precompile.
# this expects the last 4 args of identity precompile already on the stack:
# args_loc, args_len, return_loc, return_len
ALLOWED_COPY_STRING = "CALLER POP PUSH1 0x00 PUSH1 0x04 GAS CALL"
OVM_COPY_ASM = ALLOWED_COPY_STRING.split(" ")
ALLOWED_EXEC_SEQ = (
"CALLER PUSH1 0x00 SWAP1 GAS CALL PC PUSH1 0x0E ADD JUMPI RETURNDATASIZE PUSH1 0x00 DUP1 "
"RETURNDATACOPY RETURNDATASIZE PUSH1 0x00 REVERT JUMPDEST RETURNDATASIZE PUSH1 0x01 "
"EQ ISZERO PC PUSH1 0x0a ADD JUMPI PUSH1 0x01 PUSH1 0x00 RETURN JUMPDEST"
)
OVM_EXEC_ASM = [parse_asm_item(x) for x in ALLOWED_EXEC_SEQ.split(" ")]
# Call the identity precompile.
# this expects the last 4 args of identity precompile already on the stack:
# args_loc, args_len, return_loc, return_len
ALLOWED_COPY_SEQ = "CALLER POP PUSH1 0x00 PUSH1 0x04 GAS CALL"
OVM_COPY_ASM = ALLOWED_COPY_SEQ.split(" ")

Co-authored-by: El De-dog-lo <3859395+fubuloubu@users.noreply.github.com>
Comment on lines +428 to +431
bool_ = "bool"
uint256 = "uint256"
bytes_ = "bytes"
address = "address"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird

return lll_nodes, lll_runtime


def generate_assembly(lll_nodes: parser.LLLnode) -> list:
def generate_assembly(lll_nodes: parser.LLLnode, use_ovm: bool = False) -> list:
Copy link

@storming0x storming0x Aug 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment, no change needed. Could be a bit nitpicky or YAGNI syndrome, the approach of passing a bool flag across the call stack works here for what we want.

Wondering if other EVM implementations like zkEVM, etc, may also need to rewrite of opcodes, then this solution will become adding more bool flags? which at that point it may be better to go with a Config struct arg or dictionary or change to approach to functional composition generate_assembly_ovm, etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the way you're thinking. Just to give some context -- the structure of this module is already a little weird. The entry point goes thru CompilerData which is a struct with all the config data. And then it calls these functions like generate_assembly which are in fact private to the module, passing around these arguments.

I actually did consider refactoring how the config is threaded through the compiler. The reason I chose to do it this way instead is because OVM support is experimental, I wanted to minimize the diff to the existing compiler code. If we choose to remove support, say, in the next release, it won't be so hard.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree on minimizing the diff to get this out. Sounds good to refactor later if needed.

@fubuloubu fubuloubu merged commit d57b7b0 into vyperlang:master Aug 25, 2021
@charles-cooper
Copy link
Member Author

Lol I got a couple style things to fix -- rename monkey_patch to monkeypatch, rename the ovm/spec.py module, cut up long lines

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.

4 participants