From 761efd0f9ebdff90dd1e7c8514587b26fca1682a Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Mon, 30 Oct 2023 11:53:15 +0100 Subject: [PATCH] implement deserialization of newPayloadV2 request --- build.zig | 7 ++ build.zig.zon | 6 +- src/common/common.zig | 4 + src/common/hexutils.zig | 45 +++++++++++ src/engine_api/engine_api.zig | 103 ++++++++++++++++++++++++++ src/engine_api/execution_payload.zig | 75 +++++++++++++++++++ src/engine_api/test_req.json | 21 ++++++ src/exec-spec-tests/execspectests.zig | 2 +- src/main.zig | 58 ++++++++++++++- src/types/block.zig | 103 ++++++++++++++------------ src/types/testdata/block2.rlp | Bin 5549 -> 0 bytes src/types/types.zig | 3 + src/types/withdrawal.zig | 9 +++ src/vm/vm.zig | 4 +- 14 files changed, 388 insertions(+), 52 deletions(-) create mode 100644 src/common/common.zig create mode 100644 src/common/hexutils.zig create mode 100644 src/engine_api/engine_api.zig create mode 100644 src/engine_api/execution_payload.zig create mode 100644 src/engine_api/test_req.json delete mode 100644 src/types/testdata/block2.rlp create mode 100644 src/types/withdrawal.zig diff --git a/build.zig b/build.zig index 0cef9a1..73d83c1 100644 --- a/build.zig +++ b/build.zig @@ -19,6 +19,11 @@ pub fn build(b: *std.Build) void { const mod_rlp = b.dependency("zig-rlp", .{ .target = target, .optimize = optimize }).module("rlp"); const depSecp256k1 = b.dependency("zig-eth-secp256k1", .{ .target = target, .optimize = optimize }); const mod_secp256k1 = depSecp256k1.module("zig-eth-secp256k1"); + const zap = b.dependency("zap", .{ + .target = target, + .optimize = optimize, + }); + const mod_zap = zap.module("zap"); const ethash = b.addStaticLibrary(.{ .name = "ethash", @@ -100,6 +105,8 @@ pub fn build(b: *std.Build) void { exe.addModule("zig-rlp", mod_rlp); exe.linkLibrary(depSecp256k1.artifact("secp256k1")); exe.addModule("zig-eth-secp256k1", mod_secp256k1); + exe.addModule("zap", mod_zap); + exe.linkLibrary(zap.artifact("facil.io")); // This declares intent for the executable to be installed into the // standard location when the user invokes the "install" step (the default diff --git a/build.zig.zon b/build.zig.zon index f258298..378e1e1 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,5 +1,5 @@ .{ - .name = "zig-rlp", + .name = "phant", .version = "0.0.1-beta-0", .dependencies = .{ .@"zig-rlp" = .{ @@ -10,5 +10,9 @@ .url = "https://github.com/jsign/zig-eth-secp256k1/archive/refs/tags/v0.1.0-beta-3.tar.gz", .hash = "1220fcf062f8ee89b343e1588ac3cc002f37ee3f72841dd7f9493d9c09acad7915a3", }, + .zap = .{ + .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.1.14-pre.tar.gz", + .hash = "122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3", + } }, } diff --git a/src/common/common.zig b/src/common/common.zig new file mode 100644 index 0000000..eec4d6e --- /dev/null +++ b/src/common/common.zig @@ -0,0 +1,4 @@ +const hexutils = @import("./hexutils.zig"); +pub const prefixedhex2hash = hexutils.prefixedhex2hash; +pub const prefixedhex2byteslice = hexutils.prefixedhex2byteslice; +pub const prefixedhex2u64 = hexutils.prefixedhex2u64; diff --git a/src/common/hexutils.zig b/src/common/hexutils.zig new file mode 100644 index 0000000..0dda044 --- /dev/null +++ b/src/common/hexutils.zig @@ -0,0 +1,45 @@ +const std = @import("std"); +const fmt = std.fmt; +const Allocator = std.mem.Allocator; + +// This function turns an optionally '0x'-prefixed hex string +// to a types.Hash32 +pub fn prefixedhex2hash(dst: []u8, src: []const u8) !void { + if (src.len < 2 or src.len % 2 != 0) { + return error.InvalidInput; + } + var skip0x: usize = if (src[1] == 'X' or src[1] == 'x') 2 else 0; + if (src[skip0x..].len != 2 * dst.len) { + return error.InvalidOutputLength; + } + _ = try fmt.hexToBytes(dst, src[skip0x..]); +} + +// This function turns an optionally '0x'-prefixed hex string +// to a byte slice +pub fn prefixedhex2byteslice(allocator: Allocator, src: []const u8) ![]u8 { + // TODO catch the 0x0 corner case + if (src.len < 2 or src.len % 2 != 0) { + return error.InvalidInput; + } + var skip0x: usize = if (src[1] == 'X' or src[1] == 'x') 2 else 0; + // TODO when refactoring, ensure the alloc is also made in the equivalent for prefixedhex2hash + var dst: []u8 = try allocator.alloc(u8, src[skip0x..].len / 2); + + _ = try fmt.hexToBytes(dst[0..], src[skip0x..]); + + return dst; +} + +// This function turns an optionally '0x'-prefixed hex string +// to a u64 +pub fn prefixedhex2u64(src: []const u8) !u64 { + // execution engine integers can be odd-length :facepalm: + if (src.len < 3) { + return error.InvalidInput; + } + + var skip0x: usize = if (src[1] == 'X' or src[1] == 'x') 2 else 0; + + return std.fmt.parseInt(u64, src[skip0x..], 16); +} diff --git a/src/engine_api/engine_api.zig b/src/engine_api/engine_api.zig new file mode 100644 index 0000000..b9ed86c --- /dev/null +++ b/src/engine_api/engine_api.zig @@ -0,0 +1,103 @@ +const std = @import("std"); +const fmt = std.fmt; +const Allocator = std.mem.Allocator; +pub const execution_payload = @import("./execution_payload.zig"); +const ExecutionPayload = execution_payload.ExecutionPayload; +const common = @import("../common/common.zig"); + +// This is an intermediate structure used to deserialize the hex strings +// from the JSON request. I have seen some zig libraries that can do this +// out of the box, but it seems that approach hasn't been merged into the +// std yet. +// Because the JSON libary won't be able to deserialize a union unless +// the union is explicitly named, all possible object keys are declared in +// this object, and the caller is responsible for sifting through them by +// calling any of the `to_*` method, based on the context. +const AllPossibleExecutionParams = struct { + parentHash: []const u8, + feeRecipient: []const u8, + stateRoot: []const u8, + receiptsRoot: []const u8, + logsBloom: []const u8, + prevRandao: []const u8, + blockNumber: []const u8, + gasLimit: []const u8, + gasUsed: []const u8, + timestamp: []const u8, + extraData: []const u8, + baseFeePerGas: []const u8, + blockHash: []const u8, + transactions: [][]const u8, + + pub fn to_execution_payload(self: *const AllPossibleExecutionParams, allocator: Allocator) !ExecutionPayload { + var transactions: [][]const u8 = &[_][]const u8{}; + if (self.transactions.len > 0) { + transactions = try allocator.alloc([]const u8, self.transactions.len); + for (self.transactions, 0..) |tx, txidx| { + transactions[txidx] = try common.prefixedhex2byteslice(allocator, tx); + } + } + + var ret = ExecutionPayload{ + .parentHash = undefined, + .feeRecipient = undefined, + .stateRoot = undefined, + .receiptsRoot = undefined, + .prevRandao = undefined, + .extraData = try common.prefixedhex2byteslice(allocator, self.extraData), + .blockHash = undefined, + .logsBloom = undefined, + .blockNumber = try common.prefixedhex2u64(self.blockNumber), + .gasLimit = try common.prefixedhex2u64(self.gasLimit), + .gasUsed = try common.prefixedhex2u64(self.gasUsed), + .timestamp = try common.prefixedhex2u64(self.timestamp), + .baseFeePerGas = try common.prefixedhex2u64(self.baseFeePerGas), + .transactions = transactions, + .withdrawals = null, + .blobGasUsed = null, + .excessBlobGas = null, + .allocator = allocator, + }; + + _ = try common.prefixedhex2hash(ret.parentHash[0..], self.parentHash); + _ = try common.prefixedhex2hash(ret.feeRecipient[0..], self.feeRecipient); + _ = try common.prefixedhex2hash(ret.stateRoot[0..], self.stateRoot); + _ = try common.prefixedhex2hash(ret.receiptsRoot[0..], self.receiptsRoot); + _ = try common.prefixedhex2hash(ret.logsBloom[0..], self.logsBloom); + _ = try common.prefixedhex2hash(ret.prevRandao[0..], self.prevRandao); + _ = try common.prefixedhex2hash(ret.blockHash[0..], self.blockHash); + + return ret; + } +}; + +pub const EngineAPIRequest = struct { + jsonrpc: []const u8, + id: u64, + method: []const u8, + params: []const AllPossibleExecutionParams, +}; + +test "deserialize sample engine_newPayloadV2" { + const json = std.json; + const expect = std.testing.expect; + + const filePath = "./src/engine_api/test_req.json"; + + const file = try std.fs.cwd().openFile(filePath, .{}); + defer file.close(); + + const stat = try file.stat(); + + var buffer = try std.testing.allocator.alloc(u8, stat.size); + defer std.testing.allocator.free(buffer); + _ = try file.readAll(buffer); + + const payload = try json.parseFromSlice(EngineAPIRequest, std.testing.allocator, buffer, .{ .ignore_unknown_fields = true }); + defer payload.deinit(); + + try expect(std.mem.eql(u8, payload.value.method, "engine_newPayloadV2")); + const execution_payload_json = payload.value.params[0]; + var ep = try execution_payload_json.to_execution_payload(std.testing.allocator); + try execution_payload.newPayloadV2Handler(&ep, std.testing.allocator); +} diff --git a/src/engine_api/execution_payload.zig b/src/engine_api/execution_payload.zig new file mode 100644 index 0000000..0ac3271 --- /dev/null +++ b/src/engine_api/execution_payload.zig @@ -0,0 +1,75 @@ +const std = @import("std"); +const types = @import("../types/types.zig"); +const Allocator = std.mem.Allocator; + +pub const ExecutionPayload = struct { + parentHash: types.Hash32, + feeRecipient: types.Address, + stateRoot: types.Hash32, + receiptsRoot: types.Hash32, + logsBloom: [256]u8, + prevRandao: types.Hash32, + blockNumber: u64, + gasLimit: u64, + gasUsed: u64, + timestamp: u64, + extraData: []const u8, + baseFeePerGas: u256, + blockHash: types.Hash32, + transactions: [][]const u8, + + withdrawals: ?[]types.Withdrawal, + blobGasUsed: ?u64, + excessBlobGas: ?u64, + // executionWitness : ?types.ExecutionWitness, + + allocator: Allocator, + + pub fn to_block(self: *const ExecutionPayload) types.Block { + return types.Block{ + .header = types.BlockHeader{ + .parent_hash = self.parentHash, + .uncle_hash = types.empty_uncle_hash, + .fee_recipient = self.feeRecipient, + .state_root = self.stateRoot, + .receipts_root = self.receiptsRoot, + .logs_bloom = self.logsBloom, + .prev_randao = self.prevRandao, + .block_number = @intCast(self.blockNumber), + .gas_limit = @intCast(self.gasLimit), + .gas_used = self.gasUsed, + .timestamp = @intCast(self.timestamp), + .extra_data = self.extraData, + .base_fee_per_gas = self.baseFeePerGas, + .transactions_root = [_]u8{0} ** 32, + .mix_hash = 0, + .nonce = [_]u8{0} ** 8, + .blob_gas_used = null, + .withdrawals_root = null, + .excess_blob_gas = null, + }, + // .blockHash = self.blockHash, + // .transactions = self.transactions, + // .withdrawals = self.withdrawals, + }; + } + + pub fn deinit(self: *ExecutionPayload, allocator: std.mem.Allocator) void { + if (self.extraData.len > 0) { + allocator.free(self.extraData); + } + } +}; + +pub fn newPayloadV2Handler(params: *ExecutionPayload, allocator: std.mem.Allocator) !void { + // TODO reconstruct the proof from the (currently undefined) execution witness + // and verify it. Then execute the block and return the result. + // vm.run_block(params.to_block(), params.transactions); + + // But so far, just print the content of the payload + std.log.info("newPayloadV2Handler: {any}", .{params}); + + var block = params.to_block(); + std.debug.print("block number={}\n", .{block.header.block_number}); + params.deinit(allocator); +} diff --git a/src/engine_api/test_req.json b/src/engine_api/test_req.json new file mode 100644 index 0000000..9db8f0c --- /dev/null +++ b/src/engine_api/test_req.json @@ -0,0 +1,21 @@ +{ + "jsonrpc": "2.0", + "id": 60282, + "method": "engine_newPayloadV2", + "params": [ + { + "parentHash": "0x522930864dc2f6569f4d4b92f40001fe6752727ff53db5cb5c5ffd51d3cc53e4", + "feeRecipient": "0xf97e180c050e5ab072211ad2c213eb5aee4df134", + "stateRoot": "0x27bb13dc19c41288dd29236b27baac49338c466b8c0eb44fb4c0c0083dfb214a", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "prevRandao": "0x8ad449de1358704350f28598677be5c4cd609b42d31653b967f615b47ad1e63e", + "blockNumber": "0x112b8", + "gasLimit": "0x1c9c380", + "gasUsed": "0x0", + "timestamp": "0x65361030", + "extraData": "0xd983010c01846765746889676f312e32302e3130856c696e7578", + "baseFeePerGas": "0x7", + "blockHash": "0x56f5dba155cc4317aaa479f26f135dd543d5977026e83a9bb6b0ae895b4c7a10", + "transactions": [] +}]} diff --git a/src/exec-spec-tests/execspectests.zig b/src/exec-spec-tests/execspectests.zig index 191f8f7..8c73e20 100644 --- a/src/exec-spec-tests/execspectests.zig +++ b/src/exec-spec-tests/execspectests.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const rlp = @import("zig-rlp"); +const rlp = @import("rlp"); const Allocator = std.mem.Allocator; const types = @import("../types/types.zig"); const Address = types.Address; diff --git a/src/main.zig b/src/main.zig index 078412e..898ccd2 100644 --- a/src/main.zig +++ b/src/main.zig @@ -8,10 +8,50 @@ const StateDB = @import("vm/statedb.zig"); const Block = types.Block; const Transaction = types.Transaction; const TxnSigner = @import("signer/signer.zig").TxnSigner; +const zap = @import("zap"); +const engine_api = @import("engine_api/engine_api.zig"); +const json = std.json; + +var allocator: std.mem.Allocator = undefined; + +fn engineAPIHandler(r: zap.SimpleRequest) void { + if (r.body == null) { + r.setStatus(.bad_request); + return; + } + const payload = json.parseFromSlice(engine_api.EngineAPIRequest, allocator, r.body.?, .{ .ignore_unknown_fields = true }) catch |err| { + std.log.err("error parsing json: {} (body={s})", .{ err, r.body.? }); + r.setStatus(.bad_request); + return; + }; + defer payload.deinit(); + + if (std.mem.eql(u8, payload.value.method, "engine_newPayloadV2")) { + const execution_payload_json = payload.value.params[0]; + var execution_payload = execution_payload_json.to_execution_payload(allocator) catch |err| { + std.log.warn("error parsing execution payload: {}", .{err}); + r.setStatus(.bad_request); + return; + }; + engine_api.execution_payload.newPayloadV2Handler(&execution_payload, allocator) catch |err| { + std.log.err("error handling newPayloadV2: {}", .{err}); + r.setStatus(.internal_server_error); + return; + }; + r.setStatus(.ok); + } else { + r.setStatus(.internal_server_error); + } + r.setContentType(.JSON) catch |err| { + std.log.err("error setting content type: {}", .{err}); + r.setStatus(.internal_server_error); + return; + }; +} pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; - var allocator = gpa.allocator(); + allocator = gpa.allocator(); std.log.info("Welcome to phant! 🐘", .{}); const txn_signer = try TxnSigner.init(); @@ -35,6 +75,9 @@ pub fn main() !void { .mix_hash = 0, .nonce = [_]u8{0} ** 8, .base_fee_per_gas = 10, + .withdrawals_root = null, + .blob_gas_used = null, + .excess_blob_gas = null, }, }; @@ -81,6 +124,18 @@ pub fn main() !void { std.log.err("error executing transaction: {}", .{err}); return; }; + + var listener = zap.SimpleHttpListener.init(.{ + .port = 8551, + .on_request = engineAPIHandler, + .log = true, + }); + try listener.listen(); + std.log.info("Listening on 8551", .{}); + zap.start(.{ + .threads = 1, + .workers = 1, + }); } test "tests" { @@ -91,4 +146,5 @@ test "tests" { _ = @import("types/types.zig"); _ = @import("vm/vm.zig"); _ = @import("crypto/ecdsa.zig"); + _ = @import("engine_api/engine_api.zig"); } diff --git a/src/types/block.zig b/src/types/block.zig index c35d487..913554b 100644 --- a/src/types/block.zig +++ b/src/types/block.zig @@ -19,6 +19,8 @@ pub const Block = struct { } }; +pub const empty_uncle_hash: types.Hash32 = [_]u8{ 29, 204, 77, 232, 222, 199, 93, 122, 171, 133, 181, 103, 182, 204, 212, 26, 211, 18, 69, 27, 148, 138, 116, 19, 240, 161, 66, 253, 64, 212, 147, 71 }; + pub const Header = struct { parent_hash: types.Hash32, uncle_hash: types.Hash32, @@ -35,53 +37,60 @@ pub const Header = struct { extra_data: []const u8, mix_hash: u256, nonce: [8]u8, - base_fee_per_gas: u256, + base_fee_per_gas: ?u256, + withdrawals_root: ?types.Hash32, + blob_gas_used: ?u64, + excess_blob_gas: ?u64, }; -var test_allocator = std.testing.allocator; -test "decode vkt block sample" { - const block = try Block.init(@embedFile("testdata/block2.rlp")); - try std.testing.expectEqualStrings( - "904e3f9205902a780563d861aaa9cd1d635597ad1893a92d7f83dc5fb51b6eb4", - &bytesToHex(block.header.parent_hash), - ); - try std.testing.expectEqualStrings( - "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", - &bytesToHex(block.header.uncle_hash), - ); - try std.testing.expectEqualStrings( - "0000000000000000000000000000000000000000", - &bytesToHex(block.header.fee_recipient), - ); - try std.testing.expectEqualStrings( - "350f40f771a73cd6bda4c37283b88c771179469b07633568b6047cf649b8c7d1", - &bytesToHex(block.header.state_root), - ); - try std.testing.expectEqualStrings( - "5f25ec3493913aef80e3d1d99e653321be3db3b16c3c83b82e6081cdce66a55c", - &bytesToHex(block.header.transactions_root), - ); - try std.testing.expectEqualStrings( - "8d7a148023d3a4612e85b2f142dcec65c358ab7fbd3aebdfef6868c018d44e3c", - &bytesToHex(block.header.receipts_root), - ); - try std.testing.expectEqualStrings( - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - &bytesToHex(block.header.logs_bloom), - ); - try std.testing.expectEqualStrings( - "0200000000000000000000000000000000000000000000000000000000000000", - &bytesToHex(block.header.prev_randao), - ); - try std.testing.expectEqual(@as(i64, 2), block.header.block_number); - try std.testing.expectEqual(@as(i64, 0x47e7c4), block.header.gas_limit); - try std.testing.expectEqual(@as(u64, 0x05802b), block.header.gas_used); - try std.testing.expectEqual(@as(i64, 0x14), block.header.timestamp); - try std.testing.expect(block.header.extra_data.len == 0); - try std.testing.expectEqual(@as(u256, 0), block.header.mix_hash); - try std.testing.expectEqual(@as(u256, 0x2de81128), block.header.base_fee_per_gas); -} +// NOTE: this test uses a bock from an old, pre-shanghai testnet. +// I have deactivated it and will replace it with a kaustinen +// block when I publish my progress with zig-verkle. +// var test_allocator = std.testing.allocator; + +// test "decode vkt block sample" { +// const block = try Block.init(@embedFile("testdata/block2.rlp")); +// try std.testing.expectEqualStrings( +// "904e3f9205902a780563d861aaa9cd1d635597ad1893a92d7f83dc5fb51b6eb4", +// &bytesToHex(block.header.parent_hash), +// ); +// try std.testing.expectEqualStrings( +// "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", +// &bytesToHex(block.header.uncle_hash), +// ); +// try std.testing.expectEqualStrings( +// "0000000000000000000000000000000000000000", +// &bytesToHex(block.header.fee_recipient), +// ); +// try std.testing.expectEqualStrings( +// "350f40f771a73cd6bda4c37283b88c771179469b07633568b6047cf649b8c7d1", +// &bytesToHex(block.header.state_root), +// ); +// try std.testing.expectEqualStrings( +// "5f25ec3493913aef80e3d1d99e653321be3db3b16c3c83b82e6081cdce66a55c", +// &bytesToHex(block.header.transactions_root), +// ); +// try std.testing.expectEqualStrings( +// "8d7a148023d3a4612e85b2f142dcec65c358ab7fbd3aebdfef6868c018d44e3c", +// &bytesToHex(block.header.receipts_root), +// ); +// try std.testing.expectEqualStrings( +// "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", +// &bytesToHex(block.header.logs_bloom), +// ); +// try std.testing.expectEqualStrings( +// "0200000000000000000000000000000000000000000000000000000000000000", +// &bytesToHex(block.header.prev_randao), +// ); +// try std.testing.expectEqual(@as(i64, 2), block.header.block_number); +// try std.testing.expectEqual(@as(i64, 0x47e7c4), block.header.gas_limit); +// try std.testing.expectEqual(@as(u64, 0x05802b), block.header.gas_used); +// try std.testing.expectEqual(@as(i64, 0x14), block.header.timestamp); +// try std.testing.expect(block.header.extra_data.len == 0); +// try std.testing.expectEqual(@as(u256, 0), block.header.mix_hash); +// try std.testing.expectEqual(@as(u256, 0x2de81128), block.header.base_fee_per_gas.?); +// } -fn bytesToHex(bytes: anytype) [bytes.len * 2]u8 { - return std.fmt.bytesToHex(bytes, std.fmt.Case.lower); -} +// fn bytesToHex(bytes: anytype) [bytes.len * 2]u8 { +// return std.fmt.bytesToHex(bytes, std.fmt.Case.lower); +// } diff --git a/src/types/testdata/block2.rlp b/src/types/testdata/block2.rlp deleted file mode 100644 index 6301b5d24f4719b954182fe67c865da0b8be29ec..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5549 zcmd^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HYu_VvtZZOPY<@pwBu1Js z0{Uc9_YetBN@|(LBjup0-xzOOZXo(XO}V4so{vG`{{LL;eR|^6Q6J+&|C|&Uq!igD zR3KYf{!%WN7+O+J%>kzn8$=3o5l9z>9EtrHyWmG(DpH^fxzEV4HN*0c|bwL84CT#moBpyyp-vBdE%VPBPQ@I;GqqLhJgnjF;d>E z5+TNMfqYc2t4->4sh+I3D0H96BJ|`qp(hq{68xt4e54SF&YMmMfqxT%FBfcmxk&s6 zD&UN%z~fzs$FrKG0`X|fzWjcpPMz!f)1r-UUcK3uw5f0=m4mSBqZIblJ5Ex85gu-! zlUO6)pSZCnA;ZYs)bC2@@6?T%vqZ_9@|^G!y|s8!rouA0;*#aF+_yD0<9zFN2asI{ Rlk}7WZSxDY++g#nzW^eRDPaHr diff --git a/src/types/types.zig b/src/types/types.zig index 338f1e4..3297b3b 100644 --- a/src/types/types.zig +++ b/src/types/types.zig @@ -11,3 +11,6 @@ pub const AccountState = @import("account_state.zig"); pub const Transaction = @import("transaction.zig"); pub const Block = @import("block.zig").Block; pub const BlockHeader = @import("block.zig").Header; +pub const Withdrawal = @import("withdrawal.zig"); + +pub const empty_uncle_hash = @import("block.zig").empty_uncle_hash; diff --git a/src/types/withdrawal.zig b/src/types/withdrawal.zig new file mode 100644 index 0000000..9c44544 --- /dev/null +++ b/src/types/withdrawal.zig @@ -0,0 +1,9 @@ +const std = @import("std"); +const types = @import("types.zig"); + +pub const Withdrawal = struct { + index: u64, + validator: u64, + address: types.Address, + amount: u64, +}; diff --git a/src/vm/vm.zig b/src/vm/vm.zig index 2b06ff7..c30f9e9 100644 --- a/src/vm/vm.zig +++ b/src/vm/vm.zig @@ -35,7 +35,7 @@ const BlockContext = struct { timestamp: i64, gas_limit: i64, prev_randao: u256, - base_fee: u256, + base_fee: ?u256, }; pub const VM = struct { @@ -215,7 +215,7 @@ pub const VM = struct { .block_gas_limit = vm.context.?.block.gas_limit, .block_prev_randao = util.to_evmc_bytes32(vm.context.?.block.prev_randao), .chain_id = util.to_evmc_bytes32(vm.context.?.txn.chain_id), - .block_base_fee = util.to_evmc_bytes32(vm.context.?.block.base_fee), + .block_base_fee = util.to_evmc_bytes32(vm.context.?.block.base_fee.?), }; }