11const std = @import ("std" );
22const Address = @import ("../primitives/address.zig" ).Address ;
3- const U256 = @import ("../primitives/uint.zig" ).U256 ;
43const Hash = @import ("../primitives/hash.zig" ).Hash ;
4+ const uint_utils = @import ("../primitives/uint.zig" );
55
66/// Packed ABI encoding (tightly packed, no padding)
77/// Used for hashing and signature generation (e.g., EIP-712)
@@ -21,17 +21,16 @@ pub const PackedEncoder = struct {
2121 }
2222
2323 /// Encode a uint256 (no padding)
24- pub fn encodeUint256 (self : * PackedEncoder , value : U256 ) ! void {
25- const bytes = value . toBytes ( );
24+ pub fn encodeUint256 (self : * PackedEncoder , value : u256 ) ! void {
25+ const bytes = uint_utils . u256ToBytes ( value );
2626 try self .buffer .appendSlice (& bytes );
2727 }
2828
2929 /// Encode a uint of specific size
3030 pub fn encodeUint (self : * PackedEncoder , value : u256 , size_bytes : usize ) ! void {
3131 if (size_bytes > 32 ) return error .InvalidSize ;
3232
33- var bytes : [32 ]u8 = undefined ;
34- std .mem .writeInt (u256 , & bytes , value , .big );
33+ const bytes = uint_utils .u256ToBytes (value );
3534
3635 // Take only the required bytes from the end
3736 const offset = 32 - size_bytes ;
@@ -96,7 +95,7 @@ pub fn encodePacked(
9695
9796/// Packed value (tightly packed, no padding)
9897pub const PackedValue = union (enum ) {
99- uint256 : U256 ,
98+ uint256 : u256 ,
10099 uint : struct { value : u256 , size_bytes : usize },
101100 address : Address ,
102101 bool_val : bool ,
@@ -135,7 +134,7 @@ test "packed encode uint256" {
135134 var encoder = PackedEncoder .init (allocator );
136135 defer encoder .deinit ();
137136
138- const value = U256 . fromInt ( 42 );
137+ const value = @as ( u256 , 42 );
139138 try encoder .encodeUint256 (value );
140139
141140 const result = encoder .toSlice ();
@@ -191,7 +190,7 @@ test "packed encode multiple values" {
191190
192191 const values = [_ ]PackedValue {
193192 .{ .address = Address .fromBytes ([_ ]u8 {0xAB } ** 20 ) },
194- .{ .uint256 = U256 . fromInt ( 100 ) },
193+ .{ .uint256 = @as ( u256 , 100 ) },
195194 .{ .bool_val = true },
196195 };
197196
@@ -229,7 +228,7 @@ test "hash packed values" {
229228
230229 const values = [_ ]PackedValue {
231230 .{ .string = "hello" },
232- .{ .uint256 = U256 . fromInt ( 123 ) },
231+ .{ .uint256 = @as ( u256 , 123 ) },
233232 };
234233
235234 const hash = try hashPacked (allocator , & values );
0 commit comments