You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove abi_comptime module: unify selector/hash API (#25)
* Remove abi_comptime module: unify selector/hash API for comptime+runtime
Library functions no longer restrict callers with comptime parameters.
keccak.selector() and keccak.hash() work at both comptime and runtime --
the caller decides by using the `comptime` keyword or not.
Closes#23
* Remove comptime_address: rename to addressFromHex for comptime+runtime use
Same pattern as the selector/hash fix -- the caller decides whether to
evaluate at comptime, not the library.
Copy file name to clipboardExpand all lines: docs/content/docs/comptime.mdx
+19-17Lines changed: 19 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,31 @@
1
1
---
2
2
title: Comptime Selectors
3
-
description: Compile-time function selectors and event topics -- a key differentiator of eth.zig.
3
+
description: Function selectors and event topics that work at both compile time and runtime.
4
4
---
5
5
6
-
One of eth.zig's most powerful features is **comptime-first design**. Function selectors and event topics are computed at compile time, eliminating runtime hashing entirely.
6
+
eth.zig provides unified `keccak.selector()`and `keccak.hash()` functions that work at both compile time and runtime. The **caller** decides when to evaluate -- the library never restricts you.
7
7
8
8
## Function Selectors
9
9
10
-
A Solidity function selector is the first 4 bytes of the Keccak-256 hash of the function signature. In eth.zig, this is done at compile time:
10
+
A Solidity function selector is the first 4 bytes of the Keccak-256 hash of the function signature. Use `comptime` for zero runtime cost:
The Zig compiler evaluates `comptimeSelector` during compilation. The resulting binary contains only the precomputed 4-byte selectors -- no hashing at runtime.
23
+
The same function also works at runtime with dynamic strings:
24
+
25
+
```zig
26
+
// Runtime -- useful when the signature is only known at runtime
0 commit comments