Skip to content

Commit

Permalink
Add transaction initcodes support
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Mar 21, 2024
1 parent 954944a commit be2174a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
19 changes: 19 additions & 0 deletions bindings/go/evmc/evmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,22 @@ func bytesPtr(bytes []byte) *C.uint8_t {
}
return (*C.uint8_t)(unsafe.Pointer(&bytes[0]))
}

type TxInitcode struct {
hash Hash
code []byte
}

func evmcTxInitcodes(initcodes []TxInitcode) *C.evmc_tx_initcode {
if len(initcodes) == 0 {
return nil
}

out := make([]C.evmc_tx_initcode, len(initcodes))
for i := 0; i < len(initcodes); i++ {
out[i].hash = evmcBytes32(initcodes[i].hash)
out[i].code = bytesPtr(initcodes[i].code)
out[i].code_size = C.size_t(len(initcodes[i].code))
}
return &out[0]
}
3 changes: 3 additions & 0 deletions bindings/go/evmc/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type TxContext struct {
ChainID Hash
BaseFee Hash
BlobBaseFee Hash
Initcodes []TxInitcode
}

type HostContext interface {
Expand Down Expand Up @@ -188,6 +189,8 @@ func getTxContext(pCtx unsafe.Pointer) C.struct_evmc_tx_context {
evmcBytes32(txContext.BlobBaseFee),
nil, // TODO: Add support for blob hashes.
0,
evmcTxInitcodes(txContext.Initcodes),
C.size_t(len(txContext.Initcodes)),
}
}

Expand Down
2 changes: 2 additions & 0 deletions bindings/rust/evmc-vm/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ mod tests {
blob_base_fee: Uint256::default(),
blob_hashes: std::ptr::null(),
blob_hashes_count: 0,
initcodes: std::ptr::null(),
initcodes_count: 0,
}
}

Expand Down
2 changes: 2 additions & 0 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@ mod tests {
blob_base_fee: Uint256::default(),
blob_hashes: std::ptr::null(),
blob_hashes_count: 0,
initcodes: std::ptr::null(),
initcodes_count: 0,
}
}

Expand Down
38 changes: 24 additions & 14 deletions include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ struct evmc_message
/**
* The optional value used in new contract address construction.
*
* Needed only for a Host to calculate created address when kind is ::EVMC_CREATE2.
* Needed only for a Host to calculate created address when kind is ::EVMC_CREATE2,
* ::EVMC_EOFCREATE.
* Ignored in evmc_execute_fn().
*/
evmc_bytes32 create2_salt;
Expand All @@ -180,7 +181,7 @@ struct evmc_message
* For ::EVMC_CALLCODE or ::EVMC_DELEGATECALL this may be different from
* the evmc_message::recipient.
* Not required when invoking evmc_execute_fn(), only when invoking evmc_call_fn().
* Ignored if kind is ::EVMC_CREATE or ::EVMC_CREATE2.
* Ignored if kind is ::EVMC_CREATE, ::EVMC_CREATE2 or ::EVMC_EOFCREATE.
*
* In case of ::EVMC_CAPABILITY_PRECOMPILES implementation, this fields should be inspected
* to identify the requested precompile.
Expand All @@ -200,22 +201,31 @@ struct evmc_message
size_t code_size;
};

/** The hashed initcode used for TXCREATE instruction. */
typedef struct evmc_tx_initcode
{
evmc_bytes32 hash; /**< The initcode hash. */
const uint8_t* code; /**< The code. */
size_t code_size; /**< The length of the code. */
} evmc_tx_initcode;

/** The transaction and block data for execution. */
struct evmc_tx_context
{
evmc_uint256be tx_gas_price; /**< The transaction gas price. */
evmc_address tx_origin; /**< The transaction origin account. */
evmc_address block_coinbase; /**< The miner of the block. */
int64_t block_number; /**< The block number. */
int64_t block_timestamp; /**< The block timestamp. */
int64_t block_gas_limit; /**< The block gas limit. */
evmc_uint256be block_prev_randao; /**< The block previous RANDAO (EIP-4399). */
evmc_uint256be chain_id; /**< The blockchain's ChainID. */
evmc_uint256be block_base_fee; /**< The block base fee per gas (EIP-1559, EIP-3198). */
evmc_uint256be blob_base_fee; /**< The blob base fee (EIP-7516). */
const evmc_bytes32* blob_hashes; /**< The array of blob hashes (EIP-4844). */
size_t blob_hashes_count; /**< The number of blob hashes (EIP-4844). */
evmc_uint256be tx_gas_price; /**< The transaction gas price. */
evmc_address tx_origin; /**< The transaction origin account. */
evmc_address block_coinbase; /**< The miner of the block. */
int64_t block_number; /**< The block number. */
int64_t block_timestamp; /**< The block timestamp. */
int64_t block_gas_limit; /**< The block gas limit. */
evmc_uint256be block_prev_randao; /**< The block previous RANDAO (EIP-4399). */
evmc_uint256be chain_id; /**< The blockchain's ChainID. */
evmc_uint256be block_base_fee; /**< The block base fee per gas (EIP-1559, EIP-3198). */
evmc_uint256be blob_base_fee; /**< The blob base fee (EIP-7516). */
const evmc_bytes32* blob_hashes; /**< The array of blob hashes (EIP-4844). */
size_t blob_hashes_count; /**< The number of blob hashes (EIP-4844). */
const evmc_tx_initcode* initcodes; /**< The array of transaction initcodes (TXCREATE). */
size_t initcodes_count; /**< The number of transaction initcodes (TXCREATE). */
};

/**
Expand Down

0 comments on commit be2174a

Please sign in to comment.