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

implementation of EIP-4844: Shard Blob Transactions #1440

Merged
merged 15 commits into from
Jun 24, 2023
Merged
Prev Previous commit
Next Next commit
EIP-4844: implement DataHash Op Code
  • Loading branch information
jangko committed Jun 8, 2023
commit 5d092679dad2dbf10e028be2e3dcf10c2e778f25
16 changes: 15 additions & 1 deletion nimbus/evm/computation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,22 @@ template getGasPrice*(c: Computation): GasInt =
else:
c.vmState.txGasPrice

template getVersionedHashes*(c: Computation): VersionedHashes =
when evmc_enabled:
# TODO: implement
@[]
else:
c.vmState.txVersionedHashes

template getVersionedHashesLen*(c: Computation): int =
when evmc_enabled:
# TODO: implement
0
else:
c.vmState.txVersionedHashes.len

proc getBlockHash*(c: Computation, number: UInt256): Hash256
{.gcsafe, raises: [CatchableError].} =
{.gcsafe, raises: [CatchableError].} =
when evmc_enabled:
let
blockNumber = c.host.getTxContext().block_number.u256
Expand Down
1 change: 1 addition & 0 deletions nimbus/evm/interpreter/gas_costs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ template gasCosts(fork: EVMFork, prefix, ResultGasCostsName: untyped) =
ChainIdOp: fixed GasBase,
SelfBalance: fixed GasLow,
BaseFee: fixed GasBase,
DataHash: fixed GasVeryLow,

# 50s: Stack, Memory, Storage and Flow Operations
Pop: fixed GasBase,
Expand Down
5 changes: 3 additions & 2 deletions nimbus/evm/interpreter/op_codes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ type
ChainIdOp = 0x46, ## Get current chain’s EIP-155 unique identifier.
SelfBalance = 0x47, ## Get current contract's balance.
BaseFee = 0x48, ## Get block’s base fee. EIP-3198

Nop0x49, Nop0x4A, Nop0x4B, Nop0x4C, Nop0x4D,
DataHash = 0x49, ## Get transaction's versionedHash. EIP-4844

Nop0x4A, Nop0x4B, Nop0x4C, Nop0x4D,
Nop0x4E, Nop0x4F, ## ..

# 50s: Stack, Memory, Storage and Flow Operations
Expand Down
20 changes: 20 additions & 0 deletions nimbus/evm/interpreter/op_handlers/oph_blockdata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ const
k.cpt.stack.push:
k.cpt.getBaseFee

dataHashOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x49, Get current transaction's EIP-4844 versioned hash.
let index = k.cpt.stack.popInt().truncate(int)
let len = k.cpt.getVersionedHashesLen

if index < len:
k.cpt.stack.push:
k.cpt.getVersionedHashes()[index]
else:
k.cpt.stack.push:
0

# ------------------------------------------------------------------------------
# Public, op exec table entries
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -157,6 +169,14 @@ const
info: "Get current block's EIP-1559 base fee",
exec: (prep: vm2OpIgnore,
run: baseFeeOp,
post: vm2OpIgnore)),

(opCode: DataHash, ## 0x49, EIP-4844 Transaction versioned hash
forks: Vm2OpCancunAndLater,
name: "dataHash",
info: "Get current transaction's EIP-4844 versioned hash",
exec: (prep: vm2OpIgnore,
run: dataHashOp,
post: vm2OpIgnore))]

# ------------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions nimbus/evm/interpreter/op_handlers/oph_defs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ const
Vm2OpShanghaiAndLater* =
Vm2OpParisAndLater - {FkParis}

Vm2OpCancunAndLater* =
Vm2OpShanghaiAndLater - {FkShanghai}

# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------
7 changes: 6 additions & 1 deletion nimbus/evm/state_transactions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import

{.push raises: [].}

proc setupTxContext*(vmState: BaseVMState, origin: EthAddress, gasPrice: GasInt, forkOverride=none(EVMFork)) =
proc setupTxContext*(vmState: BaseVMState,
origin: EthAddress,
gasPrice: GasInt,
versionedHashes: openArray[VersionedHash],
forkOverride=none(EVMFork)) =
## this proc will be called each time a new transaction
## is going to be executed
vmState.txOrigin = origin
Expand All @@ -34,6 +38,7 @@ proc setupTxContext*(vmState: BaseVMState, origin: EthAddress, gasPrice: GasInt,
else:
vmState.determineFork
vmState.gasCosts = vmState.fork.forkToSchedule
vmState.txVersionedHashes = @versionedHashes


# FIXME-awkwardFactoring: the factoring out of the pre and
Expand Down
1 change: 1 addition & 0 deletions nimbus/evm/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type
cumulativeGasUsed*: GasInt
txOrigin* : EthAddress
txGasPrice* : GasInt
txVersionedHashes*: VersionedHashes
gasCosts* : GasCosts
fork* : EVMFork
minerAddress* : EthAddress
Expand Down
1 change: 1 addition & 0 deletions nimbus/transaction/call_common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ proc setupHost(call: CallParams): TransactionHost =
vmState.setupTxContext(
origin = call.origin.get(call.sender),
gasPrice = call.gasPrice,
versionedHashes = call.versionedHashes,
forkOverride = call.forkOverride
)

Expand Down