-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Reintroduce a gasLimit in EOA wallet / eth_estimateGas
#823
Comments
Since the |
Updated this issue to specifically call out the change required in L2Geth |
Is there a reference implementation of this calculation that we can take a look at? |
It now does |
L1 gas cost of a transaction is equal to: Total fee per tx (sum of the two): |
|
edit: no longer being used
|
Example Transaction:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This solution encodes the L2 gaslimit in the lower order bits of the fee, which is #!/usr/bin/env python
def compute_data_cost(data):
ones = 0
zeros = 0
for b in data:
if b == 0:
zeros += 1
else:
ones += 1
ones_cost = ones * 16
zeros_cost = zeros * 4
return ones_cost + zeros_cost
def eth_estimate_gas(x):
return x
def gwei_to_wei(x):
return x * 10**9
def wei_to_gwei(x):
return x * 10**-9
# The L1 gas price must satisfy the equation `x * (10**8)`
# Round to next highest number that satisfies this equation
def get_l1_gas_price(number):
number += (10**8 - 2 if number % 10**8 < 2 else 10**8)
return number - (number % 10**8)
# The L2 gas price must satisfy the equation `x * (10**8) + 1`
def get_l2_gas_price(number):
number += (10**8 - 2 if number % 10**8 < 2 else 10**8)
return number - (number % 10**8) + 1
if __name__ == '__main__':
# example mainnet transaction
tx = b'0xf86c01854349be0a0082520894a1d8d972560c2f8144af871db508f0b0b10a3fbf8803f60cc2863df0008026a06d0450652736e0b8f9b5b9d369498dcfd805bafc2099e02b5ecd1d8e9726d548a070718c36c22987a840869f87d650882554f2fa4faf85be061e355ceba930a270'
# the overhead of submitting a transaction to L1 is ~4200 gas
# this value is hardcoded
overhead = 4200
# fetch the L1 gas price from an L1 Provider
# the return value must satisfy the equation
# `y * 10**8` so round up to the nearest number
l1_gas_price = get_l1_gas_price(gwei_to_wei(2000))
# compute the L1 gas used to submit the transaction
l1_gas_used = compute_data_cost(tx) + overhead
# call the L2 gas oracle to get the current gas price
# the return value must satisfy the equation
# `x * (10**8) + 1`
# round up to the nearest number
l2_gas_price = get_l2_gas_price(gwei_to_wei(5000))
# call estimate gas to determine how much gas is used by the transaction
l2_gas_limit = eth_estimate_gas(437118)
estimate_gas = l2_gas_price * l2_gas_limit + l1_gas_price * l1_gas_used
gas_price = 1
print(estimate_gas)
recomputed_l2_gas_limit = estimate_gas % 10**8
assert recomputed_l2_gas_limit == l2_gas_limit |
do we have any code that's written in Python or is this just pseudocode? 👀 |
You can try running the python linked above |
I was more so wondering why you were referring to the python code as a "solution" if you're not implementing it in python |
I love that the overhead is 4200 gas 🤣 |
Documenting what we chatted about @tynes - When a tx is received via RPC, we calculate the fee it should have been sent by:
|
It turns out that setting a |
For this to work the following must be satisfied:
To efficiently verify whether the tx.gasPrice is correct you can use:
|
e.g. for a tx, with 1 wei gasPrice, we have a gasLimit of 45061500209015 |
^ Actionably, we just divide the fee by 10000 before adding the l2GasLimit |
Proposal: Round up Formula
Example:
For fun on the above calc:
|
Turns out Metamask rounds gasPrice down to Proposal: Round up Formula
Example:
For fun on the above calc:
|
No longer required in OVM 2.0. |
Is your feature request related to a problem? Please describe.
We have disabled the
gasLimit
check inside of the ECDSA wallet account here:optimism/packages/contracts/contracts/optimistic-ethereum/OVM/accounts/OVM_ECDSAContractAccount.sol
Lines 109 to 114 in 751e2be
We disabled this check because we changed the meaning of
gasLimit
signed in transactions to equalfee
. This meant that the wallet contract no longer had access to the gas required for execution. Removing this check introduces a security vulnerability for user wallets as the sequencer can extract a fee even if the gas supplied to the call is lower than what is acceptable.For more information on why we turned
gasLimit
intofee
see this discussion (mirror).Describe the solution you'd like
Currently,
We propose to change this to:
Where
feeDivisor=10000000
andgasLimitGranularity=100000
. Note this means that gasLimits can only be set in increments of 100k.Next we modify the wallet contract to include the following check:
This change also requires modifying L2Geth's
estimateGas
endpoint to return agas
value which also encodes thegasLimit
as is done above.Describe alternatives you've considered
Another option is require that the wallet's call does not revert. This has the adverse effect that the sequencer must execute all transactions before applying them. Otherwise they won't know that the transaction will pay them. This is a DOS vector,
The text was updated successfully, but these errors were encountered: