Skip to content

Use VMInstruction.ToString for parse script listings - #1097

Open
cschuchardt88 wants to merge 5 commits into
neo-project:master-n3from
cschuchardt88:fix/script-opcode-format
Open

Use VMInstruction.ToString for parse script listings#1097
cschuchardt88 wants to merge 5 commits into
neo-project:master-n3from
cschuchardt88:fix/script-opcode-format

Conversation

@cschuchardt88

@cschuchardt88 cschuchardt88 commented Aug 28, 2026

Copy link
Copy Markdown
Member

Summary

parse / ScriptsToOpCode now uses a single VMInstruction.ToString() layout, and DecodeOperand annotates operands instead of dumping raw hex.

Changes

  • ToString() is {position} {opcode} plus operand only when OperandSize > 0. Hex position width is at least 4 and grows with script length.
  • ScriptsToOpCode prefixes that with L{n}:. Decimal width is at least 4 (D04) and grows with the script size / instruction count (so listings longer than 9999 lines still line up).
  • Strict UTF-8 PUSHDATA* text (Utf8.IsValid) is shown as hex // text. Control runes are escaped (\n, \r, \t, \0, \xNN) so they do not create real newlines in the listing.
  • Otherwise, typed comments:
    • 33/65-byte ECPointhex // {point}
    • 20-byte UInt160 / 32-byte UInt256hex // {hash}
    • unix seconds or milliseconds in 2000–2100 on PUSHINT32/PUSHINT64 and 4/8-byte PUSHDATA
  • Remaining payloads: hex // blob N bytes.

Example

parse listing of this Base64 System.Contract.Call(updateFeeds, …) script:

