evmts / tevm-monorepo

A library that enables next-generation UX and DX via putting an ethereum node in the browser and solidity in javascript
https://tevm.sh
MIT License
250 stars 25 forks source link

Open Question: Bytecode compilation #1471

Open roninjin10 opened 1 week ago

roninjin10 commented 1 week ago

Summary

Generating bytecode is as much as 100x slower than generating an ABI. Furthermore, most use cases do not need the bytecode only the abi because the bytecode is already deployed. For this reason, Tevm only compiles bytecode for files that explicitly have a .s.sol file extension. Users are expected to either name their files .s.sol or reexport their contract from a .s.sol file

This issue is to revisit that decision before going stable

Alternative solutions

0 Keep it the same

Pros

Cons

1 Always compile the bytecode

Pros

Cons

2 Import attributes

Uses the new import attribute

import {MyContract} from '~/contracts/MyContract.sol' // by default no bytecode
import {MyContract} from '~/contracts/MyContract.sol' as { type: 'sol-script' } // this will have bytecode
import {MyContract} from '~/contracts/MyContract.sol' as { type: 'sol' } // this will not have bytecode

Pros

Cons

3 Make the bytecode different import target

This solution borrows from typechain

import { MyContract, MyContract__bytecode } from '~/contracts/MyContract.sol'

const contractWithBytecode = MyContract.withBytecode(MyContract__bytecode)

Pros

Cons

linear[bot] commented 1 week ago

TEV-1394 Open Question: Bytecode compilation

roninjin10 commented 1 week ago

Historically i initially made this change to not compiling bytecode by default well over a year ago. Users were suffering from tevm slowing their LSP to a crawl when they started adding more and more contracts and this change put out that fire.

Since then we have:

  1. Added caching
  2. Made the LSP and bundler code paths different such that this would no longer affect the LSP only the prodcution build and dev server

So even though I think the current API is good and perhaps my favorite API it's worth revisiting before going stable