diff --git a/.docker/wallets/wallet1.json b/.docker/wallets/wallet1.json index b464be87e..448326566 100644 --- a/.docker/wallets/wallet1.json +++ b/.docker/wallets/wallet1.json @@ -2,11 +2,11 @@ "version": "1.0", "accounts": [ { - "address": "AQyx83BYr1PkyYhZhUAogaHdhkLVHn6htY", - "key": "6PYKYQKRs758NBX4q5k6fSmduZDfEfQyoXMovQU5myKm2h5ArXuYpuMEaN", + "address": "ASW1VhcukJRrukCXRipY4BE9d9zy4mAYsR", + "key": "6PYNTeMkEZ1Q2MCqkPMgvC2kvRzH6f1sz4Sj9cGcLG4iYb43yQcpThAeap", "label": "", "contract": { - "script": "4c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc250680a906ad4", + "script": "0c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20b680a906ad4", "parameters": [ { "name": "parameter0", @@ -19,11 +19,11 @@ "isDefault": false }, { - "address": "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", - "key": "6PYKYQKRs758NBX4q5k6fSmduZDfEfQyoXMovQU5myKm2h5ArXuYpuMEaN", + "address": "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", + "key": "6PYNTeMkEZ1Q2MCqkPMgvC2kvRzH6f1sz4Sj9cGcLG4iYb43yQcpThAeap", "label": "", "contract": { - "script": "534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb", + "script": "130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb", "parameters": [ { "name": "parameter0", diff --git a/.docker/wallets/wallet1_solo.json b/.docker/wallets/wallet1_solo.json index f82d83b5b..efc26dbf5 100644 --- a/.docker/wallets/wallet1_solo.json +++ b/.docker/wallets/wallet1_solo.json @@ -2,11 +2,11 @@ "version": "1.0", "accounts": [ { - "address": "AQyx83BYr1PkyYhZhUAogaHdhkLVHn6htY", - "key": "6PYKYQKRs758NBX4q5k6fSmduZDfEfQyoXMovQU5myKm2h5ArXuYpuMEaN", + "address": "ASW1VhcukJRrukCXRipY4BE9d9zy4mAYsR", + "key": "6PYNTeMkEZ1Q2MCqkPMgvC2kvRzH6f1sz4Sj9cGcLG4iYb43yQcpThAeap", "label": "", "contract": { - "script": "4c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc250680a906ad4", + "script": "0c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20b680a906ad4", "parameters": [ { "name": "parameter0", @@ -19,11 +19,11 @@ "isDefault": false }, { - "address": "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", - "key": "6PYKYQKRs758NBX4q5k6fSmduZDfEfQyoXMovQU5myKm2h5ArXuYpuMEaN", + "address": "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", + "key": "6PYNTeMkEZ1Q2MCqkPMgvC2kvRzH6f1sz4Sj9cGcLG4iYb43yQcpThAeap", "label": "", "contract": { - "script": "534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb", + "script": "130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb", "parameters": [ { "name": "parameter0", @@ -44,11 +44,11 @@ "isDefault": false }, { - "address": "Ab3TJfgpa94yDr1WPeXpYQiChTRohBJ6T5", - "key": "6PYKYQKRs758NBX4q5k6fSmduZDfEfQyoXMovQU5myKm2h5ArXuYpuMEaN", + "address": "ANg3mmstMr7qtY8TgdKM777WSLKCNFbawM", + "key": "6PYNTeMkEZ1Q2MCqkPMgvC2kvRzH6f1sz4Sj9cGcLG4iYb43yQcpThAeap", "label": "", "contract": { - "script": "514c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc25150683073b3bb", + "script": "110c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2110b683073b3bb", "parameters": [ { "name": "parameter0", diff --git a/.docker/wallets/wallet2.json b/.docker/wallets/wallet2.json index 60cdeed6f..c50c2c414 100644 --- a/.docker/wallets/wallet2.json +++ b/.docker/wallets/wallet2.json @@ -2,11 +2,11 @@ "version": "1.0", "accounts": [ { - "address": "AdB6ayKfBRJZasiXX4JL5N2YtmxftNp1b3", - "key": "6PYXPEFeBxeDjqMiwRrSe81LnpL1cpw1WSwENJY1p4NtgSbfZPaUFy8Kkg", + "address": "Aaidx8VxYVjpD6knF8toWG7WquQjQFWcZB", + "key": "6PYMZM16cgdQ9GH5ejEPFqehuZ3Lp16W4fW7LyoBdUuVyeMeom7z8wP5QV", "label": "", "contract": { - "script": "4c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e50680a906ad4", + "script": "0c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0b680a906ad4", "parameters": [ { "name": "parameter0", @@ -19,11 +19,11 @@ "isDefault": false }, { - "address": "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", - "key": "6PYXPEFeBxeDjqMiwRrSe81LnpL1cpw1WSwENJY1p4NtgSbfZPaUFy8Kkg", + "address": "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", + "key": "6PYMZM16cgdQ9GH5ejEPFqehuZ3Lp16W4fW7LyoBdUuVyeMeom7z8wP5QV", "label": "", "contract": { - "script": "534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb", + "script": "130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb", "parameters": [ { "name": "parameter0", diff --git a/.docker/wallets/wallet3.json b/.docker/wallets/wallet3.json index 5e249f996..caa3d7b02 100644 --- a/.docker/wallets/wallet3.json +++ b/.docker/wallets/wallet3.json @@ -2,11 +2,11 @@ "version": "1.0", "accounts": [ { - "address": "AbJTkhSMjJnm2CHZbCUe5j8w2xzjDbeWM8", - "key": "6PYRHjZrvxYqrHLpXz1aP6dBnrFkkxQMCdYsJi7YDPoQnQddvRuTzKGxME", + "address": "Ae6y4Jx6rjwGu6Vtf6y1piTN3dnhCs6Gp4", + "key": "6PYSeHjvJFBn4FVccKHtaq2Hrvqa3aj9EDq5XSnWszvagRyxRmmRijqV6r", "label": "", "contract": { - "script": "4c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69950680a906ad4", + "script": "0c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6990b680a906ad4", "parameters": [ { "name": "parameter0", @@ -19,11 +19,11 @@ "isDefault": false }, { - "address": "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", - "key": "6PYRHjZrvxYqrHLpXz1aP6dBnrFkkxQMCdYsJi7YDPoQnQddvRuTzKGxME", + "address": "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", + "key": "6PYSeHjvJFBn4FVccKHtaq2Hrvqa3aj9EDq5XSnWszvagRyxRmmRijqV6r", "label": "", "contract": { - "script": "534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb", + "script": "130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb", "parameters": [ { "name": "parameter0", diff --git a/.docker/wallets/wallet4.json b/.docker/wallets/wallet4.json index 8ee67d375..a7bdd86da 100644 --- a/.docker/wallets/wallet4.json +++ b/.docker/wallets/wallet4.json @@ -2,11 +2,11 @@ "version": "1.0", "accounts": [ { - "address": "AT7C1Jno1CtJTYzA6MH8HpfYYso1RiES8q", - "key": "6PYWscJHQ76uctwuM7GRcAp6xfGjdYDKnbMtMnT6hcXxcNn7CywbQmvfSy", + "address": "ANysJU18KPh6jBBcrGby9bPAHxFmAeL1q3", + "key": "6PYNWeXTgyP88XsqDLUdjnCNHypSD8wYLURE78226LU9gYNiSGL1grjFC9", "label": "", "contract": { - "script": "4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd6250680a906ad4", + "script": "0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620b680a906ad4", "parameters": [ { "name": "parameter0", @@ -19,11 +19,11 @@ "isDefault": false }, { - "address": "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", - "key": "6PYWscJHQ76uctwuM7GRcAp6xfGjdYDKnbMtMnT6hcXxcNn7CywbQmvfSy", + "address": "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", + "key": "6PYNWeXTgyP88XsqDLUdjnCNHypSD8wYLURE78226LU9gYNiSGL1grjFC9", "label": "", "contract": { - "script": "534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb", + "script": "130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb", "parameters": [ { "name": "parameter0", diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index fdfad81d0..144c18897 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -16,9 +16,10 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/mempool" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/vm/opcode" + "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/wallet" "go.uber.org/zap" ) @@ -394,17 +395,16 @@ func (s *service) getBlockWitness(b *coreb.Block) *transaction.Witness { sort.Sort(keys.PublicKeys(pubs)) - var invoc []byte + buf := io.NewBufBinWriter() for i, j := 0, 0; i < len(pubs) && j < m; i++ { if sig, ok := sigs[pubs[i]]; ok { - invoc = append(invoc, byte(opcode.PUSHBYTES64)) - invoc = append(invoc, sig...) + emit.Bytes(buf.BinWriter, sig) j++ } } return &transaction.Witness{ - InvocationScript: invoc, + InvocationScript: buf.Bytes(), VerificationScript: verif, } } diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index 068098ce4..01699a3ed 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -11,9 +11,10 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/internal/testchain" + "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/vm/opcode" + "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" @@ -249,14 +250,14 @@ func signTx(t *testing.T, txs ...*transaction.Transaction) { for _, tx := range txs { data := tx.GetSignedPart() - var invoc []byte + buf := io.NewBufBinWriter() for _, key := range privNetKeys { signature := key.Sign(data) - invoc = append(invoc, append([]byte{byte(opcode.PUSHBYTES64)}, signature...)...) + emit.Bytes(buf.BinWriter, signature) } tx.Scripts = []transaction.Witness{{ - InvocationScript: invoc, + InvocationScript: buf.Bytes(), VerificationScript: rawScript, }} } diff --git a/pkg/consensus/payload.go b/pkg/consensus/payload.go index 4db64e298..a8bca0391 100644 --- a/pkg/consensus/payload.go +++ b/pkg/consensus/payload.go @@ -12,7 +12,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" - "github.com/nspcc-dev/neo-go/pkg/vm/opcode" + "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/pkg/errors" ) @@ -192,7 +192,9 @@ func (p *Payload) Sign(key *privateKey) error { return err } - p.Witness.InvocationScript = append([]byte{byte(opcode.PUSHBYTES64)}, sig...) + buf := io.NewBufBinWriter() + emit.Bytes(buf.BinWriter, sig) + p.Witness.InvocationScript = buf.Bytes() p.Witness.VerificationScript = key.PublicKey().GetVerificationScript() return nil diff --git a/pkg/consensus/testdata/wallet1.json b/pkg/consensus/testdata/wallet1.json index b464be87e..448326566 100644 --- a/pkg/consensus/testdata/wallet1.json +++ b/pkg/consensus/testdata/wallet1.json @@ -2,11 +2,11 @@ "version": "1.0", "accounts": [ { - "address": "AQyx83BYr1PkyYhZhUAogaHdhkLVHn6htY", - "key": "6PYKYQKRs758NBX4q5k6fSmduZDfEfQyoXMovQU5myKm2h5ArXuYpuMEaN", + "address": "ASW1VhcukJRrukCXRipY4BE9d9zy4mAYsR", + "key": "6PYNTeMkEZ1Q2MCqkPMgvC2kvRzH6f1sz4Sj9cGcLG4iYb43yQcpThAeap", "label": "", "contract": { - "script": "4c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc250680a906ad4", + "script": "0c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20b680a906ad4", "parameters": [ { "name": "parameter0", @@ -19,11 +19,11 @@ "isDefault": false }, { - "address": "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", - "key": "6PYKYQKRs758NBX4q5k6fSmduZDfEfQyoXMovQU5myKm2h5ArXuYpuMEaN", + "address": "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", + "key": "6PYNTeMkEZ1Q2MCqkPMgvC2kvRzH6f1sz4Sj9cGcLG4iYb43yQcpThAeap", "label": "", "contract": { - "script": "534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb", + "script": "130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb", "parameters": [ { "name": "parameter0", diff --git a/pkg/consensus/testdata/wallet2.json b/pkg/consensus/testdata/wallet2.json index 60cdeed6f..c50c2c414 100644 --- a/pkg/consensus/testdata/wallet2.json +++ b/pkg/consensus/testdata/wallet2.json @@ -2,11 +2,11 @@ "version": "1.0", "accounts": [ { - "address": "AdB6ayKfBRJZasiXX4JL5N2YtmxftNp1b3", - "key": "6PYXPEFeBxeDjqMiwRrSe81LnpL1cpw1WSwENJY1p4NtgSbfZPaUFy8Kkg", + "address": "Aaidx8VxYVjpD6knF8toWG7WquQjQFWcZB", + "key": "6PYMZM16cgdQ9GH5ejEPFqehuZ3Lp16W4fW7LyoBdUuVyeMeom7z8wP5QV", "label": "", "contract": { - "script": "4c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e50680a906ad4", + "script": "0c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0b680a906ad4", "parameters": [ { "name": "parameter0", @@ -19,11 +19,11 @@ "isDefault": false }, { - "address": "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", - "key": "6PYXPEFeBxeDjqMiwRrSe81LnpL1cpw1WSwENJY1p4NtgSbfZPaUFy8Kkg", + "address": "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", + "key": "6PYMZM16cgdQ9GH5ejEPFqehuZ3Lp16W4fW7LyoBdUuVyeMeom7z8wP5QV", "label": "", "contract": { - "script": "534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb", + "script": "130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb", "parameters": [ { "name": "parameter0", diff --git a/pkg/consensus/testdata/wallet3.json b/pkg/consensus/testdata/wallet3.json index 5e249f996..caa3d7b02 100644 --- a/pkg/consensus/testdata/wallet3.json +++ b/pkg/consensus/testdata/wallet3.json @@ -2,11 +2,11 @@ "version": "1.0", "accounts": [ { - "address": "AbJTkhSMjJnm2CHZbCUe5j8w2xzjDbeWM8", - "key": "6PYRHjZrvxYqrHLpXz1aP6dBnrFkkxQMCdYsJi7YDPoQnQddvRuTzKGxME", + "address": "Ae6y4Jx6rjwGu6Vtf6y1piTN3dnhCs6Gp4", + "key": "6PYSeHjvJFBn4FVccKHtaq2Hrvqa3aj9EDq5XSnWszvagRyxRmmRijqV6r", "label": "", "contract": { - "script": "4c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69950680a906ad4", + "script": "0c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6990b680a906ad4", "parameters": [ { "name": "parameter0", @@ -19,11 +19,11 @@ "isDefault": false }, { - "address": "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", - "key": "6PYRHjZrvxYqrHLpXz1aP6dBnrFkkxQMCdYsJi7YDPoQnQddvRuTzKGxME", + "address": "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", + "key": "6PYSeHjvJFBn4FVccKHtaq2Hrvqa3aj9EDq5XSnWszvagRyxRmmRijqV6r", "label": "", "contract": { - "script": "534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb", + "script": "130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb", "parameters": [ { "name": "parameter0", diff --git a/pkg/consensus/testdata/wallet4.json b/pkg/consensus/testdata/wallet4.json index 8ee67d375..a7bdd86da 100644 --- a/pkg/consensus/testdata/wallet4.json +++ b/pkg/consensus/testdata/wallet4.json @@ -2,11 +2,11 @@ "version": "1.0", "accounts": [ { - "address": "AT7C1Jno1CtJTYzA6MH8HpfYYso1RiES8q", - "key": "6PYWscJHQ76uctwuM7GRcAp6xfGjdYDKnbMtMnT6hcXxcNn7CywbQmvfSy", + "address": "ANysJU18KPh6jBBcrGby9bPAHxFmAeL1q3", + "key": "6PYNWeXTgyP88XsqDLUdjnCNHypSD8wYLURE78226LU9gYNiSGL1grjFC9", "label": "", "contract": { - "script": "4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd6250680a906ad4", + "script": "0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620b680a906ad4", "parameters": [ { "name": "parameter0", @@ -19,11 +19,11 @@ "isDefault": false }, { - "address": "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", - "key": "6PYWscJHQ76uctwuM7GRcAp6xfGjdYDKnbMtMnT6hcXxcNn7CywbQmvfSy", + "address": "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", + "key": "6PYNWeXTgyP88XsqDLUdjnCNHypSD8wYLURE78226LU9gYNiSGL1grjFC9", "label": "", "contract": { - "script": "534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb", + "script": "130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb", "parameters": [ { "name": "parameter0", diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index 773a40b8c..b2a546c9e 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -71,7 +71,7 @@ func newBlock(cfg config.ProtocolConfiguration, index uint32, prev util.Uint256, } _ = b.RebuildMerkleRoot() - invScript := make([]byte, 0) + buf := io.NewBufBinWriter() for i := 0; i < testchain.Size(); i++ { pKey := testchain.PrivateKey(i) b := b.GetSignedPart() @@ -79,10 +79,9 @@ func newBlock(cfg config.ProtocolConfiguration, index uint32, prev util.Uint256, if len(sig) != 64 { panic("wrong signature length") } - invScript = append(invScript, byte(opcode.PUSHBYTES64)) - invScript = append(invScript, sig...) + emit.Bytes(buf.BinWriter, sig) } - b.Script.InvocationScript = invScript + b.Script.InvocationScript = buf.Bytes() return b } @@ -159,7 +158,9 @@ func newDumbBlock() *block.Block { func getInvocationScript(data []byte, priv *keys.PrivateKey) []byte { signature := priv.Sign(data) - return append([]byte{byte(opcode.PUSHBYTES64)}, signature...) + buf := io.NewBufBinWriter() + emit.Bytes(buf.BinWriter, signature) + return buf.Bytes() } // This function generates "../rpc/testdata/testblocks.acc" file which contains data diff --git a/pkg/core/util.go b/pkg/core/util.go index fca65ecdc..2eeb9adea 100644 --- a/pkg/core/util.go +++ b/pkg/core/util.go @@ -45,7 +45,7 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*block.Block, error) NextConsensus: nextConsensus, Script: transaction.Witness{ InvocationScript: []byte{}, - VerificationScript: []byte{byte(opcode.PUSHT)}, + VerificationScript: []byte{byte(opcode.OLDPUSH1)}, }, } @@ -64,7 +64,7 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*block.Block, error) issueTx := transaction.NewIssueTX() // TODO NEO3.0: nonce should be constant to avoid variability of genesis block issueTx.Nonce = 0 - issueTx.Sender = hash.Hash160([]byte{byte(opcode.PUSH1)}) + issueTx.Sender = hash.Hash160([]byte{byte(opcode.OLDPUSH1)}) issueTx.Outputs = []transaction.Output{ { AssetID: governingTokenTX.Hash(), @@ -75,7 +75,7 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*block.Block, error) issueTx.Scripts = []transaction.Witness{ { InvocationScript: []byte{}, - VerificationScript: []byte{byte(opcode.PUSHT)}, + VerificationScript: []byte{byte(opcode.OLDPUSH1)}, }, } @@ -97,7 +97,7 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*block.Block, error) } func init() { - admin := hash.Hash160([]byte{byte(opcode.PUSHT)}) + admin := hash.Hash160([]byte{byte(opcode.OLDPUSH1)}) registerTX := &transaction.RegisterTX{ AssetType: transaction.GoverningToken, Name: "[{\"lang\":\"zh-CN\",\"name\":\"小蚁股\"},{\"lang\":\"en\",\"name\":\"AntShare\"}]", @@ -109,9 +109,9 @@ func init() { governingTokenTX = *transaction.NewRegisterTX(registerTX) // TODO NEO3.0: nonce should be constant to avoid variability of token hash governingTokenTX.Nonce = 0 - governingTokenTX.Sender = hash.Hash160([]byte{byte(opcode.PUSH1)}) + governingTokenTX.Sender = hash.Hash160([]byte{byte(opcode.OLDPUSH1)}) - admin = hash.Hash160([]byte{byte(opcode.PUSHF)}) + admin = hash.Hash160([]byte{0x00}) registerTX = &transaction.RegisterTX{ AssetType: transaction.UtilityToken, Name: "[{\"lang\":\"zh-CN\",\"name\":\"小蚁币\"},{\"lang\":\"en\",\"name\":\"AntCoin\"}]", @@ -122,7 +122,7 @@ func init() { utilityTokenTX = *transaction.NewRegisterTX(registerTX) // TODO NEO3.0: nonce should be constant to avoid variability of token hash utilityTokenTX.Nonce = 0 - utilityTokenTX.Sender = hash.Hash160([]byte{byte(opcode.PUSH1)}) + utilityTokenTX.Sender = hash.Hash160([]byte{byte(opcode.OLDPUSH1)}) } // GoverningTokenID returns the governing token (NEO) hash. diff --git a/pkg/core/util_test.go b/pkg/core/util_test.go index 833557877..ba870d324 100644 --- a/pkg/core/util_test.go +++ b/pkg/core/util_test.go @@ -20,14 +20,14 @@ func TestGenesisBlockMainNet(t *testing.T) { // have been changed. Consequently, hash of the genesis block has been changed. // Update expected genesis block hash for better times. // Old hash is "d42561e3d30e15be6400b6df2f328e02d2bf6354c41dce433bc57687c82144bf" - expect := "8b247d93f1f2cba80f0908c65f94c74d17bbadefc27c7afdee5b5b078ed6ed55" + expect := "931161239581bcd90b73d092483dee6b7bf2162e66df7e15c3a276a22b4c9422" assert.Equal(t, expect, block.Hash().StringLE()) } func TestGetConsensusAddressMainNet(t *testing.T) { var ( - consensusAddr = "ASwdHjdAGfmSDuZbr641W1eYFVugjByJAS" - consensusScript = "7a818ecc4582f8526e7c4271a690c04bd3b9e017" + consensusAddr = "APtiVEdLi5GEmQ8CL5RcCE7BNcsPsxeXh7" + consensusScript = "590c459950f1d83e67ee11fcef202a6ebb8b1a77" ) cfg, err := config.Load("../../config", config.ModeMainNet) diff --git a/pkg/crypto/keys/publickey.go b/pkg/crypto/keys/publickey.go index 739d86330..063995201 100644 --- a/pkg/crypto/keys/publickey.go +++ b/pkg/crypto/keys/publickey.go @@ -232,8 +232,7 @@ func (p *PublicKey) EncodeBinary(w *io.BinWriter) { func (p *PublicKey) GetVerificationScript() []byte { b := p.Bytes() buf := io.NewBufBinWriter() - emit.Instruction(buf.BinWriter, opcode.PUSHDATA1, []byte{33}) - buf.BinWriter.WriteBytes(b) + emit.Bytes(buf.BinWriter, b) emit.Opcode(buf.BinWriter, opcode.PUSHNULL) emit.Syscall(buf.BinWriter, "Neo.Crypto.ECDsaVerify") diff --git a/pkg/crypto/keys/publickey_test.go b/pkg/crypto/keys/publickey_test.go index 78f8ec787..e2e0a0da2 100644 --- a/pkg/crypto/keys/publickey_test.go +++ b/pkg/crypto/keys/publickey_test.go @@ -89,7 +89,7 @@ func TestPubkeyToAddress(t *testing.T) { pubKey, err := NewPublicKeyFromString("031ee4e73a17d8f76dc02532e2620bcb12425b33c0c9f9694cc2caa8226b68cad4") require.NoError(t, err) actual := pubKey.Address() - expected := "Ads7RRw2vS2jfRypVbMUGt22pxaDaojJHs" + expected := "AbjmXh5RXBMvzYcv7LCmUgrX4sWk1QBJMK" require.Equal(t, expected, actual) } diff --git a/pkg/internal/keytestcases/testcases.go b/pkg/internal/keytestcases/testcases.go index 6a6754cd1..640cf3701 100644 --- a/pkg/internal/keytestcases/testcases.go +++ b/pkg/internal/keytestcases/testcases.go @@ -14,28 +14,28 @@ type Ktype struct { // Arr contains a set of known keys in Ktype format. var Arr = []Ktype{ { - Address: "Ac5bo2k5rKFvYzCZaTqUG6xFe6iXuW9xQs", + Address: "AZdm8Dt15QFTrYkMYRrZsTmpx4jbeLtPFj", PrivateKey: "7d128a6d096f0c14c3a25a2b0c41cf79661bfcb4a8cc95aaaea28bde4d732344", PublicKey: "02028a99826edc0c97d18e22b6932373d908d323aa7f92656a77ec26e8861699ef", Wif: "L1QqQJnpBwbsPGAuutuzPTac8piqvbR1HRjrY5qHup48TBCBFe4g", Passphrase: "city of zion", - EncryptedWif: "6PYKSxMYzHGuiT3iK7kkeGqn3Q6hJnHUc3U3Hro2kb1rPC7G15Eg2GnqL7", + EncryptedWif: "6PYRQrhDFP6hM7Pb4cqJ7T1Erh1XabLDEs42fENU4Htvsdgt6SmShDbCLR", }, { - Address: "ATKoxGh7rytJRr96XWkvs3shMM5uiiHjhg", + Address: "AHPNXvNiGGx43DBTEs9j1z9CjYSSC11jpe", PrivateKey: "9ab7e154840daca3a2efadaf0df93cd3a5b51768c632f5433f86909d9b994a69", PublicKey: "031d8e1630ce640966967bc6d95223d21f44304133003140c3b52004dc981349c9", Wif: "L2QTooFoDFyRFTxmtiVHt5CfsXfVnexdbENGDkkrrgTTryiLsPMG", Passphrase: "我的密码", - EncryptedWif: "6PYQYBtL2kifXe3Dv96pMoPNJ2fZz8cPv2YqpHGKdfM2g5swEBUdwJqKsu", + EncryptedWif: "6PYKuvXj1Yq9ZjsVNVyNrAHVHrAqg6BLxUoTdpZX5NFkG5Akq79dPYYm7c", }, { - Address: "AbjLAUABpmvLAJv4brQ7pt4QG87qy8K75T", + Address: "AGo5guykksq8uRxfWyC8dAnTMoz62yUWcn", PrivateKey: "3edee7036b8fd9cef91de47386b191dd76db2888a553e7736bb02808932a915b", PublicKey: "02232ce8d2e2063dce0451131851d47421bfc4fc1da4db116fca5302c0756462fa", Wif: "KyKvWLZsNwBJx5j9nurHYRwhYfdQUu9tTEDsLCUHDbYBL8cHxMiG", Passphrase: "MyL33tP@33w0rd", - EncryptedWif: "6PYMbnB7h7SjueFXUMUiGptmvMXZKLALSsCnuaotBEAnmv5fXiYh7vReBA", + EncryptedWif: "6PYQUTBmYbWZukmBTuvTkbjSmz7m5XkEzsyJBk32ZhvC7AbVUpArb1yeMv", }, { Address: "xdf4UGKevVrMR1j3UkPsuoYKSC4ocoAkKx", @@ -43,7 +43,7 @@ var Arr = []Ktype{ PublicKey: "zz232ce8d2e2063dce0451131851d47421bfc4fc1da4db116fca5302c0756462fa", Wif: "zzKvWLZsNwBJx5j9nurHYRwhYfdQUu9tTEDsLCUHDbYBL8cHxMiG", Passphrase: "zzL33tP@33w0rd", - EncryptedWif: "6PYMbnB7h7SjueFXUMUiGptmvMXZKLALSsCnuaotBEAnmv5fXiYh7vReBA", + EncryptedWif: "6PYQUTBmYbWZukmBTuvTkbjSmz7m5XkEzsyJBk32ZhvC7AbVUpArb1yeMv", Invalid: true, }, } diff --git a/pkg/rpc/request/tx_builder_test.go b/pkg/rpc/request/tx_builder_test.go index ef9dcb326..f6f04958b 100644 --- a/pkg/rpc/request/tx_builder_test.go +++ b/pkg/rpc/request/tx_builder_test.go @@ -22,40 +22,40 @@ func TestInvocationScriptCreationGood(t *testing.T) { script: "676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: StringT, Value: "transfer"}}, - script: "087472616e73666572676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "0c087472616e73666572676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: NumberT, Value: 42}}, - script: "023432676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "0c023432676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{}}}, - script: "00c10161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "10c10c0161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.ByteArrayType, Value: Param{Type: StringT, Value: "50befd26fdf6e4d957c11e078b24ebce6291456f"}}}}}}, - script: "1450befd26fdf6e4d957c11e078b24ebce6291456f51c10161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "0c1450befd26fdf6e4d957c11e078b24ebce6291456f11c10c0161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.SignatureType, Value: Param{Type: StringT, Value: "4edf5005771de04619235d5a4c7a9a11bb78e008541f1da7725f654c33380a3c87e2959a025da706d7255cb3a3fa07ebe9c6559d0d9e6213c68049168eb1056f"}}}}}}, - script: "404edf5005771de04619235d5a4c7a9a11bb78e008541f1da7725f654c33380a3c87e2959a025da706d7255cb3a3fa07ebe9c6559d0d9e6213c68049168eb1056f51c10161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "0c404edf5005771de04619235d5a4c7a9a11bb78e008541f1da7725f654c33380a3c87e2959a025da706d7255cb3a3fa07ebe9c6559d0d9e6213c68049168eb1056f11c10c0161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.StringType, Value: Param{Type: StringT, Value: "50befd26fdf6e4d957c11e078b24ebce6291456f"}}}}}}, - script: "283530626566643236666466366534643935376331316530373862323465626365363239313435366651c10161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "0c283530626566643236666466366534643935376331316530373862323465626365363239313435366611c10c0161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.Hash160Type, Value: Param{Type: StringT, Value: "50befd26fdf6e4d957c11e078b24ebce6291456f"}}}}}}, - script: "146f459162ceeb248b071ec157d9e4f6fd26fdbe5051c10161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "0c146f459162ceeb248b071ec157d9e4f6fd26fdbe5011c10c0161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.Hash256Type, Value: Param{Type: StringT, Value: "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7"}}}}}}, - script: "20e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6051c10161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "0c20e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6011c10c0161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.PublicKeyType, Value: Param{Type: StringT, Value: "03c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c1"}}}}}}, - script: "2103c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c151c10161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "0c2103c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c111c10c0161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.IntegerType, Value: Param{Type: NumberT, Value: 42}}}}}}, - script: "012a51c10161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "002a11c10c0161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.BoolType, Value: Param{Type: StringT, Value: "true"}}}}}}, - script: "5151c10161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "1111c10c0161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }, { ps: Params{{Type: StringT, Value: "a"}, {Type: ArrayT, Value: []Param{{Type: FuncParamT, Value: FuncParam{Type: smartcontract.BoolType, Value: Param{Type: StringT, Value: "false"}}}}}}, - script: "0051c10161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", + script: "1011c10c0161676f459162ceeb248b071ec157d9e4f6fd26fdbe50", }} for _, ps := range paramScripts { script, err := CreateFunctionInvocationScript(contract, ps.ps) diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index bd7fc82b8..cc434a285 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -44,18 +44,18 @@ type rpcTestCase struct { check func(t *testing.T, e *executor, result interface{}) } -const testContractHash = "1b5cbfaa2e54b584d3240e38fc4bd413a65ea40c" +const testContractHash = "8bb068bca226bf013e7d19400b9d85c4eb865607" var rpcTestCases = map[string][]rpcTestCase{ "getapplicationlog": { { name: "positive", - params: `["af51984d1dbec1557c9c14d8d404ff35015e53255d53e8c7f55088a74ecc399b"]`, + params: `["66238fd4ac778326b0c151c025ee8f1c6d738e7e191820537564d2b887f3ecde"]`, result: func(e *executor) interface{} { return &result.ApplicationLog{} }, check: func(t *testing.T, e *executor, acc interface{}) { res, ok := acc.(*result.ApplicationLog) require.True(t, ok) - expectedTxHash, err := util.Uint256DecodeStringLE("af51984d1dbec1557c9c14d8d404ff35015e53255d53e8c7f55088a74ecc399b") + expectedTxHash, err := util.Uint256DecodeStringLE("66238fd4ac778326b0c151c025ee8f1c6d738e7e191820537564d2b887f3ecde") require.NoError(t, err) assert.Equal(t, expectedTxHash, res.TxHash) assert.Equal(t, 1, len(res.Executions)) @@ -404,25 +404,25 @@ var rpcTestCases = map[string][]rpcTestCase{ "getblockheader": { { name: "positive, no verbose", - params: `["ad185bb609f95fd709b6a9cce9f67ee636c4acdac9afcafb26209d922a889958"]`, + params: `["8c702625ab05236fda5763bbe168359b7747508e1387e4404217e0418846c94e"]`, result: func(e *executor) interface{} { - expected := "000000003a879986b02b0f46b6a311b74799446f1fca447c1a4ae7baa804876194669cfd14aa46a5e3e62056c842d54ea5ba480fc448c498989f505bcae9ae4364436b9dd78b9d5e010000005704000000000000d60ac443bb800fb08261e75fa5925d747d48586101fd040140fd33aaf63b15fcfb1d2ad465297e35e52e26d9049c28022fd8f4a27fca573135e539852f5093d37fc3ebb669b3ad7998c250ae7b7d073ba29aa59738f5543d844003422200411a06e5ddb5d148cd16314d9f5a66ed6d91efd6abf8d8f9757487e1066016e3c333842b90509eb05fa33f2d7adf7c270d892839f68a62b037ce1ae040452ea91701a973650958337caa1e646b06dfa63d1e6357e0bbfb9ad4cb0a74e4c2fbac23f980675c26167b720717fa95552c1f795becac1f7c1ea2be20571a9a4012125e56f2d562980b833ecc9d5e8dc12b253a591a06059a8ccf1c1850b32220c310d9376b627b3c8975f88d78ff3b08d332c8d63210f8ae9c68d87181148fc894534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb00" + expected := "000000007654fa898eba5ced6ab7a44fe1187e48b80ddd5340499fb2d312cc2fe4a6df1bb31cada0cb85914ee5bd6d11d25289a59203bf65f40232de8ffaa2bb7517f3b50a0ca05e010000005704000000000000e903736ceceeceae1806eee0e3ec61e7cce476ce01fd08010c404def65e6b379e441fe1507d6d031c874e686b854b2afe9843fda5087f76e261e282b4db232079485dcf449678e2358a3d148835b85affba4ecd08a2bf1b556fe0c406b6218df12f8a7060379daf4eed312a85be51ea2fabee826a745547141694a3f49f8a61ac63db7ece1de7fbb54ecb9c5ac244a7fcdd794c9767b4cb2637a9c840c40ebaf64e3b76299d3ccc7e48e197a09af11cc0a80bd636cdef80312c61e24eebaace44cda90d17eb3ba85cfc08079676626966c75a48631b508c39375a8181ec40c402a77786cdaa5e93f0952c834cebdab25475beee0b60fce4263d85b7395bcde993ebee884667def21b7de494097f30c14c626357683680bdbace9667cc03b0da894130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb00" return &expected }, }, { name: "positive, verbose 0", - params: `["ad185bb609f95fd709b6a9cce9f67ee636c4acdac9afcafb26209d922a889958", 0]`, + params: `["8c702625ab05236fda5763bbe168359b7747508e1387e4404217e0418846c94e", 0]`, result: func(e *executor) interface{} { - expected := "000000003a879986b02b0f46b6a311b74799446f1fca447c1a4ae7baa804876194669cfd14aa46a5e3e62056c842d54ea5ba480fc448c498989f505bcae9ae4364436b9dd78b9d5e010000005704000000000000d60ac443bb800fb08261e75fa5925d747d48586101fd040140fd33aaf63b15fcfb1d2ad465297e35e52e26d9049c28022fd8f4a27fca573135e539852f5093d37fc3ebb669b3ad7998c250ae7b7d073ba29aa59738f5543d844003422200411a06e5ddb5d148cd16314d9f5a66ed6d91efd6abf8d8f9757487e1066016e3c333842b90509eb05fa33f2d7adf7c270d892839f68a62b037ce1ae040452ea91701a973650958337caa1e646b06dfa63d1e6357e0bbfb9ad4cb0a74e4c2fbac23f980675c26167b720717fa95552c1f795becac1f7c1ea2be20571a9a4012125e56f2d562980b833ecc9d5e8dc12b253a591a06059a8ccf1c1850b32220c310d9376b627b3c8975f88d78ff3b08d332c8d63210f8ae9c68d87181148fc894534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb00" + expected := "000000007654fa898eba5ced6ab7a44fe1187e48b80ddd5340499fb2d312cc2fe4a6df1bb31cada0cb85914ee5bd6d11d25289a59203bf65f40232de8ffaa2bb7517f3b50a0ca05e010000005704000000000000e903736ceceeceae1806eee0e3ec61e7cce476ce01fd08010c404def65e6b379e441fe1507d6d031c874e686b854b2afe9843fda5087f76e261e282b4db232079485dcf449678e2358a3d148835b85affba4ecd08a2bf1b556fe0c406b6218df12f8a7060379daf4eed312a85be51ea2fabee826a745547141694a3f49f8a61ac63db7ece1de7fbb54ecb9c5ac244a7fcdd794c9767b4cb2637a9c840c40ebaf64e3b76299d3ccc7e48e197a09af11cc0a80bd636cdef80312c61e24eebaace44cda90d17eb3ba85cfc08079676626966c75a48631b508c39375a8181ec40c402a77786cdaa5e93f0952c834cebdab25475beee0b60fce4263d85b7395bcde993ebee884667def21b7de494097f30c14c626357683680bdbace9667cc03b0da894130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb00" return &expected }, }, { name: "positive, verbose !=0", - params: `["ad185bb609f95fd709b6a9cce9f67ee636c4acdac9afcafb26209d922a889958", 2]`, + params: `["8c702625ab05236fda5763bbe168359b7747508e1387e4404217e0418846c94e", 2]`, result: func(e *executor) interface{} { - hash, err := util.Uint256DecodeStringLE("ad185bb609f95fd709b6a9cce9f67ee636c4acdac9afcafb26209d922a889958") + hash, err := util.Uint256DecodeStringLE("8c702625ab05236fda5763bbe168359b7747508e1387e4404217e0418846c94e") if err != nil { panic("can not decode hash parameter") } @@ -519,7 +519,7 @@ var rpcTestCases = map[string][]rpcTestCase{ params: `["` + testchain.MultisigAddress() + `"]`, result: func(*executor) interface{} { // hash of the issueTx - h, _ := util.Uint256DecodeStringBE("4cccf8f1a4cfa9ebd9344c312f8220199ee9000f14cb951f677601d208aa5af0") + h, _ := util.Uint256DecodeStringBE("8a4711012932f4f79f9534803feab0ef85e7a313c52a36f5d56b9f8ec190bd92") amount := util.Fixed8FromInt64(1 * 8) // (endHeight - startHeight) * genAmount[0] return &result.ClaimableInfo{ Spents: []result.Claimable{ @@ -578,7 +578,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "gettransactionheight": { { name: "positive", - params: `["865469df8fab5f665b37c67de3beba832fa17b27675d4ac2eec0d60ce40f42fd"]`, + params: `["5f1e841f625d52dd3d73bbf5203f8468835353b7c476a4d367161ea959944981"]`, result: func(e *executor) interface{} { h := 1 return &h @@ -693,7 +693,7 @@ var rpcTestCases = map[string][]rpcTestCase{ check: func(t *testing.T, e *executor, inv interface{}) { res, ok := inv.(*result.Invoke) require.True(t, ok) - assert.Equal(t, "06717765727479676f459162ceeb248b071ec157d9e4f6fd26fdbe50", res.Script) + assert.Equal(t, "0c06717765727479676f459162ceeb248b071ec157d9e4f6fd26fdbe50", res.Script) assert.NotEqual(t, "", res.State) assert.NotEqual(t, 0, res.GasConsumed) }, @@ -790,7 +790,7 @@ var rpcTestCases = map[string][]rpcTestCase{ "sendrawtransaction": { { name: "positive", - params: `["8000130000006501dbe71845f26f6b4d848b034d624eeda7bbc4b00400000001d41146fbea5a066daa8ff358822fba2b5a60d0b554feccb5ee54cedbdb86315c010001f5bc5a9ac7b85a47be381260a06b5a1e7a667ce8f7d7c8baa5cfc6465571377a0030d3dec38623006501dbe71845f26f6b4d848b034d624eeda7bbc40141402ddc9a3b036932fa42df8e97f7fe713e2c673060d1d4134ce93e35da790b98bd744beb7a37d515371929f98ee2642699303856ea603d1d68fc157174aa586671294c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc250680a906ad4"]`, + params: `["80001300000075a94799633ed955dd85a8af314a5b435ab51903b00400000001eb15931b0544cbb9a283f934ab89a23e73cf90b9ca097bb327a0bcdcddf8ce2e010001f5bc5a9ac7b85a47be381260a06b5a1e7a667ce8f7d7c8baa5cfc6465571377a0030d3dec386230075a94799633ed955dd85a8af314a5b435ab5190301420c4082632495e555507a056eae951ad1893f27163dde40505340f6cf9578e20c3d7ec0c7e00f93cb2e770a7ce3e8a2910deabdd01fd966507a7a29106dd2add583ee290c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20b680a906ad4"]`, result: func(e *executor) interface{} { v := true return &v @@ -821,7 +821,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { // If you are planning to modify test chain from `testblocks.acc`, please, update param value (first block) name: "empty block", - params: `["00000000bdd51295d6e8bbfcff7d08ddfc2e8d6b509829547f8f834a259d785f88c5dd030000000000000000000000000000000000000000000000000000000000000000a78c9d5ed10000005704000000000000d60ac443bb800fb08261e75fa5925d747d48586101fd04014064132b8f90426ebc0370693a16a0bf9a334b3022fe1b0e7abbdded639892cd8ce5a222de32c90e6882b155d21da95e8b7dda4c9e2641fb605b1ea04d3b8de056405456777ba6296fe98f0c9af9364a84691f5b3c3f7a6f19ca600d02db6ba2ab019ef6cb67c0c39ee6b6c98a9e920eec592e73ac8525949fada9094368adcaa06140eb3b961953d97daedb0898da8a7d32f0a3de0eb553ef55c5ae6fe982d9442804be1b883e2d9ebcff592c4c57350acb1527a669e6bf15d560295701ed71dbaa5a4018d2accab62726b7608c8370c601f5916b5ff87e3552f1c17a06b8453037a7a20a4c3c937e002c5dbbfc1f877a9e08b401d688fca96de4aba79e92a2f7e90f9594534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb00"]`, + params: `["0000000007b57cc5c1902010f968adc0cb96c87e1a97005ee1ddc8510cf6272e812221820000000000000000000000000000000000000000000000000000000000000000db0ca05ed10000005704000000000000e903736ceceeceae1806eee0e3ec61e7cce476ce01fd08010c4050da0a5d3672a56ad442a1e58129e8df0ca4c3235e33e86b8332144a253c559a35742206f87866cfdb8f809cac8b4cc9bc901372161a7a577ed6490158c492a60c4007bb4e7776a3102c183ba8e5aec77b9a436e6629f67150a77689e25c32df427b5a4c77f2198f0554fbc1ef2f2e2605f3a84d5789a48e90883203d491172c3f0d0c4049b0a16bb1decc7673d9bdca2e3a613b1102a7774e405d3d1ce1fff276acb8d6d0eff980554792d21603b9d9b6dd50941ea3eda4efad4922b063571ea49108df0c401bb53c5d0fcf94beeb7c1f0d9d9998b7af5f29c906492d49f4650de250826926cfc2c7bdb6369139563a0ed74039c4fb69c0e63ced82fc2a2b74778c7287ca5694130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb00"]`, fail: true, }, { @@ -847,7 +847,7 @@ var rpcTestCases = map[string][]rpcTestCase{ { name: "positive", // If you are planning to modify test chain from `testblocks.acc`, please, update param value (second block) - params: `["00000000bdd51295d6e8bbfcff7d08ddfc2e8d6b509829547f8f834a259d785f88c5dd036801125aaa2b6bdaa47414006f28316315df928520e630a702e944522720ad06a78c9d5ed10000005704000000000000d60ac443bb800fb08261e75fa5925d747d48586101fd040140caf89bf82fd25e9b3d0d0fab62fbf832df753116682e23939441da868a79c5d8cf4000066130de95d184a778053a3c41cf832009add80ecb7648621de5ad63ef4060438f3f3a7744a813c9d1ebd814a2ca5d55ea86f223a56dd7f295d9d3f355687e679311656e83c014642f78e22a9c8388d880e64080e1f07de420b280e0023a4053478c1eaac15771a07506bc97d0b6f1766b8cb0d5f98ead7e5df30555ec1bb409c7e57d4e8286beeb23221a2e01273240ad74ab7ee88474812848392fdc9f8e401391d88d7a0add6d79fa9f3c5598707fc89bcb372b3e40a76d90b57f0e615c503b10b2c648df2b79f22ca949f143aaeae3a6bd4b64f666965fbc1c286c0a6dcb94534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb010000140000006501dbe71845f26f6b4d848b034d624eeda7bbc4b0040000000000014140acddd18b655f8692dd169c7dcf53923dc85cbe34852cf4220dffdfea284dbca19035dff2f8655245d51a4823719fef1228e40351213633c9b46aed79df2eaa4e294c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc250680a906ad4"]`, + params: `["0000000007b57cc5c1902010f968adc0cb96c87e1a97005ee1ddc8510cf6272e81222182d13aba8fa5e27a16382d64ce3751b9ffaa3f81f634fbd4399bf048d58e7c5c7adb0ca05ed10000005704000000000000e903736ceceeceae1806eee0e3ec61e7cce476ce01fd08010c405545b3ad5912f043ed975176ba1f02f64119f10d63385a472ecaef6aa4a2b04237946e66e74e53435a19abd59fb14dfa7d64d29a39b8655c23ed87c74d2674d70c40e6880ad9677b3b28f6c0a3c9172f8ff98dcc5ad7c78768e34481799edebcf5bbcafa583740808bf0668bdd07288b004b11f52db517ef68482e8cf1f5774ef6ba0c406ea533f7f49310e9156d7c6032fbc8a63d20777e9e850fdc0a0d3e3d9c5b9340e4d22eba14a8a1446b886a34dee437e6cfd4f2b6eed9048291610330968c225a0c401a7c49e25676aabd511bcf556970c28e530df561f89dd7d12285e848ef234273eca90a9344420ace9c84df798925d4c547ea120183ae5562b6507f55acb52c7e94130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb0100001400000075a94799633ed955dd85a8af314a5b435ab51903b004000000000001420c40b2eb026301528ce76f07caa304f26e3aaa08997e82f12a94350ec1354683d165f4a02c87f2250dae39abbf55dd9a0bd642ecbbbb17136ca2c202bc5757c1495c290c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20b680a906ad4"]`, result: func(e *executor) interface{} { v := true return &v diff --git a/pkg/rpc/server/testdata/test_contract.avm b/pkg/rpc/server/testdata/test_contract.avm index 110c81188..19a8d3404 100755 Binary files a/pkg/rpc/server/testdata/test_contract.avm and b/pkg/rpc/server/testdata/test_contract.avm differ diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index 6c280d9fe..4f28d0d7a 100644 Binary files a/pkg/rpc/server/testdata/testblocks.acc and b/pkg/rpc/server/testdata/testblocks.acc differ diff --git a/pkg/smartcontract/contract.go b/pkg/smartcontract/contract.go index 274a9e80b..6f55f08c7 100644 --- a/pkg/smartcontract/contract.go +++ b/pkg/smartcontract/contract.go @@ -26,8 +26,7 @@ func CreateMultiSigRedeemScript(m int, publicKeys keys.PublicKeys) ([]byte, erro emit.Int(buf.BinWriter, int64(m)) sort.Sort(publicKeys) for _, pubKey := range publicKeys { - emit.Instruction(buf.BinWriter, opcode.PUSHDATA1, []byte{33}) - buf.BinWriter.WriteBytes(pubKey.Bytes()) + emit.Bytes(buf.BinWriter, pubKey.Bytes()) } emit.Int(buf.BinWriter, int64(len(publicKeys))) emit.Opcode(buf.BinWriter, opcode.PUSHNULL) diff --git a/pkg/vm/context.go b/pkg/vm/context.go index 529ddc9f5..44dfcd77a 100644 --- a/pkg/vm/context.go +++ b/pkg/vm/context.go @@ -108,8 +108,8 @@ func (c *Context) Next() (opcode.Opcode, []byte, error) { case opcode.CALLE, opcode.CALLET: numtoread = 22 default: - if instr >= opcode.PUSHBYTES1 && instr <= opcode.PUSHBYTES75 { - numtoread = int(instr) + if instr <= opcode.PUSHINT256 { + numtoread = 1 << instr } else { // No parameters, can just return. return instr, nil, nil diff --git a/pkg/vm/contract_checks.go b/pkg/vm/contract_checks.go index b5f3c5c91..257d3e3ec 100644 --- a/pkg/vm/contract_checks.go +++ b/pkg/vm/contract_checks.go @@ -15,16 +15,15 @@ var ( func getNumOfThingsFromInstr(instr opcode.Opcode, param []byte) (int, bool) { var nthings int - switch instr { - case opcode.PUSH1, opcode.PUSH2, opcode.PUSH3, opcode.PUSH4, - opcode.PUSH5, opcode.PUSH6, opcode.PUSH7, opcode.PUSH8, - opcode.PUSH9, opcode.PUSH10, opcode.PUSH11, opcode.PUSH12, - opcode.PUSH13, opcode.PUSH14, opcode.PUSH15, opcode.PUSH16: + switch { + case opcode.PUSH1 <= instr && instr <= opcode.PUSH16: nthings = int(instr-opcode.PUSH1) + 1 - case opcode.PUSHBYTES1: - nthings = int(param[0]) - case opcode.PUSHBYTES2: - nthings = int(binary.LittleEndian.Uint16(param)) + case instr <= opcode.PUSHINT256: + n := emit.BytesToInt(param) + if !n.IsInt64() || n.Int64() > MaxArraySize { + return 0, false + } + nthings = int(n.Int64()) default: return 0, false } diff --git a/pkg/vm/emit/bigint.go b/pkg/vm/emit/bigint.go index fb555036c..c3fc6fb18 100644 --- a/pkg/vm/emit/bigint.go +++ b/pkg/vm/emit/bigint.go @@ -84,9 +84,13 @@ func getEffectiveSize(buf []byte, isNeg bool) int { // when n == 0. For zero is equal to empty slice in NEO3. // https://github.com/neo-project/neo-vm/blob/master/src/neo-vm/Types/Integer.cs#L16 func IntToBytes(n *big.Int) []byte { + return intToBytes(n, []byte{}) +} + +func intToBytes(n *big.Int, data []byte) []byte { sign := n.Sign() if sign == 0 { - return []byte{} + return data } var ws []big.Word @@ -95,13 +99,19 @@ func IntToBytes(n *big.Int) []byte { } else { n1 := new(big.Int).Add(n, big.NewInt(1)) if n1.Sign() == 0 { // n == -1 - return []byte{0xFF} + return append(data, 0xFF) } ws = n1.Bits() } - data := wordsToBytes(ws) + lb := len(ws) * wordSizeBytes + if c := cap(data); c < lb { + data = make([]byte, lb, lb+1) + } else { + data = data[:lb] + } + data = wordsToBytes(ws, data) size := len(data) for ; data[size-1] == 0; size-- { @@ -122,10 +132,7 @@ func IntToBytes(n *big.Int) []byte { return data } -func wordsToBytes(ws []big.Word) []byte { - lb := len(ws) * wordSizeBytes - bs := make([]byte, lb, lb+1) - +func wordsToBytes(ws []big.Word, bs []byte) []byte { if wordSizeBytes == 8 { for i := range ws { binary.LittleEndian.PutUint64(bs[i*wordSizeBytes:], uint64(ws[i])) diff --git a/pkg/vm/emit/emit.go b/pkg/vm/emit/emit.go index 411276787..4aa5ef688 100644 --- a/pkg/vm/emit/emit.go +++ b/pkg/vm/emit/emit.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "math/big" + "math/bits" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/util" @@ -32,20 +33,31 @@ func Bool(w *io.BinWriter, ok bool) { Opcode(w, opcode.PUSHF) } +func padRight(s int, buf []byte) []byte { + l := len(buf) + buf = buf[:s] + if buf[l-1]&0x80 != 0 { + for i := l; i < s; i++ { + buf[i] = 0xFF + } + } + return buf +} + // Int emits a int type to the given buffer. func Int(w *io.BinWriter, i int64) { switch { case i == -1: Opcode(w, opcode.PUSHM1) - case i == 0: - Opcode(w, opcode.PUSHF) - case i > 0 && i < 16: + case i >= 0 && i < 16: val := opcode.Opcode(int(opcode.PUSH1) - 1 + int(i)) Opcode(w, val) default: - bInt := big.NewInt(i) - val := IntToBytes(bInt) - Bytes(w, val) + buf := intToBytes(big.NewInt(i), make([]byte, 0, 32)) + // l != 0 becase of switch + padSize := byte(8 - bits.LeadingZeros8(byte(len(buf)-1))) + Opcode(w, opcode.PUSHINT8+opcode.Opcode(padSize)) + w.WriteBytes(padRight(1<= opcode.PUSHBYTES1 && op <= opcode.PUSHBYTES75 { - v.estack.PushVal(parameter) + if op <= opcode.PUSHINT256 { + v.estack.PushVal(emit.BytesToInt(parameter)) return } @@ -549,6 +550,10 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro val := int(op) - int(opcode.PUSH1) + 1 v.estack.PushVal(val) + case opcode.OLDPUSH1: + // FIXME remove this after Issue transactions will be removed + v.estack.PushVal(1) + case opcode.PUSH0: v.estack.PushVal([]byte{}) diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 758072487..6d96879dc 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -8,6 +8,7 @@ import ( "math/rand" "testing" + "github.com/nspcc-dev/neo-go/pkg/internal/random" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/emit" @@ -138,13 +139,6 @@ func TestPushBytes1to75(t *testing.T) { } } -func TestPushBytesNoParam(t *testing.T) { - prog := make([]byte, 1) - prog[0] = byte(opcode.PUSHBYTES1) - vm := load(prog) - checkVMFailed(t, vm) -} - func runVM(t *testing.T, vm *VM) { err := vm.Run() require.NoError(t, err) @@ -179,6 +173,24 @@ func TestStackLimitPUSH1Bad(t *testing.T) { checkVMFailed(t, v) } +func testPUSHINT(t *testing.T, op opcode.Opcode, parameter []byte, expected *big.Int) { + prog := append([]byte{byte(op)}, parameter...) + v := load(prog) + runVM(t, v) + require.Equal(t, 1, v.estack.Len()) + require.EqualValues(t, expected, v.estack.Pop().BigInt()) +} + +func TestPUSHINT(t *testing.T) { + for i := byte(0); i < 5; i++ { + op := opcode.PUSHINT8 + opcode.Opcode(i) + t.Run(op.String(), func(t *testing.T) { + buf := random.Bytes((8 << i) / 8) + testPUSHINT(t, op, buf, emit.BytesToInt(buf)) + }) + } +} + func TestPUSHNULL(t *testing.T) { prog := makeProgram(opcode.PUSHNULL, opcode.PUSHNULL, opcode.EQUAL) v := load(prog) @@ -220,7 +232,7 @@ func appendBigStruct(size uint16) []opcode.Opcode { } return append(prog, - opcode.PUSHBYTES2, opcode.Opcode(size), opcode.Opcode(size>>8), // LE + opcode.PUSHINT16, opcode.Opcode(size), opcode.Opcode(size>>8), // LE opcode.PACK, opcode.NEWSTRUCT, opcode.DUP, opcode.PUSH0, opcode.NEWARRAY, opcode.TOALTSTACK, opcode.DUPFROMALTSTACK, @@ -277,13 +289,6 @@ func TestStackLimit(t *testing.T) { } } -func TestPushBytesShort(t *testing.T) { - prog := make([]byte, 10) - prog[0] = byte(opcode.PUSHBYTES10) // but only 9 left in the `prog` - vm := load(prog) - checkVMFailed(t, vm) -} - func TestPushm1to16(t *testing.T) { var prog []byte for i := int(opcode.PUSHM1); i <= int(opcode.PUSH16); i++ { @@ -295,14 +300,10 @@ func TestPushm1to16(t *testing.T) { vm := load(prog) for i := int(opcode.PUSHM1); i <= int(opcode.PUSH16); i++ { - if i == 80 { - continue // nice opcode layout we got here. - } err := vm.Step() require.NoError(t, err) elem := vm.estack.Pop() - assert.IsType(t, &BigIntegerItem{}, elem.value) val := i - int(opcode.PUSH1) + 1 assert.Equal(t, elem.BigInt().Int64(), int64(val)) } @@ -716,7 +717,7 @@ func TestSerializeInterop(t *testing.T) { func callNTimes(n uint16) []byte { return makeProgram( - opcode.PUSHBYTES2, opcode.Opcode(n), opcode.Opcode(n>>8), // little-endian + opcode.PUSHINT16, opcode.Opcode(n), opcode.Opcode(n>>8), // little-endian opcode.TOALTSTACK, opcode.DUPFROMALTSTACK, opcode.JMPIF, 0x4, 0, opcode.RET, opcode.FROMALTSTACK, opcode.DEC, @@ -1391,7 +1392,7 @@ func TestPICKITEMDupArray(t *testing.T) { } func TestPICKITEMDupMap(t *testing.T) { - prog := makeProgram(opcode.DUP, opcode.PUSHBYTES1, 42, opcode.PICKITEM, opcode.ABS) + prog := makeProgram(opcode.DUP, opcode.PUSHINT8, 42, opcode.PICKITEM, opcode.ABS) vm := load(prog) m := NewMapItem() m.Add(makeStackItem([]byte{42}), makeStackItem(-1)) @@ -2036,12 +2037,12 @@ func TestOVERgood(t *testing.T) { } func TestOVERDup(t *testing.T) { - prog := makeProgram(opcode.PUSHBYTES2, 1, 0, + prog := makeProgram(opcode.PUSHDATA1, 2, 1, 0, opcode.PUSH1, opcode.OVER, opcode.PUSH1, opcode.LEFT, - opcode.PUSHBYTES1, 2, + opcode.PUSHDATA1, 1, 2, opcode.CAT) vm := load(prog) runVM(t, vm) @@ -2679,11 +2680,11 @@ func TestDupInt(t *testing.T) { } func TestDupByteArray(t *testing.T) { - prog := makeProgram(opcode.PUSHBYTES2, 1, 0, + prog := makeProgram(opcode.PUSHDATA1, 2, 1, 0, opcode.DUP, opcode.PUSH1, opcode.LEFT, - opcode.PUSHBYTES1, 2, + opcode.PUSHDATA1, 1, 2, opcode.CAT) vm := load(prog) runVM(t, vm) @@ -2707,7 +2708,7 @@ func TestDupBool(t *testing.T) { func TestSHA1(t *testing.T) { // 0x0100 hashes to 0e356ba505631fbf715758bed27d503f8b260e3a res := "0e356ba505631fbf715758bed27d503f8b260e3a" - prog := makeProgram(opcode.PUSHBYTES2, 1, 0, + prog := makeProgram(opcode.PUSHDATA1, 2, 1, 0, opcode.SHA1) vm := load(prog) runVM(t, vm) @@ -2718,7 +2719,7 @@ func TestSHA1(t *testing.T) { func TestSHA256(t *testing.T) { // 0x0100 hashes to 47dc540c94ceb704a23875c11273e16bb0b8a87aed84de911f2133568115f254 res := "47dc540c94ceb704a23875c11273e16bb0b8a87aed84de911f2133568115f254" - prog := makeProgram(opcode.PUSHBYTES2, 1, 0, + prog := makeProgram(opcode.PUSHDATA1, 2, 1, 0, opcode.SHA256) vm := load(prog) runVM(t, vm) diff --git a/pkg/wallet/account.go b/pkg/wallet/account.go index 273584259..2236e7216 100644 --- a/pkg/wallet/account.go +++ b/pkg/wallet/account.go @@ -135,7 +135,7 @@ func (a *Account) SignTx(t *transaction.Transaction) error { sign := a.privateKey.Sign(data) t.Scripts = append(t.Scripts, transaction.Witness{ - InvocationScript: append([]byte{byte(opcode.PUSHBYTES64)}, sign...), + InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, sign...), VerificationScript: a.getVerificationScript(), }) diff --git a/pkg/wallet/account_test.go b/pkg/wallet/account_test.go index 3ee38dfac..380a7d2c7 100644 --- a/pkg/wallet/account_test.go +++ b/pkg/wallet/account_test.go @@ -113,13 +113,13 @@ func TestAccount_ConvertMultisig(t *testing.T) { t.Run("1/1 multisig", func(t *testing.T) { pubs := convertPubs(t, hexs[:1]) require.NoError(t, a.ConvertMultisig(1, pubs)) - require.Equal(t, "Ab3TJfgpa94yDr1WPeXpYQiChTRohBJ6T5", a.Address) + require.Equal(t, "ANg3mmstMr7qtY8TgdKM777WSLKCNFbawM", a.Address) }) t.Run("3/4 multisig", func(t *testing.T) { pubs := convertPubs(t, hexs) require.NoError(t, a.ConvertMultisig(3, pubs)) - require.Equal(t, "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", a.Address) + require.Equal(t, "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", a.Address) }) } diff --git a/pkg/wallet/testdata/wallet1.json b/pkg/wallet/testdata/wallet1.json index b464be87e..448326566 100644 --- a/pkg/wallet/testdata/wallet1.json +++ b/pkg/wallet/testdata/wallet1.json @@ -2,11 +2,11 @@ "version": "1.0", "accounts": [ { - "address": "AQyx83BYr1PkyYhZhUAogaHdhkLVHn6htY", - "key": "6PYKYQKRs758NBX4q5k6fSmduZDfEfQyoXMovQU5myKm2h5ArXuYpuMEaN", + "address": "ASW1VhcukJRrukCXRipY4BE9d9zy4mAYsR", + "key": "6PYNTeMkEZ1Q2MCqkPMgvC2kvRzH6f1sz4Sj9cGcLG4iYb43yQcpThAeap", "label": "", "contract": { - "script": "4c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc250680a906ad4", + "script": "0c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20b680a906ad4", "parameters": [ { "name": "parameter0", @@ -19,11 +19,11 @@ "isDefault": false }, { - "address": "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", - "key": "6PYKYQKRs758NBX4q5k6fSmduZDfEfQyoXMovQU5myKm2h5ArXuYpuMEaN", + "address": "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", + "key": "6PYNTeMkEZ1Q2MCqkPMgvC2kvRzH6f1sz4Sj9cGcLG4iYb43yQcpThAeap", "label": "", "contract": { - "script": "534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb", + "script": "130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb", "parameters": [ { "name": "parameter0", diff --git a/pkg/wallet/testdata/wallet2.json b/pkg/wallet/testdata/wallet2.json index 779f5b271..7a9f98719 100644 --- a/pkg/wallet/testdata/wallet2.json +++ b/pkg/wallet/testdata/wallet2.json @@ -2,11 +2,11 @@ "version": "1.0", "accounts": [ { - "address": "AQyx83BYr1PkyYhZhUAogaHdhkLVHn6htY", - "key": "6PYKYQKRs758NBX4q5k6fSmduZDfEfQyoXMovQU5myKm2h5ArXuYpuMEaN", + "address": "ASW1VhcukJRrukCXRipY4BE9d9zy4mAYsR", + "key": "6PYNTeMkEZ1Q2MCqkPMgvC2kvRzH6f1sz4Sj9cGcLG4iYb43yQcpThAeap", "label": "", "contract": { - "script": "4c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc250680a906ad4", + "script": "0c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20b680a906ad4", "parameters": [ { "name": "parameter0", @@ -19,11 +19,11 @@ "isDefault": false }, { - "address": "AbHd9dXYUryuCvMgXRUfdR6zC2CJixS6Q6", - "key": "6PYKYQKRs758NBX4q5k6fSmduZDfEfQyoXMovQU5myKm2h5ArXuYpuMEaN", + "address": "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy", + "key": "6PYNTeMkEZ1Q2MCqkPMgvC2kvRzH6f1sz4Sj9cGcLG4iYb43yQcpThAeap", "label": "", "contract": { - "script": "534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb", + "script": "130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb", "parameters": [ { "name": "parameter0", @@ -44,11 +44,11 @@ "isDefault": false }, { - "address": "AdB6ayKfBRJZasiXX4JL5N2YtmxftNp1b3", - "key": "6PYXPEFeBxeDjqMiwRrSe81LnpL1cpw1WSwENJY1p4NtgSbfZPaUFy8Kkg", + "address": "Aaidx8VxYVjpD6knF8toWG7WquQjQFWcZB", + "key": "6PYMZM16cgdQ9GH5ejEPFqehuZ3Lp16W4fW7LyoBdUuVyeMeom7z8wP5QV", "label": "", "contract": { - "script": "4c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e50680a906ad4", + "script": "0c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0b680a906ad4", "parameters": [ { "name": "parameter0", diff --git a/pkg/wallet/wallet_test.go b/pkg/wallet/wallet_test.go index ac2951162..b159582ad 100644 --- a/pkg/wallet/wallet_test.go +++ b/pkg/wallet/wallet_test.go @@ -181,14 +181,14 @@ func TestWalletGetChangeAddress(t *testing.T) { require.NoError(t, err) sh := w1.GetChangeAddress() // No default address, the first one is used. - expected, err := address.StringToUint160("AQyx83BYr1PkyYhZhUAogaHdhkLVHn6htY") + expected, err := address.StringToUint160("ASW1VhcukJRrukCXRipY4BE9d9zy4mAYsR") require.NoError(t, err) require.Equal(t, expected, sh) w2, err := NewWalletFromFile("testdata/wallet2.json") require.NoError(t, err) sh = w2.GetChangeAddress() // Default address. - expected, err = address.StringToUint160("AdB6ayKfBRJZasiXX4JL5N2YtmxftNp1b3") + expected, err = address.StringToUint160("Aaidx8VxYVjpD6knF8toWG7WquQjQFWcZB") require.NoError(t, err) require.Equal(t, expected, sh) }