Describe the bug
The following instruction will cause different behavior on DefaultMachine(rust) and AsmMachine(asm).
1021a: 00000097 auipc ra,0x0
1021e: fd4080e7 jalr -44(ra) # 0x101ee
Let's focus on the instruction 1021e. We expect this instruction to jump to rs1(which is ra) - 14 and set the pc + 4 to the rd(which is ra) register. The DefaultMachine handles this as expected. But unfortunately, the AsmMachine set the registers in a wrong ordering:
https://github.com/nervosnetwork/ckb-vm/blob/develop/src/machine/asm/execute.S#L441
AsmMachine set rd first, then read from rs1, when the rs1 and rd use the different registers this behavior is correct, but if the rs1 and rd use the same register then the WRITE_RD operation overwrite the value of rs1.
How to fix
To simply fix this problem, we can move the WRITE_RD to the after of the REGISTER_ADDRESS(RS1).
The change may cause the network consensus split. We need to wait for a hard-fork to apply it.
Describe the bug
The following instruction will cause different behavior on DefaultMachine(rust) and AsmMachine(asm).
Let's focus on the instruction
1021e. We expect this instruction to jump tors1(which isra) -14and set thepc + 4to therd(which isra) register. The DefaultMachine handles this as expected. But unfortunately, the AsmMachine set the registers in a wrong ordering:https://github.com/nervosnetwork/ckb-vm/blob/develop/src/machine/asm/execute.S#L441
AsmMachine set
rdfirst, then read fromrs1, when thers1andrduse the different registers this behavior is correct, but if thers1andrduse the same register then theWRITE_RDoperation overwrite the value ofrs1.How to fix
To simply fix this problem, we can move the
WRITE_RDto the after of theREGISTER_ADDRESS(RS1).The change may cause the network consensus split. We need to wait for a hard-fork to apply it.