L0000:0000 PUSH0
L0001:0001 PUSH0
L0002:0002 PUSH0
L0003:0003 PUSH0
L0004:0004 PUSH0
L0005:0005 PUSH0
L0006:0006 PUSH0
L0007:0007 PUSH0
L0008:0008 PUSH0
L0009:0009 PUSH0
L0010:000A PUSH0
L0011:000B PUSH0
L0012:000C PUSH12
L0013:000D PACK
L0014:000E PUSHDATA1 71BDDFD76DBDEF67BCF1C71AE77E787B973C69F79C79FF1F // blob 24 bytes
L0015:0028 PUSHDATA1 DF4EBBF5E7FDD1FD1BE7DE7979CF3C79A7F879F6F5F7879F // blob 24 bytes
L0016:0042 PUSHDATA1 EFDE7ADDBDDDDF5F7D7396F46BAEDE79AEF6F5B7F4DDAE36 // blob 24 bytes
L0017:005C PUSHDATA1 73B6DDDBAD5EE3DE9DDF969EE79E766FCDDE75AD7CF7AE75 // blob 24 bytes
L0018:0076 PUSHDATA1 D9ED1CEB8DFDD37EB469BF36F7ADB7774EDF77479DE3DF7D // blob 24 bytes
L0019:0090 PUSHDATA1 EB87B4EBC6B67FA7BDF7871E77BF5AD9EE1F7DBEDFEBBF7D // blob 24 bytes
L0020:00AA PUSHDATA1 79E73CEF869D778F1D79B79BD38D1CDF6D9E6F875CDB5775 // blob 24 bytes
L0021:00C4 PUSHDATA1 75B69AEB4F3C777D5B6DAF7AD1EF746B8EF5E5FE3AE37EFB // blob 24 bytes
L0022:00DE PUSHDATA1 DFD6F7E77DF4D38F35EDDD3AE39EDAD5F7F77767F4F766FC // blob 24 bytes
L0023:00F8 PUSHDATA1 739F5DD9ED34E9EE1CDB6D7DDF5F1FEF47F67BADF675FEB8 // blob 24 bytes
L0024:0112 PUSHDATA1 EDEE1BD78D7CEF6EDDF5EEBBF1EE1E6DAE9AF1B77C7F5EBB // blob 24 bytes
L0025:012C PUSHDATA1 D5CE3BE39E76F77F1B6FD738D9BD3B7F67BB71ADDE71C774 // blob 24 bytes
L0026:0146 PUSH12
L0027:0147 PACK
L0028:0148 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0029:014D PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0030:0152 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0031:0157 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0032:015C PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0033:0161 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0034:0166 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0035:016B PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0036:0170 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0037:0175 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0038:017A PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0039:017F PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0040:0184 PUSH12
L0041:0185 PACK
L0042:0186 PUSHINT32 148800
L0043:018B PUSHINT16 6265
L0044:018E PUSHINT32 771039978
L0045:0193 PUSHINT32 504880000
L0046:0198 PUSHINT32 87170
L0047:019D PUSHINT32 1417300
L0048:01A2 PUSHINT32 999930
L0049:01A7 PUSHINT32 1000020
L0050:01AC PUSHINT32 339700
L0051:01B1 PUSHINT64 2491470000 // 2048-12-13T11:00:00Z
L0052:01BA PUSHINT64 79426600000
L0053:01C3 PUSHINT32 2162000
L0054:01C8 PUSH12
L0055:01C9 PACK
L0056:01CA PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0057:01CF PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0058:01D4 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0059:01D9 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0060:01DE PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0061:01E3 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0062:01E8 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0063:01ED PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0064:01F2 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0065:01F7 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0066:01FC PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0067:0201 PUSHINT32 1787908101 // 2026-08-28T09:08:21Z
L0068:0206 PUSH12
L0069:0207 PACK
L0070:0208 PUSHDATA1 5457454C5645444154413A434E592D555344 // TWELVEDATA:CNY-USD
L0071:021C PUSHDATA1 5457454C5645444154413A4A50592D555344 // TWELVEDATA:JPY-USD
L0072:0230 PUSHDATA1 5457454C5645444154413A5350592D555344 // TWELVEDATA:SPY-USD
L0073:0244 PUSHDATA1 5457454C5645444154413A4D5346542D555344 // TWELVEDATA:MSFT-USD
L0074:0259 PUSHDATA1 5457454C5645444154413A444F47452D555344 // TWELVEDATA:DOGE-USD
L0075:026E PUSHDATA1 5457454C5645444154413A5852502D555344 // TWELVEDATA:XRP-USD
L0076:0282 PUSHDATA1 5457454C5645444154413A555344432D555344 // TWELVEDATA:USDC-USD
L0077:0297 PUSHDATA1 5457454C5645444154413A555344542D555344 // TWELVEDATA:USDT-USD
L0078:02AC PUSHDATA1 5457454C5645444154413A5452582D555344 // TWELVEDATA:TRX-USD
L0079:02C0 PUSHDATA1 5457454C5645444154413A4554482D555344 // TWELVEDATA:ETH-USD
L0080:02D4 PUSHDATA1 5457454C5645444154413A4254432D555344 // TWELVEDATA:BTC-USD
L0081:02E8 PUSHDATA1 5457454C5645444154413A4E454F2D555344 // TWELVEDATA:NEO-USD
L0082:02FC PUSH12
L0083:02FD PACK
L0084:02FE PUSH6
L0085:02FF PACK
L0086:0300 PUSH15
L0087:0301 PUSHDATA1 7570646174654665656473 // updateFeeds
L0088:030E PUSHDATA1 ABCC7F51C334D4F958BE8B6C54142AC4493F0103 // 0x03013f49c42a14546c8bbe58f9d434c3517fccab
L0089:0324 SYSCALL   [System.Contract.Call]

ScriptsToOpCode printed opcodes with a separate format from
VMInstruction.ToString. Share one layout: position, opcode, and
operand only when present. Keep the Lxxxx line prefix in parse output.
@github-actions github-actions Bot added the N3 label Aug 28, 2026
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.69811% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.61%. Comparing base (82b15f0) to head (584a1b0).

Files with missing lines Patch % Lines
src/Neo.CLI/Tools/VMInstruction.cs 72.38% 22 Missing and 7 partials ⚠️
src/Neo.CLI/CLI/MainService.Tools.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           master-n3    #1097      +/-   ##
=============================================
+ Coverage      50.88%   51.61%   +0.73%     
=============================================
  Files            284      284              
  Lines          16660    16747      +87     
  Branches        2137     2155      +18     
=============================================
+ Hits            8477     8644     +167     
+ Misses          7619     7523      -96     
- Partials         564      580      +16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Readable ASCII (including punctuation) is shown after the hex.
Otherwise 20/32/33/65-byte payloads use UInt160, UInt256, or ECPoint
ToString. Unix seconds or milliseconds in 2000-2100 are annotated on
PUSHINT and 4/8-byte PUSHDATA.
Require Utf8.IsValid and reject control runes. Allow any printable
Unicode, not only ASCII letters and digits.
Control characters in UTF-8 text comments are written as \n \r \t \0
or \xNN so they do not break the listing. Untyped payloads get
// blob N bytes.
D04 is the minimum. Larger scripts use more decimal digits for Lxxxx
and more hex digits for the instruction position.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant