Skip to content

Commit

Permalink
Merge pull request #17 from jsign/jsign-vm2
Browse files Browse the repository at this point in the history
Implement the block execution pipeline
  • Loading branch information
jsign authored Feb 6, 2024
2 parents 277c762 + 555ea0f commit e6be1bc
Show file tree
Hide file tree
Showing 29 changed files with 1,342 additions and 873 deletions.
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = .{ .path = "src/lib.zig" },
.target = target,
.optimize = optimize,
});
Expand Down
6 changes: 3 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
.version = "0.0.1-beta-0",
.dependencies = .{
.@"zig-rlp" = .{
.url = "https://github.com/gballet/zig-rlp/archive/refs/tags/v0.0.1-beta-9.tar.gz",
.hash = "12203e6f5225dec28e2661b9c4d93dd142bea37ab1f2cac165d93dc56c65fb259be8",
.url = "https://github.com/gballet/zig-rlp/archive/refs/tags/v0.1.0.tar.gz",
.hash = "1220ebf62505957cdd9c87b9c517ceba60c46f5c9578a504ab3299b3970cc3ab0a1d",
},
.@"zig-eth-secp256k1" = .{
.url = "https://github.com/jsign/zig-eth-secp256k1/archive/refs/tags/v0.1.0-beta-3.tar.gz",
Expand All @@ -13,6 +13,6 @@
.httpz = .{
.url = "https://github.com/karlseguin/http.zig/archive/1a82beb0dfc22e6fc38e9918e323f8fbd3cb78a3.tar.gz",
.hash = "122020cbd399273b1220f11c4b2d734b86c94cc5f1c2d6d90fc766580bc0e25b0dfb",
}
},
},
}
414 changes: 414 additions & 0 deletions src/blockchain/blockchain.zig

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions src/blockchain/params.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const std = @import("std");
const types = @import("../types/types.zig");
const Address = types.Address;

pub const gas_limit_adjustement_factor = 1024;
pub const gas_limit_minimum = 5000;
pub const gas_init_code_word_const = 2;

pub const tx_base_cost = 21000;
pub const tx_data_cost_per_zero = 4;
pub const tx_data_cost_per_non_zero = 16;
pub const tx_create_cost = 32000;
pub const tx_access_list_address_cost = 2400;
pub const tx_access_list_storage_key_cost = 1900;

pub const base_fee_max_change_denominator = 8;
pub const elasticity_multiplier = 2;
pub const max_code_size = 0x6000;

pub const stack_depth_limit = 1024;

pub const precompiled_contract_addresses = [_]Address{
addressFromInt(1), // ECRECOVER
addressFromInt(2), // SHA256
addressFromInt(3), // RIPEMD160
addressFromInt(4), // IDENTITY_ADDRESS
addressFromInt(5), // MODEXP_ADDRESS
addressFromInt(6), // ALT_BN128_ADD
addressFromInt(7), // ALT_BN128_MUL
addressFromInt(8), // ALT_BN128_PAIRING_CHECK
addressFromInt(9), // BLAKE2F
};

fn addressFromInt(comptime i: u160) Address {
var addr: Address = undefined;
std.mem.writeInt(u160, &addr, i, .Big);
return addr;
}
35 changes: 35 additions & 0 deletions src/blockchain/types.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const types = @import("../types/types.zig");
const config = @import("../config/config.zig");
const common = @import("../common/common.zig");
const StateDB = @import("../state/state.zig").StateDB;
const Address = types.Address;
const Hash32 = types.Hash32;
const Bytes32 = types.Bytes32;
const AddressSet = common.AddressSet;
const AddresssKey = common.AddressKey;
const AddressKeySet = common.AddressKeySet;

pub const Environment = struct {
block_hashes: [256]Hash32,
origin: Address,
coinbase: Address,
number: u64,
base_fee_per_gas: u256,
gas_limit: u64,
gas_price: u256,
time: u64,
prev_randao: Bytes32,
state: *StateDB,
chain_id: config.ChainId,
};

pub const Message = struct {
caller: Address,
target: ?Address,
current_target: Address,
gas: u64,
value: u256,
data: []const u8,
code_address: ?Address,
code: []const u8,
};
Loading

0 comments on commit e6be1bc

Please sign in to comment.