Skip to content

Refactor dMint v2 contract layout and fix bytecode issues - #23

Merged
Antares-RXD merged 4 commits into
RadiantBlockchain-Community:masterfrom
Radiant-Core:master
Apr 11, 2026
Merged

Refactor dMint v2 contract layout and fix bytecode issues#23
Antares-RXD merged 4 commits into
RadiantBlockchain-Community:masterfrom
Radiant-Core:master

Conversation

@Antares-RXD

Copy link
Copy Markdown
Member

No description provided.

…atch

- Remove redundant clearTimeout(this.connectedTimeout) from onOpen()
- Keep single clearTimeout in onClose() to prevent timeout leak
- Update patch hash in pnpm-lock.yaml to reflect simplified patch
… bytecode-embedded DAA params

- Remove variable state item count; all v2 contracts now use 10 state items
- Add lastTime to state layout (height, contractRef, tokenRef, maxHeight, reward, algoId, daaMode, targetTime, lastTime, target)
- Move halfLife from state to bytecode constant in ASERT DAA implementation
- Split Part B into B1 (PoW extraction), B2 (target comparison), B4 (cleanup), and dynamic DAA bytecode
- Add buildAsertDaaBytecode()
The code sequence is OP_OUTPOINTTXHASH OP_INPUTBYTECODE <N> OP_PICK.
OP_INPUTBYTECODE pushes an extra item onto the stack before the PICK,
so all PICK/ROLL indices must be +1 vs. the naive stateItemCount formula.

Before (wrong):  contractRefPick = stateItemCount-1 (9 for 10 items)
After  (correct): contractRefPick = stateItemCount   (10 for 10 items)
Similarly:        ioPick: +3 -> +4, nonceRoll: +4 -> +5

This caused 'mandatory-script-verify-flag-failed (Operation not valid
with the current stack size)' on broadcast because OP_9 PICK was
reaching tokenRef instead of contractRef at runtime.

Also adds inputBytecode to the assertDmintPreimageLayout stack
simulation so the self-verification catches future index drift.
The original Part A bytecode 5175c0c8 included both OP_INPUTINDEX (c0)
and OP_OUTPOINTTXHASH (c8). After Part A execution, txHash is consumed
by OP_CAT with contractRef, but inputIndex (from c0) remains on the
stack, shifting B.2's OP_1 PICK away from target and breaking the DAA.

Fix: remove c0 from buildDmintPreimageBytecodePartA so the code starts
with 5175c8 only. With a single push opcode (c8=OP_OUTPOINTTXHASH),
the stack is clean after Part A and OP_1 PICK in B.2 correctly reaches
the target. Indices remain stateItemCount-1 / +3 / +4.

Update assertDmintPreimageLayout simulation to use outpointTxHash
(matching runtime) and update test expectations accordingly.
@Antares-RXD
Antares-RXD merged commit 0a8b33d into RadiantBlockchain-Community:master Apr 11, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants