fix: encoder no longer treats all pointer fields as optional<T>#10
Merged
Conversation
The reflection-based encoder in encodeStruct() was adding a 0x01 "pointer present" flag before every pointer field, assuming all Go pointers map to Steem C++ optional<T>. This is wrong: many operations use plain (non-optional) structs like chain_properties and authority. For example, witness_update_operation::props is a plain chain_properties in C++, but the Go type uses *ChainProperties. The extra 0x01 byte corrupted the transaction digest, causing steemd to reject the signed transaction with "missing required active authority". Fix: - Add a steem:"optional" struct tag to distinguish truly optional fields - In encodeStruct(), only emit the presence byte for tagged fields - Untagged pointers are serialized directly (follow the pointer, no flag) - Tagged AccountUpdateOperation and AccountUpdate2Operation authority fields as optional (matching their C++ optional<authority> definition) - Added TestWitnessUpdateSerialization to guard against regression
- TestWitnessUpdateGoldenHex: byte-exact comparison against a hardcoded golden hex string, catching any field encoding regression (not just the 0x01 pointer bug) - TestAccountUpdateOptionalFields: verifies optional fields (owner/posting nil → 0x00, active set → 0x01) still emit presence flags correctly
kuny0707
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The reflection-based encoder in
encodeStruct()was adding a0x01"pointer present" flag before every pointer field, assuming all Go pointers map to Steem C++optional<T>. This is incorrect — many operations use plain (non-optional) structs.For example,
witness_update_operation::propsis a plainchain_propertiesin C++, but the Go type uses*ChainProperties. The extra0x01byte corrupted the transaction digest, causing steemd to reject the signed transaction withmissing required active authority.Root Cause
In
encoder/encoder.goencodeStruct():Fix
steem:"optional"struct tag to distinguish truly optional fieldssteem:"optional"AccountUpdateOperationandAccountUpdate2Operationauthority fields asoptional(matching their C++optional<authority>definition)witness_update.props,account_create.owner/active/posting,reset_account.new_owner_authority,escrow_transfer.ratification_deadline/escrow_expiration,limit_order_create.expiration,create_proposal.start_date/end_date,pow.*) are left untagged — they are plain structs in C++Verification
Added
TestWitnessUpdateSerialization— verifies the serialized output is 131 bytes (not 132) and that the byte afterblock_signing_keyis NOT0x01.