feat(v2:shred): transaction sanitize and verify ticks #1660
Codecov Report
:x: Patch coverage is
95.01466% with 17 lines in your changes missing coverage. Please review.| Files with missing lines | Patch % | Lines |
|---|---|---|
| v2/services/replay.zig | 0.00% | 12 Missing :warning: |
| v2/lib/solana/transaction.zig | 98.48% | 5 Missing :warning: |
| Files with missing lines | Coverage Δ | |
|---|---|---|
| v2/lib/solana/transaction.zig | 96.87% <98.48%> (+96.87%) | :arrow_up: |
| v2/services/replay.zig | 32.88% <0.00%> (+2.84%) | :arrow_up: |
... and 4 files with indirect coverage changes
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
What is this in reference? I can't seem to find the switch (self) branch this is talking about.
for (0..keys.len - 1) |i| {
for (i + 1..keys.len) |j| {
if (std.mem.eql(u8, &keys[i].data, &keys[j].data)) return false;
}
}
Would there be any value in changing this from a boolean to an enum? The enum could then represent each "invariant", with the relevant member being annotated with the doc comment here, acting as the "numbering" directly in the code, instead of having to manually maintain these "comment links".
Any reason to not simply use a u8 here?
var max_acct_idx: u8 = 0;
for (instructions) |ix| {
const pid: usize = ix.program_id_index;
if (pid == 0 or pid >= acct_cnt) return false;
for (ix.accounts.items) |a| {
max_acct_idx = @max(max_acct_idx, a);
const w = try self.allocator.dupe(u8, writable);
errdefer self.allocator.free(w);
const r = try self.allocator.dupe(u8, readonly);
errdefer self.allocator.free(r);
No need to allocate 0 bytes, can initialize []T with &.{}.
const accounts_copy = try self.allocator.dupe(u8, accounts);
errdefer self.allocator.free(accounts_copy);
try self.instructions.append(self.allocator, .{
.program_id_index = program_id_index,
.accounts = .{ .items = accounts_copy },
.data = .{ .items = &.{} },
});
With the way this is used, should maybe instead modeled as a parameter on the build method, like builder.build(.v0).
General note: let's get used to using the new init decls, because the default initializations are deprecated. i.e. signatures: std.ArrayList(Signature) = .empty.
Requested changes.
sanity check, agave takes a tick_hash_count: &mut u64, is it fine to just copy rather than mutate?
How about we add an assert for this at the top?
I think we're not fully supporting SIMD 406 here, not a huge deal as it's not active yet
Requested changes.
Thanks for highlighting, I should have fixed it directly. Added a round trip unit test and updated the switch
8c495f7ca087d9f334083f0089e1c5c964771e13
fb08f9dc65770d7d7c3d677bb68753d0a9620d3f
fb08f9dc65770d7d7c3d677bb68753d0a9620d3f
fb08f9dc65770d7d7c3d677bb68753d0a9620d3f
fb08f9dc65770d7d7c3d677bb68753d0a9620d3f
fb08f9dc65770d7d7c3d677bb68753d0a9620d3f
5b125ccef7f0bbdf9de7cee0975953faa4406271
Good call, I like it! 15ece62d0930dc93437ec44f6d2319a7d7b55b3a
If we use std.debug.assert we may as well just have the check and return an error, since it will run in debug and release. This brings back the concept of having a debug assert which is omitted in ReleaseSafe. What are your thoughts?
Making it an actual error makes sense, that way can also get the stack trace for it in some contexts; not sure why that didn't occur to me lol.
Approved these changes.
Fair, it wasn't required for shred parse harness but likely will be in v2, updated to use mutable u64 as in v1. aac674bc5f0657270a0898ef67a616be2b467815
Here is the parse update we discussed. Lmk your thoughts c69859d7d95f38f2d5e0e029f9f6d4d2c503710a
InKryption
yewman
v2/solana: parse-level transaction + tick validation primitivesAdds three parse-time validation primitives the Solana protocol applies to every transaction and every slot's tick chain. Pure v2 library additions, no callers yet — the
sol_compat_shred_parse_v1differential harness wires them in a later PR.Changes
verify_ticks(verify_ticks.zig) — enforces the three slot-level tick invariants: exact tick count for the window, final entry is a tick once full, inter-tick hash counts equalhashes_per_tick. ReturnsBlockErrorwith the five failure modes. Lives under solana because v2Entryusesbincode.Vec(VersionedTransaction)where v1 uses[]const Transaction.VersionedTransaction.serializedSize— analytical bincode size (no round-trip, allocation-free). Backs the MTU rulesize > MAX_BYTES(1232). Per-component size functions co-located with each type.VersionedTransaction.validateAccountLocks— pairwise-distinct check on staticaccount_keys. Duplicates reject asAccountLoadedTwice. Static keys only; ALT-resolved entries must be re-checked post-resolution.VersionedTransaction.sanitize— 13 numbered structural invariants (signature/header agreement, instruction indices, ALT bookkeeping, …). Each documented inline and individually tested. MTU and duplicate-key checks deliberately live in the two methods above — treating them assanitizeerrors would conflate parse and account-locking stages.