Skip to content

Commit 7ce79d4

Browse files
committed
Updated demo
1 parent ec1bfc9 commit 7ce79d4

16 files changed

Lines changed: 2427 additions & 17 deletions

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,14 @@ zig-out/
2020
# Although this was renamed to .zig-cache, let's leave it here for a few
2121
# releases to make it less annoying to work with multiple branches.
2222
zig-cache/
23+
24+
# Build artifacts
25+
*.o
26+
*.a
27+
*.so
28+
*.dylib
29+
*.dll
30+
31+
# OS files
32+
.DS_Store
33+
Thumbs.db

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM ubuntu:24.04 AS builder
2+
3+
RUN apt-get update && apt-get install -y wget xz-utils && rm -rf /var/lib/apt/lists/*
4+
5+
# Install Zig 0.15.2
6+
RUN wget -q https://ziglang.org/download/0.15.2/zig-0.15.2-x86_64-linux.tar.xz && \
7+
tar xf zig-0.15.2-x86_64-linux.tar.xz && \
8+
mv zig-0.15.2-x86_64-linux /opt/zig && \
9+
rm zig-0.15.2-x86_64-linux.tar.xz
10+
11+
ENV PATH="/opt/zig:${PATH}"
12+
13+
WORKDIR /app
14+
COPY . .
15+
16+
RUN zig build build-web -Doptimize=ReleaseFast
17+
18+
FROM ubuntu:24.04
19+
COPY --from=builder /app/zig-out/bin/zig-evm-web /usr/local/bin/zig-evm-web
20+
21+
EXPOSE 3000
22+
ENV PORT=3000
23+
24+
CMD ["zig-evm-web"]

build.zig

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,30 @@ pub fn build(b: *std.Build) void {
153153
const run_compliance_step = b.step("compliance", "Run Ethereum compliance tests");
154154
run_compliance_step.dependOn(&run_compliance_cmd.step);
155155

156+
// Web demo server
157+
const web_exe = b.addExecutable(.{
158+
.name = "zig-evm-web",
159+
.root_module = b.createModule(.{
160+
.root_source_file = b.path("src/web_server.zig"),
161+
.target = target,
162+
.optimize = optimize,
163+
}),
164+
});
165+
166+
b.installArtifact(web_exe);
167+
168+
const install_web = b.addInstallArtifact(web_exe, .{});
169+
const build_web_step = b.step("build-web", "Build the web demo server");
170+
build_web_step.dependOn(&install_web.step);
171+
172+
const run_web_cmd = b.addRunArtifact(web_exe);
173+
174+
const run_web_step = b.step("web", "Run the web demo server");
175+
run_web_step.dependOn(&run_web_cmd.step);
176+
156177
// Shared library for FFI
157-
const lib = b.addSharedLibrary(.{
178+
const lib = b.addLibrary(.{
179+
.linkage = .dynamic,
158180
.name = "zigevm",
159181
.root_module = b.createModule(.{
160182
.root_source_file = b.path("src/ffi.zig"),
@@ -167,7 +189,8 @@ pub fn build(b: *std.Build) void {
167189
b.installArtifact(lib);
168190

169191
// Also create static library
170-
const static_lib = b.addStaticLibrary(.{
192+
const static_lib = b.addLibrary(.{
193+
.linkage = .static,
171194
.name = "zigevm",
172195
.root_module = b.createModule(.{
173196
.root_source_file = b.path("src/ffi.zig"),

captain-definition

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"schemaVersion": 2,
3+
"dockerfilePath": "./Dockerfile"
4+
}

src/bigint.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ pub const BigInt = struct {
461461
if (i >= word_shift) {
462462
result.data[i] = self.data[i - word_shift] << bit_shift;
463463
if (i > word_shift) {
464-
result.data[i] |= self.data[i - word_shift - 1] >> @as(u6, 64 - bit_shift);
464+
result.data[i] |= self.data[i - word_shift - 1] >> @as(u6, @intCast(@as(u7, 64) - @as(u7, bit_shift)));
465465
}
466466
}
467467
}
@@ -500,7 +500,7 @@ pub const BigInt = struct {
500500
if (i + word_shift < 4) {
501501
result.data[i] = self.data[i + word_shift] >> bit_shift;
502502
if (i + word_shift + 1 < 4) {
503-
result.data[i] |= self.data[i + word_shift + 1] << @as(u6, 64 - bit_shift);
503+
result.data[i] |= self.data[i + word_shift + 1] << @as(u6, @intCast(@as(u7, 64) - @as(u7, bit_shift)));
504504
}
505505
}
506506
}

src/call_frame.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ pub const CallFrame = struct {
106106

107107
/// Call stack managing nested call frames
108108
pub const CallStack = struct {
109-
frames: std.ArrayList(CallFrame),
109+
frames: std.array_list.Managed(CallFrame),
110110
max_depth: u16,
111111
allocator: Allocator,
112112

113113
pub const MAX_CALL_DEPTH: u16 = 1024;
114114

115115
pub fn init(allocator: Allocator) CallStack {
116116
return CallStack{
117-
.frames = std.ArrayList(CallFrame).init(allocator),
117+
.frames = std.array_list.Managed(CallFrame).init(allocator),
118118
.max_depth = MAX_CALL_DEPTH,
119119
.allocator = allocator,
120120
};
@@ -258,7 +258,7 @@ test "static context propagation" {
258258
defer stack.deinit();
259259

260260
// First frame is static
261-
var static_frame = CallFrame.init(
261+
const static_frame = CallFrame.init(
262262
[_]u8{0} ** 20,
263263
[_]u8{0} ** 20,
264264
[_]u8{0} ** 20,
@@ -275,7 +275,7 @@ test "static context propagation" {
275275
try stack.push(static_frame);
276276

277277
// Nested frame is not explicitly static, but inherits from parent
278-
var nested_frame = CallFrame.init(
278+
const nested_frame = CallFrame.init(
279279
[_]u8{0} ** 20,
280280
[_]u8{0} ** 20,
281281
[_]u8{0} ** 20,

0 commit comments

Comments
 (0)