Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions data/transactions/logic/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,56 @@ func typeDig(ops *OpStream, args []string) (StackTypes, StackTypes) {
return anys, returns
}

func typeEquals(ops *OpStream, args []string) (StackTypes, StackTypes) {
top := len(ops.typeStack) - 1
if top >= 0 {
//Require arg0 and arg1 to have same type
return StackTypes{ops.typeStack[top], ops.typeStack[top]}, oneInt
}
return oneAny.plus(oneAny), oneInt
}

func typeDup(ops *OpStream, args []string) (StackTypes, StackTypes) {
top := len(ops.typeStack) - 1
if top >= 0 {
return StackTypes{ops.typeStack[top]}, StackTypes{ops.typeStack[top], ops.typeStack[top]}
}
return StackTypes{StackAny}, oneAny.plus(oneAny)
}

func typeDupTwo(ops *OpStream, args []string) (StackTypes, StackTypes) {
topTwo := oneAny.plus(oneAny)
top := len(ops.typeStack) - 1
if top >= 0 {
topTwo[1] = ops.typeStack[top]
if top >= 1 {
topTwo[0] = ops.typeStack[top-1]
}
}
result := topTwo.plus(topTwo)
return topTwo, result
}

func typeSelect(ops *OpStream, args []string) (StackTypes, StackTypes) {
selectArgs := twoAny.plus(oneInt)
top := len(ops.typeStack) - 1
if top >= 2 {
if ops.typeStack[top-1] == ops.typeStack[top-2] {
return selectArgs, StackTypes{ops.typeStack[top-1]}
}
}
return selectArgs, StackTypes{StackAny}
}

func typeSetBit(ops *OpStream, args []string) (StackTypes, StackTypes) {
setBitArgs := oneAny.plus(twoInts)
top := len(ops.typeStack) - 1
if top >= 2 {
return setBitArgs, StackTypes{ops.typeStack[top-2]}
}
return setBitArgs, StackTypes{StackAny}
}

