From 16bee7a719f23fbc8c51ea09d3310bfe854aaa37 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Fri, 19 Aug 2022 14:55:22 -0400 Subject: [PATCH 01/13] deprecate stuffs, prototype SanityCheckProgram --- crypto/crypto.go | 12 +++++++++--- crypto/crypto_test.go | 10 +++++----- logic/logic.go | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/crypto/crypto.go b/crypto/crypto.go index a47c7f55..16fb5543 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -160,7 +160,7 @@ func SignBytes(sk ed25519.PrivateKey, bytesToSign []byte) (signature []byte, err return } -//VerifyBytes verifies that the signature is valid +// VerifyBytes verifies that the signature is valid func VerifyBytes(pk ed25519.PublicKey, message, signature []byte) bool { msgParts := [][]byte{bytesPrefix, message} toBeVerified := bytes.Join(msgParts, nil) @@ -462,9 +462,12 @@ func ComputeGroupID(txgroup []types.Transaction) (gid types.Digest, err error) { // multsig account). In that case, it should be the address of the delegating // account. func VerifyLogicSig(lsig types.LogicSig, singleSigner types.Address) (result bool) { - if err := logic.CheckProgram(lsig.Logic, lsig.Args); err != nil { + if err := logic.SanityCheckProgram(lsig.Logic); err != nil { return false } + //if err := logic.CheckProgram(lsig.Logic, lsig.Args); err != nil { + // return false + //} hasSig := lsig.Sig != (types.Signature{}) hasMsig := !lsig.Msig.Blank() @@ -615,9 +618,12 @@ func MakeLogicSig(program []byte, args [][]byte, sk ed25519.PrivateKey, ma Multi err = errLsigInvalidProgram return } - if err = logic.CheckProgram(program, args); err != nil { + if err = logic.SanityCheckProgram(program); err != nil { return } + //if err = logic.CheckProgram(program, args); err != nil { + // return + //} if sk == nil && ma.Blank() { lsig.Logic = program diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index f7101fac..6c5c9ba2 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -329,11 +329,11 @@ func TestMakeLogicSigBasic(t *testing.T) { require.Equal(t, lsig, lsig1) // check invalid program fails - programMod := make([]byte, len(program)) - copy(programMod[:], program) - programMod[0] = 128 - lsig, err = MakeLogicSig(programMod, args, sk, pk) - require.Error(t, err) + //programMod := make([]byte, len(program)) + //copy(programMod[:], program) + //programMod[0] = 128 + //lsig, err = MakeLogicSig(programMod, args, sk, pk) + //require.Error(t, err) } func TestMakeLogicSigSingle(t *testing.T) { diff --git a/logic/logic.go b/logic/logic.go index b3378859..698a1616 100644 --- a/logic/logic.go +++ b/logic/logic.go @@ -3,6 +3,7 @@ package logic //go:generate ./bundle_langspec_json.sh import ( + "encoding/base64" "encoding/binary" "encoding/json" "fmt" @@ -10,12 +11,14 @@ import ( "github.com/algorand/go-algorand-sdk/types" ) +// Deprecated type langSpec struct { EvalMaxVersion int LogicSigVersion int Ops []operation } +// Deprecated type operation struct { Opcode int Name string @@ -29,16 +32,31 @@ type operation struct { Group []string } +// Deprecated var spec *langSpec + +// Deprecated var opcodes []operation // CheckProgram performs basic program validation: instruction count and program cost +// Deprecated func CheckProgram(program []byte, args [][]byte) error { _, _, err := ReadProgram(program, args) return err } +func SanityCheckProgram(program []byte) error { + if _, err := base64.StdEncoding.DecodeString(string(program)); err == nil { + return fmt.Errorf("program should not be b64 encoded") + } + if _, err := types.DecodeAddress(string(program)); err == nil { + return fmt.Errorf("requesting program bytes, but get Algorand address") + } + return nil +} + // ReadProgram is used to validate a program as well as extract found variables +// Deprecated func ReadProgram(program []byte, args [][]byte) (ints []uint64, byteArrays [][]byte, err error) { const intcblockOpcode = 32 const bytecblockOpcode = 38 @@ -138,6 +156,7 @@ func ReadProgram(program []byte, args [][]byte) (ints []uint64, byteArrays [][]b return } +// Deprecated func readIntConstBlock(program []byte, pc int) (size int, ints []uint64, err error) { size = 1 numInts, bytesUsed := binary.Uvarint(program[pc+size:]) @@ -163,6 +182,7 @@ func readIntConstBlock(program []byte, pc int) (size int, ints []uint64, err err return } +// Deprecated func readByteConstBlock(program []byte, pc int) (size int, byteArrays [][]byte, err error) { size = 1 numInts, bytesUsed := binary.Uvarint(program[pc+size:]) @@ -195,6 +215,7 @@ func readByteConstBlock(program []byte, pc int) (size int, byteArrays [][]byte, return } +// Deprecated func readPushIntOp(program []byte, pc int) (size int, foundInt uint64, err error) { size = 1 foundInt, bytesUsed := binary.Uvarint(program[pc+size:]) @@ -207,6 +228,7 @@ func readPushIntOp(program []byte, pc int) (size int, foundInt uint64, err error return } +// Deprecated func readPushByteOp(program []byte, pc int) (size int, byteArray []byte, err error) { size = 1 itemLen, bytesUsed := binary.Uvarint(program[pc+size:]) From 4d5562fec9a40d67abd94d6fc1d73a9dfdad87ad Mon Sep 17 00:00:00 2001 From: Hang Su Date: Mon, 22 Aug 2022 15:09:58 -0400 Subject: [PATCH 02/13] remove commented deprecated code --- crypto/crypto.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/crypto/crypto.go b/crypto/crypto.go index 16fb5543..f143ab3a 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -465,9 +465,6 @@ func VerifyLogicSig(lsig types.LogicSig, singleSigner types.Address) (result boo if err := logic.SanityCheckProgram(lsig.Logic); err != nil { return false } - //if err := logic.CheckProgram(lsig.Logic, lsig.Args); err != nil { - // return false - //} hasSig := lsig.Sig != (types.Signature{}) hasMsig := !lsig.Msig.Blank() @@ -621,9 +618,6 @@ func MakeLogicSig(program []byte, args [][]byte, sk ed25519.PrivateKey, ma Multi if err = logic.SanityCheckProgram(program); err != nil { return } - //if err = logic.CheckProgram(program, args); err != nil { - // return - //} if sk == nil && ma.Blank() { lsig.Logic = program From 79db2477408fd5d78e5a3e8d7d5658c45dc81e3a Mon Sep 17 00:00:00 2001 From: Hang Su Date: Mon, 22 Aug 2022 15:12:23 -0400 Subject: [PATCH 03/13] docstring for sanitycheckprogram --- logic/logic.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/logic/logic.go b/logic/logic.go index 81ce7616..123d2605 100644 --- a/logic/logic.go +++ b/logic/logic.go @@ -45,6 +45,8 @@ func CheckProgram(program []byte, args [][]byte) error { return err } +// SanityCheckProgram performs heuristic program validation: +// check if passed in bytes are Algorand address or is B64 encoded, rather than Teal bytes func SanityCheckProgram(program []byte) error { if _, err := base64.StdEncoding.DecodeString(string(program)); err == nil { return fmt.Errorf("program should not be b64 encoded") From 9a9da404281223e9a040164d14b2573b95e34752 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Mon, 22 Aug 2022 15:18:45 -0400 Subject: [PATCH 04/13] detailed deprecation msg --- .test-env | 3 ++- crypto/crypto_test.go | 7 ------- logic/logic.go | 36 +++++++++++++++++++++++++++++------- test/steps_test.go | 37 ++++++++++++++++++++++++++++++++++++- test/unit.tags | 1 + 5 files changed, 68 insertions(+), 16 deletions(-) diff --git a/.test-env b/.test-env index 3b17bb19..16d51885 100644 --- a/.test-env +++ b/.test-env @@ -1,6 +1,7 @@ # Configs for testing repo download: SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing" -SDK_TESTING_BRANCH="master" +# TODO revert back to "master" after sdk-testing is merged +SDK_TESTING_BRANCH="deprecate-langspec" SDK_TESTING_HARNESS="test-harness" VERBOSE_HARNESS=0 diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index 6c5c9ba2..3da8677a 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -327,13 +327,6 @@ func TestMakeLogicSigBasic(t *testing.T) { err = msgpack.Decode(encoded, &lsig1) require.NoError(t, err) require.Equal(t, lsig, lsig1) - - // check invalid program fails - //programMod := make([]byte, len(program)) - //copy(programMod[:], program) - //programMod[0] = 128 - //lsig, err = MakeLogicSig(programMod, args, sk, pk) - //require.Error(t, err) } func TestMakeLogicSigSingle(t *testing.T) { diff --git a/logic/logic.go b/logic/logic.go index 123d2605..dde1b367 100644 --- a/logic/logic.go +++ b/logic/logic.go @@ -39,26 +39,48 @@ var spec *langSpec var opcodes []operation // CheckProgram performs basic program validation: instruction count and program cost -// Deprecated +// Deprecated: `langspec.json` can no longer correctly to depicting the cost model (as of 2022.08.22), +// also to minimize the work in updating SDKs per AVM release, we are deprecating`langspec.json` across all SDKs. +// The behavior of `CheckProgram` relies on `langspec.json`. Thus, this method is being deprecated. func CheckProgram(program []byte, args [][]byte) error { _, _, err := ReadProgram(program, args) return err } +func isAsciiPrintableByte(symbol byte) bool { + isBreakLine := symbol == '\n' + isStdPrintable := symbol >= ' ' && symbol <= '~' + return isBreakLine || isStdPrintable +} + +func isAsciiPrintable(program []byte) bool { + for _, b := range program { + if !isAsciiPrintableByte(b) { + return false + } + } + return true +} + // SanityCheckProgram performs heuristic program validation: // check if passed in bytes are Algorand address or is B64 encoded, rather than Teal bytes func SanityCheckProgram(program []byte) error { - if _, err := base64.StdEncoding.DecodeString(string(program)); err == nil { - return fmt.Errorf("program should not be b64 encoded") - } - if _, err := types.DecodeAddress(string(program)); err == nil { - return fmt.Errorf("requesting program bytes, but get Algorand address") + if isAsciiPrintable(program) { + if _, err := types.DecodeAddress(string(program)); err == nil { + return fmt.Errorf("requesting program bytes, get Algorand address") + } + if _, err := base64.StdEncoding.DecodeString(string(program)); err == nil { + return fmt.Errorf("program should not be b64 encoded") + } + return fmt.Errorf("program bytes are all ASCII printable characters, not looking like Teal byte code") } return nil } // ReadProgram is used to validate a program as well as extract found variables -// Deprecated +// Deprecated: `langspec.json` can no longer correctly to depicting the cost model (as of 2022.08.22), +// also to minimize the work in updating SDKs per AVM release, we are deprecating`langspec.json` across all SDKs. +// The behavior of `ReadProgram` relies on `langspec.json`. Thus, this method is being deprecated. func ReadProgram(program []byte, args [][]byte) (ints []uint64, byteArrays [][]byte, err error) { const intcblockOpcode = 32 const bytecblockOpcode = 38 diff --git a/test/steps_test.go b/test/steps_test.go index f5528ef2..14dd980d 100644 --- a/test/steps_test.go +++ b/test/steps_test.go @@ -107,6 +107,8 @@ var txTrace future.DryrunTxnResult var trace string var sourceMap logic.SourceMap var srcMapping map[string]interface{} +var seeminglyProgram []byte +var sanityCheckError error var assetTestFixture struct { Creator string @@ -387,7 +389,10 @@ func FeatureContext(s *godog.Suite) { s.Step(`^the resulting source map is the same as the json "([^"]*)"$`, theResultingSourceMapIsTheSameAsTheJson) s.Step(`^getting the line associated with a pc "([^"]*)" equals "([^"]*)"$`, gettingTheLineAssociatedWithAPcEquals) s.Step(`^getting the last pc associated with a line "([^"]*)" equals "([^"]*)"$`, gettingTheLastPcAssociatedWithALineEquals) - + s.Step(`^a base64 encoded program bytes for heuristic sanity check "([^"]*)"$`, takeB64encodedBytes) + s.Step(`^I start heuristic sanity check over the bytes$`, heuristicCheckOverBytes) + s.Step(`^if there exists an error, the error contains "([^"]*)"$`, checkErrorIfMatching) + s.BeforeScenario(func(interface{}) { stxObj = types.SignedTxn{} abiMethods = nil @@ -2634,3 +2639,33 @@ func theResultingSourceMapIsTheSameAsTheJson(expectedJsonPath string) error { return nil } + +func takeB64encodedBytes(b64encodedBytes string) error { + var err error + seeminglyProgram, err = base64.StdEncoding.DecodeString(b64encodedBytes) + if err != nil { + return err + } + return nil +} + +func heuristicCheckOverBytes() error { + sanityCheckError = logic.SanityCheckProgram(seeminglyProgram) + if sanityCheckError != nil { + fmt.Printf(sanityCheckError.Error()) + } + return nil +} + +func checkErrorIfMatching(errMsg string) error { + if len(errMsg) == 0 { + if sanityCheckError != nil { + return fmt.Errorf("expected err message to be empty, but sanity check says %w", sanityCheckError) + } + } else { + if sanityCheckError == nil || !strings.Contains(sanityCheckError.Error(), errMsg) { + return fmt.Errorf("expected err to contain %s, but sanity check error not matching: %w", errMsg, sanityCheckError) + } + } + return nil +} diff --git a/test/unit.tags b/test/unit.tags index 9dc6ffc2..f8384ed5 100644 --- a/test/unit.tags +++ b/test/unit.tags @@ -12,6 +12,7 @@ @unit.indexer.logs @unit.indexer.rekey @unit.offline +@unit.program_sanity_check @unit.rekey @unit.responses @unit.responses.231 From c703e265acb88c7ebed67ce02d808015623e3a0f Mon Sep 17 00:00:00 2001 From: Hang Su Date: Wed, 24 Aug 2022 15:27:22 -0400 Subject: [PATCH 05/13] add empty program check --- logic/logic.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/logic/logic.go b/logic/logic.go index dde1b367..73580759 100644 --- a/logic/logic.go +++ b/logic/logic.go @@ -65,6 +65,9 @@ func isAsciiPrintable(program []byte) bool { // SanityCheckProgram performs heuristic program validation: // check if passed in bytes are Algorand address or is B64 encoded, rather than Teal bytes func SanityCheckProgram(program []byte) error { + if len(program) == 0 { + return fmt.Errorf("empty program") + } if isAsciiPrintable(program) { if _, err := types.DecodeAddress(string(program)); err == nil { return fmt.Errorf("requesting program bytes, get Algorand address") From faee071fffd37e937ff4278c0a6992020faa3935 Mon Sep 17 00:00:00 2001 From: Hang Su <87964331+ahangsu@users.noreply.github.com> Date: Thu, 25 Aug 2022 10:20:38 -0400 Subject: [PATCH 06/13] Update logic/logic.go Co-authored-by: Michael Diamant --- logic/logic.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/logic/logic.go b/logic/logic.go index 73580759..823d53ed 100644 --- a/logic/logic.go +++ b/logic/logic.go @@ -81,8 +81,7 @@ func SanityCheckProgram(program []byte) error { } // ReadProgram is used to validate a program as well as extract found variables -// Deprecated: `langspec.json` can no longer correctly to depicting the cost model (as of 2022.08.22), -// also to minimize the work in updating SDKs per AVM release, we are deprecating`langspec.json` across all SDKs. +// Deprecated: Validation relies on metadata (`langspec.json`) that does not accurately represent opcode behavior across program versions. // The behavior of `ReadProgram` relies on `langspec.json`. Thus, this method is being deprecated. func ReadProgram(program []byte, args [][]byte) (ints []uint64, byteArrays [][]byte, err error) { const intcblockOpcode = 32 From f0b153f1bf0aa169346df2737d219fa7d47384ab Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 25 Aug 2022 10:26:39 -0400 Subject: [PATCH 07/13] deprecation msg modify --- logic/logic.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/logic/logic.go b/logic/logic.go index 823d53ed..86157dea 100644 --- a/logic/logic.go +++ b/logic/logic.go @@ -39,8 +39,7 @@ var spec *langSpec var opcodes []operation // CheckProgram performs basic program validation: instruction count and program cost -// Deprecated: `langspec.json` can no longer correctly to depicting the cost model (as of 2022.08.22), -// also to minimize the work in updating SDKs per AVM release, we are deprecating`langspec.json` across all SDKs. +// Deprecated: Validation relies on metadata (`langspec.json`) that does not accurately represent opcode behavior across program versions. // The behavior of `CheckProgram` relies on `langspec.json`. Thus, this method is being deprecated. func CheckProgram(program []byte, args [][]byte) error { _, _, err := ReadProgram(program, args) From 0c21ff3a8d57ad62f7e13b1c986f3e37280df00b Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 25 Aug 2022 11:27:00 -0400 Subject: [PATCH 08/13] more specific error checking santence --- test/steps_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/steps_test.go b/test/steps_test.go index 14dd980d..c356571b 100644 --- a/test/steps_test.go +++ b/test/steps_test.go @@ -391,7 +391,7 @@ func FeatureContext(s *godog.Suite) { s.Step(`^getting the last pc associated with a line "([^"]*)" equals "([^"]*)"$`, gettingTheLastPcAssociatedWithALineEquals) s.Step(`^a base64 encoded program bytes for heuristic sanity check "([^"]*)"$`, takeB64encodedBytes) s.Step(`^I start heuristic sanity check over the bytes$`, heuristicCheckOverBytes) - s.Step(`^if there exists an error, the error contains "([^"]*)"$`, checkErrorIfMatching) + s.Step(`^if the heuristic sanity check throws an error, the error contains "([^"]*)"$`, checkErrorIfMatching) s.BeforeScenario(func(interface{}) { stxObj = types.SignedTxn{} From a0021b67f4fc148e248251cfb2b7fa0006da5039 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 25 Aug 2022 12:49:48 -0400 Subject: [PATCH 09/13] move sanity check prog into logicsig def --- crypto/crypto.go | 43 ++++++++++++++++++++++++++++++++++++------- logic/logic.go | 34 ---------------------------------- test/steps_test.go | 2 +- 3 files changed, 37 insertions(+), 42 deletions(-) diff --git a/crypto/crypto.go b/crypto/crypto.go index f143ab3a..3229aa1a 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -5,13 +5,13 @@ import ( "crypto/rand" "crypto/sha512" "encoding/base32" + "encoding/base64" "encoding/binary" "fmt" "golang.org/x/crypto/ed25519" "github.com/algorand/go-algorand-sdk/encoding/msgpack" - "github.com/algorand/go-algorand-sdk/logic" "github.com/algorand/go-algorand-sdk/types" ) @@ -454,6 +454,39 @@ func ComputeGroupID(txgroup []types.Transaction) (gid types.Digest, err error) { /* LogicSig support */ +func isAsciiPrintableByte(symbol byte) bool { + isBreakLine := symbol == '\n' + isStdPrintable := symbol >= ' ' && symbol <= '~' + return isBreakLine || isStdPrintable +} + +func isAsciiPrintable(program []byte) bool { + for _, b := range program { + if !isAsciiPrintableByte(b) { + return false + } + } + return true +} + +// sanityCheckProgram performs heuristic program validation: +// check if passed in bytes are Algorand address or is B64 encoded, rather than Teal bytes +func sanityCheckProgram(program []byte) error { + if len(program) == 0 { + return fmt.Errorf("empty program") + } + if isAsciiPrintable(program) { + if _, err := types.DecodeAddress(string(program)); err == nil { + return fmt.Errorf("requesting program bytes, get Algorand address") + } + if _, err := base64.StdEncoding.DecodeString(string(program)); err == nil { + return fmt.Errorf("program should not be b64 encoded") + } + return fmt.Errorf("program bytes are all ASCII printable characters, not looking like Teal byte code") + } + return nil +} + // VerifyLogicSig verifies that a LogicSig contains a valid program and, if a // delegated signature is present, that the signature is valid. // @@ -462,7 +495,7 @@ func ComputeGroupID(txgroup []types.Transaction) (gid types.Digest, err error) { // multsig account). In that case, it should be the address of the delegating // account. func VerifyLogicSig(lsig types.LogicSig, singleSigner types.Address) (result bool) { - if err := logic.SanityCheckProgram(lsig.Logic); err != nil { + if err := sanityCheckProgram(lsig.Logic); err != nil { return false } @@ -611,11 +644,7 @@ func AddressFromProgram(program []byte) types.Address { // 2. If no ma provides, it returns Sig delegated LogicSig // 3. If both sk and ma specified the function returns Multisig delegated LogicSig func MakeLogicSig(program []byte, args [][]byte, sk ed25519.PrivateKey, ma MultisigAccount) (lsig types.LogicSig, err error) { - if len(program) == 0 { - err = errLsigInvalidProgram - return - } - if err = logic.SanityCheckProgram(program); err != nil { + if err = sanityCheckProgram(program); err != nil { return } diff --git a/logic/logic.go b/logic/logic.go index 86157dea..1e98768c 100644 --- a/logic/logic.go +++ b/logic/logic.go @@ -3,7 +3,6 @@ package logic //go:generate ./bundle_langspec_json.sh import ( - "encoding/base64" "encoding/binary" "encoding/json" "fmt" @@ -46,39 +45,6 @@ func CheckProgram(program []byte, args [][]byte) error { return err } -func isAsciiPrintableByte(symbol byte) bool { - isBreakLine := symbol == '\n' - isStdPrintable := symbol >= ' ' && symbol <= '~' - return isBreakLine || isStdPrintable -} - -func isAsciiPrintable(program []byte) bool { - for _, b := range program { - if !isAsciiPrintableByte(b) { - return false - } - } - return true -} - -// SanityCheckProgram performs heuristic program validation: -// check if passed in bytes are Algorand address or is B64 encoded, rather than Teal bytes -func SanityCheckProgram(program []byte) error { - if len(program) == 0 { - return fmt.Errorf("empty program") - } - if isAsciiPrintable(program) { - if _, err := types.DecodeAddress(string(program)); err == nil { - return fmt.Errorf("requesting program bytes, get Algorand address") - } - if _, err := base64.StdEncoding.DecodeString(string(program)); err == nil { - return fmt.Errorf("program should not be b64 encoded") - } - return fmt.Errorf("program bytes are all ASCII printable characters, not looking like Teal byte code") - } - return nil -} - // ReadProgram is used to validate a program as well as extract found variables // Deprecated: Validation relies on metadata (`langspec.json`) that does not accurately represent opcode behavior across program versions. // The behavior of `ReadProgram` relies on `langspec.json`. Thus, this method is being deprecated. diff --git a/test/steps_test.go b/test/steps_test.go index c356571b..b7add65e 100644 --- a/test/steps_test.go +++ b/test/steps_test.go @@ -2650,7 +2650,7 @@ func takeB64encodedBytes(b64encodedBytes string) error { } func heuristicCheckOverBytes() error { - sanityCheckError = logic.SanityCheckProgram(seeminglyProgram) + _, sanityCheckError = crypto.MakeLogicSig(seeminglyProgram, nil, nil, crypto.MultisigAccount{}) if sanityCheckError != nil { fmt.Printf(sanityCheckError.Error()) } From 2329b0e29e1131ae2a66c058d980587f34100729 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 25 Aug 2022 14:43:51 -0400 Subject: [PATCH 10/13] deprecate MakeLogicSigAccountEscrow for not applying sanity check --- crypto/account.go | 16 ++++++++++++++++ crypto/crypto.go | 5 +++-- test/steps_test.go | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crypto/account.go b/crypto/account.go index 9fb368d5..5b3dda07 100644 --- a/crypto/account.go +++ b/crypto/account.go @@ -189,6 +189,8 @@ type LogicSigAccount struct { // MakeLogicSigAccountEscrow creates a new escrow LogicSigAccount. The address // of this account will be a hash of its program. +// Deprecated: This method is deprecated for not applying basic sanity check over program bytes, +// use `MakeLogicSigAccountEscrowChecked` instead. func MakeLogicSigAccountEscrow(program []byte, args [][]byte) LogicSigAccount { return LogicSigAccount{ Lsig: types.LogicSig{ @@ -198,6 +200,20 @@ func MakeLogicSigAccountEscrow(program []byte, args [][]byte) LogicSigAccount { } } +// MakeLogicSigAccountEscrowChecked creates a new escrow LogicSigAccount. +// The address of this account will be a hash of its program. +func MakeLogicSigAccountEscrowChecked(program []byte, args [][]byte) (LogicSigAccount, error) { + if err := sanityCheckProgram(program); err != nil { + return LogicSigAccount{}, err + } + return LogicSigAccount{ + Lsig: types.LogicSig{ + Logic: program, + Args: args, + }, + }, nil +} + // MakeLogicSigAccountDelegated creates a new delegated LogicSigAccount. This // type of LogicSig has the authority to sign transactions on behalf of another // account, called the delegating account. If the delegating account is a diff --git a/crypto/crypto.go b/crypto/crypto.go index 3229aa1a..8aec7a19 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -635,8 +635,9 @@ func AddressFromProgram(program []byte) types.Address { // MakeLogicSig produces a new LogicSig signature. // -// THIS FUNCTION IS DEPRECATED. It will be removed in v2 of this library. Use -// one of MakeLogicSigAccountEscrow, MakeLogicSigAccountDelegated, or +// Deprecated: THIS FUNCTION IS DEPRECATED. +// It will be removed in v2 of this library. +// Use one of MakeLogicSigAccountEscrow, MakeLogicSigAccountDelegated, or // MakeLogicSigAccountDelegatedMsig instead. // // The function can work in three modes: diff --git a/test/steps_test.go b/test/steps_test.go index b7add65e..95aa6f54 100644 --- a/test/steps_test.go +++ b/test/steps_test.go @@ -2650,7 +2650,7 @@ func takeB64encodedBytes(b64encodedBytes string) error { } func heuristicCheckOverBytes() error { - _, sanityCheckError = crypto.MakeLogicSig(seeminglyProgram, nil, nil, crypto.MultisigAccount{}) + _, sanityCheckError = crypto.MakeLogicSigAccountEscrowChecked(seeminglyProgram, nil) if sanityCheckError != nil { fmt.Printf(sanityCheckError.Error()) } From 6884c744fb789d2ef1b0f23a7471afacccea2f2d Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 25 Aug 2022 15:55:41 -0400 Subject: [PATCH 11/13] complete codepath calling makelogicsig --- crypto/account.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/crypto/account.go b/crypto/account.go index 5b3dda07..4aead19e 100644 --- a/crypto/account.go +++ b/crypto/account.go @@ -203,15 +203,11 @@ func MakeLogicSigAccountEscrow(program []byte, args [][]byte) LogicSigAccount { // MakeLogicSigAccountEscrowChecked creates a new escrow LogicSigAccount. // The address of this account will be a hash of its program. func MakeLogicSigAccountEscrowChecked(program []byte, args [][]byte) (LogicSigAccount, error) { - if err := sanityCheckProgram(program); err != nil { + lsig, err := MakeLogicSig(program, args, nil, MultisigAccount{}) + if err != nil { return LogicSigAccount{}, err } - return LogicSigAccount{ - Lsig: types.LogicSig{ - Logic: program, - Args: args, - }, - }, nil + return LogicSigAccount{Lsig: lsig}, nil } // MakeLogicSigAccountDelegated creates a new delegated LogicSigAccount. This From 16746aca585d53c3c64fa61e3079d1add04f5a96 Mon Sep 17 00:00:00 2001 From: Hang Su <87964331+ahangsu@users.noreply.github.com> Date: Thu, 25 Aug 2022 18:50:36 -0400 Subject: [PATCH 12/13] Update .test-env --- .test-env | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.test-env b/.test-env index 16d51885..3b17bb19 100644 --- a/.test-env +++ b/.test-env @@ -1,7 +1,6 @@ # Configs for testing repo download: SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing" -# TODO revert back to "master" after sdk-testing is merged -SDK_TESTING_BRANCH="deprecate-langspec" +SDK_TESTING_BRANCH="master" SDK_TESTING_HARNESS="test-harness" VERBOSE_HARNESS=0 From 7c405922fcc9e0a5cfef68fa3feba4e3d44fc83f Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 25 Aug 2022 18:57:47 -0400 Subject: [PATCH 13/13] oops --- test/steps_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/steps_test.go b/test/steps_test.go index 95aa6f54..b35dc7bc 100644 --- a/test/steps_test.go +++ b/test/steps_test.go @@ -2651,9 +2651,6 @@ func takeB64encodedBytes(b64encodedBytes string) error { func heuristicCheckOverBytes() error { _, sanityCheckError = crypto.MakeLogicSigAccountEscrowChecked(seeminglyProgram, nil) - if sanityCheckError != nil { - fmt.Printf(sanityCheckError.Error()) - } return nil }