diff --git a/pkg/vm/instruction.go b/pkg/vm/instruction.go index 880190389..43c14384b 100644 --- a/pkg/vm/instruction.go +++ b/pkg/vm/instruction.go @@ -2,6 +2,7 @@ package vm import ( "fmt" + "math/bits" f "github.com/consensys/gnark-crypto/ecc/stark-curve/fp" ) @@ -154,13 +155,13 @@ func decodeInstructionFlags(instruction *Instruction, flags uint16) error { instruction.DstRegister = Register((flags >> dstRegBit) & 1) instruction.Op0Register = Register((flags >> op0RegBit) & 1) - op1Addr, err := oneHot((flags>>op1ImmBit)&1, (flags>>op1FpBit)&1, (flags>>op1ApBit)&1) + op1Addr, err := oneHot(flags&(1<>pcJumpAbsBit)&1, (flags>>pcJumpRelBit)&1, (flags>>pcJnzBit)&1) + pcUpdate, err := oneHot(flags&(1<>resAddBit)&1, (flags>>resMulBit)&1) + res, err := oneHot(flags&(1<>apAddBit)&1, (flags>>apAdd1Bit)&1) + apUpdate, err := oneHot(flags&(1<>opcodeCallBit)&1, (flags>>opcodeRetBit)&1, (flags>>opcodeAssertEqBit)&1) + opcode, err := oneHot(flags&(1< 1 { + return 0, fmt.Errorf("decoding wrong sequence of bits: %b", bin>>offset) } - if checkSum > 1 { - return 0, fmt.Errorf("decoding wrong sequence of bits: %v", bits) + len := bits.Len16(bin) + + if len == 0 { + return maxLen, nil } - return uint16(setBit), nil + return uint16(len-int(offset)) - 1, nil }