func typeCover(ops *OpStream, args []string) (StackTypes, StackTypes) {
if len(args) == 0 {
return oneAny, oneAny
Expand Down
34 changes: 34 additions & 0 deletions data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,40 @@ func TestDigAsm(t *testing.T) {

}

func TestEqualsTypeCheck(t *testing.T) {
t.Parallel()
testProg(t, "int 1; byte 0x1234; ==", AssemblerMaxVersion, expect{3, "== arg 0..."})
testProg(t, "int 1; byte 0x1234; !=", AssemblerMaxVersion, expect{3, "!= arg 0..."})
testProg(t, "byte 0x1234; int 1; ==", AssemblerMaxVersion, expect{3, "== arg 0..."})
testProg(t, "byte 0x1234; int 1; !=", AssemblerMaxVersion, expect{3, "!= arg 0..."})
}

func TestDupTypeCheck(t *testing.T) {
t.Parallel()
testProg(t, "byte 0x1234; dup; int 1; +", AssemblerMaxVersion, expect{4, "+ arg 0..."})
testProg(t, "byte 0x1234; int 1; dup; +", AssemblerMaxVersion)
testProg(t, "byte 0x1234; int 1; dup2; +", AssemblerMaxVersion, expect{4, "+ arg 0..."})
testProg(t, "int 1; byte 0x1234; dup2; +", AssemblerMaxVersion, expect{4, "+ arg 1..."})

testProg(t, "byte 0x1234; int 1; dup; dig 1; len", AssemblerMaxVersion, expect{5, "len arg 0..."})
testProg(t, "int 1; byte 0x1234; dup; dig 1; !", AssemblerMaxVersion, expect{5, "! arg 0..."})

testProg(t, "byte 0x1234; int 1; dup2; dig 2; len", AssemblerMaxVersion, expect{5, "len arg 0..."})
testProg(t, "int 1; byte 0x1234; dup2; dig 2; !", AssemblerMaxVersion, expect{5, "! arg 0..."})
}

func TestSelectTypeCheck(t *testing.T) {
t.Parallel()
testProg(t, "int 1; int 2; int 3; select; len", AssemblerMaxVersion, expect{5, "len arg 0..."})
testProg(t, "byte 0x1234; byte 0x5678; int 3; select; !", AssemblerMaxVersion, expect{5, "! arg 0..."})
}

func TestSetBitTypeCheck(t *testing.T) {
t.Parallel()
testProg(t, "int 1; int 2; int 3; setbit; len", AssemblerMaxVersion, expect{5, "len arg 0..."})
testProg(t, "byte 0x1234; int 2; int 3; setbit; !", AssemblerMaxVersion, expect{5, "! arg 0..."})
}

func TestCoverAsm(t *testing.T) {
t.Parallel()
testProg(t, `int 4; byte "john"; int 5; cover 2; pop; +`, AssemblerMaxVersion)
Expand Down
4 changes: 2 additions & 2 deletions data/transactions/logic/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4064,14 +4064,14 @@ func TestAllowedOpcodesV2(t *testing.T) {
"dup2": "int 1; int 2; dup2",
"concat": "byte 0x41; dup; concat",
"substring": "byte 0x41; substring 0 1",
"substring3": "byte 0x41; dup; dup; substring3",
"substring3": "byte 0x41; int 0; int 1; substring3",
"balance": "int 1; balance",
"app_opted_in": "int 0; dup; app_opted_in",
"app_local_get": "int 0; byte 0x41; app_local_get",
"app_local_get_ex": "int 0; dup; byte 0x41; app_local_get_ex",
"app_global_get": "int 0; byte 0x41; app_global_get",
"app_global_get_ex": "int 0; byte 0x41; app_global_get_ex",
"app_local_put": "int 0; dup; byte 0x41; app_local_put",
"app_local_put": "int 0; byte 0x41; dup; app_local_put",
"app_global_put": "byte 0x41; dup; app_global_put",
"app_local_del": "int 0; byte 0x41; app_local_del",
"app_global_del": "byte 0x41; app_global_del",
Expand Down
12 changes: 6 additions & 6 deletions data/transactions/logic/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ var OpSpecs = []OpSpec{
{0x0f, ">=", opGe, asmDefault, disDefault, twoInts, oneInt, 1, modeAny, opDefault},
{0x10, "&&", opAnd, asmDefault, disDefault, twoInts, oneInt, 1, modeAny, opDefault},
{0x11, "||", opOr, asmDefault, disDefault, twoInts, oneInt, 1, modeAny, opDefault},
{0x12, "==", opEq, asmDefault, disDefault, twoAny, oneInt, 1, modeAny, opDefault},
{0x13, "!=", opNeq, asmDefault, disDefault, twoAny, oneInt, 1, modeAny, opDefault},
{0x12, "==", opEq, asmDefault, disDefault, twoAny, oneInt, 1, modeAny, stacky(typeEquals)},
{0x13, "!=", opNeq, asmDefault, disDefault, twoAny, oneInt, 1, modeAny, stacky(typeEquals)},
{0x14, "!", opNot, asmDefault, disDefault, oneInt, oneInt, 1, modeAny, opDefault},
{0x15, "len", opLen, asmDefault, disDefault, oneBytes, oneInt, 1, modeAny, opDefault},
{0x16, "itob", opItob, asmDefault, disDefault, oneInt, oneBytes, 1, modeAny, opDefault},
Expand Down Expand Up @@ -212,21 +212,21 @@ var OpSpecs = []OpSpec{
{0x43, "return", opReturn, asmDefault, disDefault, oneInt, nil, 2, modeAny, opDefault},
{0x44, "assert", opAssert, asmDefault, disDefault, oneInt, nil, 3, modeAny, opDefault},
{0x48, "pop", opPop, asmDefault, disDefault, oneAny, nil, 1, modeAny, opDefault},
{0x49, "dup", opDup, asmDefault, disDefault, oneAny, twoAny, 1, modeAny, opDefault},
{0x4a, "dup2", opDup2, asmDefault, disDefault, twoAny, twoAny.plus(twoAny), 2, modeAny, opDefault},
{0x49, "dup", opDup, asmDefault, disDefault, oneAny, twoAny, 1, modeAny, stacky(typeDup)},
{0x4a, "dup2", opDup2, asmDefault, disDefault, twoAny, twoAny.plus(twoAny), 2, modeAny, stacky(typeDupTwo)},
// There must be at least one thing on the stack for dig, but
// it would be nice if we did better checking than that.
{0x4b, "dig", opDig, asmDefault, disDefault, oneAny, twoAny, 3, modeAny, stacky(typeDig, "n")},
{0x4c, "swap", opSwap, asmDefault, disDefault, twoAny, twoAny, 3, modeAny, stacky(typeSwap)},
{0x4d, "select", opSelect, asmDefault, disDefault, twoAny.plus(oneInt), oneAny, 3, modeAny, opDefault},
{0x4d, "select", opSelect, asmDefault, disDefault, twoAny.plus(oneInt), oneAny, 3, modeAny, stacky(typeSelect)},
{0x4e, "cover", opCover, asmDefault, disDefault, oneAny, oneAny, 5, modeAny, stacky(typeCover, "n")},
{0x4f, "uncover", opUncover, asmDefault, disDefault, oneAny, oneAny, 5, modeAny, stacky(typeUncover, "n")},

{0x50, "concat", opConcat, asmDefault, disDefault, twoBytes, oneBytes, 2, modeAny, opDefault},
{0x51, "substring", opSubstring, assembleSubstring, disDefault, oneBytes, oneBytes, 2, modeAny, immediates("s", "e")},
{0x52, "substring3", opSubstring3, asmDefault, disDefault, byteIntInt, oneBytes, 2, modeAny, opDefault},
{0x53, "getbit", opGetBit, asmDefault, disDefault, anyInt, oneInt, 3, modeAny, opDefault},
{0x54, "setbit", opSetBit, asmDefault, disDefault, anyIntInt, oneAny, 3, modeAny, opDefault},
{0x54, "setbit", opSetBit, asmDefault, disDefault, anyIntInt, oneAny, 3, modeAny, stacky(typeSetBit)},
{0x55, "getbyte", opGetByte, asmDefault, disDefault, byteInt, oneInt, 3, modeAny, opDefault},
{0x56, "setbyte", opSetByte, asmDefault, disDefault, byteIntInt, oneBytes, 3, modeAny, opDefault},
{0x57, "extract", opExtract, asmDefault, disDefault, oneBytes, oneBytes, 5, modeAny, immediates("s", "l")},
Expand Down