From 32da529f03993ede58786c5ea21673e29babc66b Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 25 Sep 2023 17:49:25 +0300 Subject: [PATCH 01/12] fix: prevents polkadot zero-address bug using `sr25519_verify` version 1 --- .gitattributes | 1 + .../test_data/westend/block8077850.zip | 3 + lib/runtime/wazero/imports.go | 20 +++- lib/runtime/wazero/instance_test.go | 92 +++++++++++++++++++ 4 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 lib/runtime/test_data/westend/block8077850.zip diff --git a/.gitattributes b/.gitattributes index 0c10a94057..a0384c9ffb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,4 @@ lib/runtime/test_data/kusama/ filter=lfs diff=lfs merge=lfs -text lib/runtime/test_data/polkadot/ filter=lfs diff=lfs merge=lfs -text +lib/runtime/test_data/westend/block8077850.zip filter=lfs diff=lfs merge=lfs -text diff --git a/lib/runtime/test_data/westend/block8077850.zip b/lib/runtime/test_data/westend/block8077850.zip new file mode 100644 index 0000000000..3ff85db914 --- /dev/null +++ b/lib/runtime/test_data/westend/block8077850.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3abf74e0f1078c5287ee5f7642e79771a629d892783f1772903f9b00252fb8db +size 161571390 diff --git a/lib/runtime/wazero/imports.go b/lib/runtime/wazero/imports.go index 9092e42ef1..a206609b6b 100644 --- a/lib/runtime/wazero/imports.go +++ b/lib/runtime/wazero/imports.go @@ -4,6 +4,7 @@ package wazero_runtime import ( + "bytes" "context" "crypto/rand" "encoding/binary" @@ -32,7 +33,8 @@ var ( log.AddContext("module", "wazero"), ) - noneEncoded []byte = []byte{0x00} + noneEncoded []byte = []byte{0x00} + allZeroesBytes = [32]byte{} ) const ( @@ -710,6 +712,18 @@ func ext_crypto_sr25519_verify_version_2(ctx context.Context, m api.Module, sig panic("nil runtime context") } + pubKeyBytes, ok := m.Memory().Read(key, 32) + if !ok { + panic("read overflow") + } + + // prevents Polkadot zero-address crash using + // ext_crypto_sr25519_verify_version_1 + // https://pacna.org/dot-zero-addr/ + if bytes.Equal(pubKeyBytes, allZeroesBytes[:]) { + return ext_crypto_sr25519_verify_version_1(ctx, m, sig, msg, key) + } + sigVerifier := rtCtx.SigVerifier message := read(m, msg) @@ -718,10 +732,6 @@ func ext_crypto_sr25519_verify_version_2(ctx context.Context, m api.Module, sig panic("read overflow") } - pubKeyBytes, ok := m.Memory().Read(key, 32) - if !ok { - panic("read overflow") - } pub, err := sr25519.NewPublicKey(pubKeyBytes) if err != nil { logger.Error("invalid sr25519 public key") diff --git a/lib/runtime/wazero/instance_test.go b/lib/runtime/wazero/instance_test.go index 204266e1c8..aef093e1eb 100644 --- a/lib/runtime/wazero/instance_test.go +++ b/lib/runtime/wazero/instance_test.go @@ -4,13 +4,16 @@ package wazero_runtime import ( + "archive/zip" "bytes" "encoding/json" + "io" "math/big" "os" "path/filepath" "testing" + "github.com/ChainSafe/gossamer/dot/network" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/internal/log" "github.com/ChainSafe/gossamer/lib/common" @@ -403,6 +406,79 @@ func TestInstance_BabeConfiguration_WestendRuntime_NoAuthorities(t *testing.T) { require.Equal(t, expected, cfg) } +func extractZippedState(t *testing.T, zippedFile, destPath string) { + r, err := zip.OpenReader(zippedFile) + require.NoError(t, err) + defer r.Close() + + for _, f := range r.File { + outFile, err := os.OpenFile(destPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) + require.NoError(t, err) + + defer outFile.Close() + + rc, err := f.Open() + require.NoError(t, err) + defer rc.Close() + + _, err = io.Copy(outFile, rc) + require.NoError(t, err) + + // File extracted, no need to loop further + return + } +} + +func TestInstance_ExecuteBlock_WestendRuntime_WestendBlock8077850(t *testing.T) { + stateTrieFile := t.TempDir() + "block8077850.txt" + extractZippedState(t, "../test_data/westend/block8077850.zip", stateTrieFile) + + gossTrie8077850 := newTrieFromScaledPairs(t, stateTrieFile) + expectedRoot := common.MustHexToHash("0x731cea81940165128e1ffdfc5b4207e2ad84548377899b392dc497b1c166dc1f") + + require.Equal(t, expectedRoot, gossTrie8077850.MustHash()) + + // set state to genesis state + state8077850 := storage.NewTrieState(gossTrie8077850) + cfg := Config{ + Storage: state8077850, + LogLvl: log.Critical, + } + + instance, err := NewInstanceFromTrie(gossTrie8077850, cfg) + require.NoError(t, err) + + entireBlockData := []byte{10, 145, 25, 10, 32, 11, 146, 32, 18, 124, 216, 103, 54, 86, 76, 220, 10, 81, 63, 13, 190, 172, 49, 219, 250, 166, 49, 204, 47, 60, 218, 91, 89, 65, 181, 209, 63, 18, 160, 2, 175, 118, 225, 235, 187, 192, 11, 26, 115, 129, 172, 137, 84, 115, 109, 176, 65, 229, 57, 91, 74, 154, 86, 230, 224, 93, 51, 144, 254, 16, 23, 246, 106, 8, 237, 1, 111, 188, 129, 22, 65, 72, 127, 226, 37, 135, 40, 234, 64, 215, 232, 164, 70, 159, 220, 9, 183, 227, 249, 144, 40, 62, 11, 199, 211, 38, 18, 189, 86, 196, 133, 36, 243, 107, 42, 3, 255, 158, 204, 130, 202, 177, 128, 147, 36, 24, 26, 232, 5, 88, 174, 70, 249, 227, 47, 33, 96, 213, 45, 127, 8, 6, 66, 65, 66, 69, 181, 1, 3, 2, 0, 0, 0, 13, 89, 64, 16, 0, 0, 0, 0, 46, 55, 172, 197, 232, 47, 252, 200, 169, 85, 67, 49, 172, 84, 71, 147, 147, 43, 113, 218, 251, 229, 121, 96, 2, 143, 174, 52, 166, 55, 12, 39, 239, 51, 22, 241, 206, 221, 93, 193, 69, 172, 61, 24, 22, 181, 20, 76, 140, 220, 81, 163, 198, 168, 46, 159, 195, 241, 100, 239, 244, 167, 73, 14, 142, 146, 140, 196, 160, 240, 171, 238, 170, 252, 56, 153, 149, 203, 148, 192, 135, 235, 125, 78, 140, 122, 239, 179, 79, 106, 210, 178, 80, 92, 237, 9, 5, 66, 65, 66, 69, 1, 1, 194, 5, 155, 37, 93, 12, 210, 230, 125, 30, 8, 53, 22, 207, 48, 223, 175, 199, 105, 27, 105, 114, 63, 135, 226, 130, 184, 70, 200, 181, 214, 48, 180, 113, 0, 14, 143, 141, 161, 238, 41, 46, 173, 95, 46, 46, 61, 165, 158, 197, 211, 226, 30, 191, 212, 56, 163, 240, 165, 80, 127, 161, 134, 136, 26, 11, 40, 4, 2, 0, 11, 180, 32, 39, 228, 124, 1, 26, 167, 21, 149, 42, 4, 45, 0, 64, 20, 5, 0, 0, 0, 0, 244, 88, 24, 239, 152, 25, 113, 0, 202, 96, 54, 243, 229, 247, 176, 66, 54, 123, 87, 90, 125, 109, 80, 30, 57, 113, 87, 242, 22, 250, 90, 6, 167, 193, 169, 11, 30, 11, 190, 17, 141, 28, 248, 39, 240, 91, 86, 85, 2, 81, 111, 183, 225, 140, 44, 10, 47, 95, 69, 210, 203, 202, 238, 139, 20, 5, 1, 0, 0, 0, 0, 33, 98, 139, 168, 31, 87, 75, 117, 6, 26, 244, 22, 190, 139, 12, 223, 107, 73, 99, 202, 95, 235, 164, 6, 180, 253, 7, 44, 88, 187, 98, 248, 250, 89, 254, 185, 222, 8, 226, 64, 221, 210, 198, 106, 17, 143, 158, 72, 66, 115, 125, 206, 106, 137, 117, 185, 167, 144, 251, 177, 245, 23, 138, 20, 5, 2, 0, 0, 0, 106, 138, 122, 226, 15, 122, 32, 99, 29, 154, 68, 219, 203, 80, 3, 177, 55, 70, 26, 23, 69, 60, 160, 214, 40, 70, 220, 117, 23, 17, 167, 69, 117, 156, 221, 235, 69, 22, 186, 153, 251, 233, 92, 105, 173, 64, 70, 222, 204, 211, 40, 136, 243, 212, 16, 118, 167, 159, 112, 11, 20, 44, 122, 134, 20, 5, 3, 0, 0, 0, 22, 46, 74, 193, 129, 129, 103, 15, 220, 207, 207, 9, 49, 240, 87, 51, 188, 112, 50, 29, 138, 67, 129, 110, 21, 9, 239, 80, 66, 122, 79, 50, 50, 176, 137, 44, 115, 247, 28, 124, 152, 49, 112, 156, 203, 165, 190, 247, 98, 179, 183, 26, 215, 86, 18, 94, 96, 191, 107, 149, 127, 251, 249, 133, 20, 5, 4, 0, 0, 0, 234, 214, 58, 36, 153, 250, 15, 26, 201, 14, 175, 40, 78, 98, 208, 0, 152, 54, 234, 242, 212, 186, 71, 215, 229, 59, 99, 214, 184, 164, 146, 9, 198, 3, 196, 253, 199, 29, 102, 122, 33, 195, 221, 82, 184, 82, 216, 198, 49, 219, 204, 89, 102, 197, 214, 222, 244, 207, 175, 140, 138, 139, 113, 133, 20, 5, 5, 0, 0, 0, 246, 40, 137, 18, 82, 230, 239, 122, 106, 139, 113, 21, 148, 48, 107, 247, 141, 38, 202, 235, 11, 14, 64, 202, 89, 118, 255, 77, 110, 184, 186, 3, 151, 189, 29, 44, 79, 7, 215, 104, 72, 204, 166, 217, 68, 227, 237, 97, 101, 76, 247, 26, 66, 66, 151, 201, 148, 91, 20, 118, 89, 215, 35, 139, 20, 1, 6, 0, 0, 0, 124, 240, 172, 211, 154, 161, 82, 29, 142, 120, 115, 236, 105, 225, 183, 147, 177, 104, 133, 23, 161, 38, 206, 1, 164, 169, 72, 13, 90, 222, 22, 46, 194, 185, 223, 199, 92, 198, 90, 102, 161, 165, 152, 86, 45, 97, 215, 102, 179, 217, 186, 155, 79, 52, 51, 232, 166, 169, 53, 113, 209, 185, 83, 140, 20, 5, 7, 0, 0, 0, 202, 155, 108, 121, 156, 216, 29, 53, 87, 111, 239, 92, 110, 232, 116, 18, 182, 115, 207, 1, 67, 137, 42, 186, 152, 203, 49, 71, 245, 209, 253, 44, 2, 18, 217, 156, 207, 101, 215, 114, 128, 169, 154, 188, 0, 128, 50, 244, 238, 227, 249, 67, 170, 63, 89, 157, 118, 77, 249, 56, 79, 36, 46, 138, 20, 0, 8, 0, 0, 0, 114, 132, 25, 201, 23, 39, 240, 61, 106, 167, 216, 88, 188, 46, 140, 110, 157, 186, 145, 14, 68, 66, 252, 69, 6, 183, 48, 139, 202, 111, 46, 28, 105, 48, 207, 190, 62, 146, 189, 58, 251, 185, 233, 146, 109, 59, 202, 188, 120, 217, 255, 109, 60, 107, 39, 201, 14, 81, 117, 22, 125, 140, 203, 128, 20, 5, 9, 0, 0, 0, 16, 127, 40, 188, 209, 216, 6, 113, 201, 7, 111, 14, 153, 196, 187, 28, 112, 243, 51, 109, 72, 93, 6, 72, 164, 96, 205, 154, 24, 20, 2, 38, 93, 21, 183, 126, 64, 147, 142, 150, 178, 243, 221, 192, 246, 171, 66, 191, 214, 39, 0, 65, 234, 221, 78, 85, 115, 117, 28, 105, 251, 10, 117, 139, 20, 5, 10, 0, 0, 0, 146, 222, 162, 150, 12, 209, 251, 40, 120, 174, 41, 92, 211, 115, 212, 33, 75, 170, 38, 143, 49, 55, 71, 85, 103, 127, 108, 245, 106, 49, 108, 72, 46, 30, 118, 126, 71, 216, 151, 196, 24, 150, 151, 127, 110, 27, 199, 67, 81, 116, 159, 224, 196, 53, 7, 131, 82, 56, 80, 112, 179, 19, 248, 143, 20, 5, 11, 0, 0, 0, 76, 50, 55, 68, 158, 129, 149, 202, 202, 141, 202, 228, 63, 1, 49, 166, 145, 91, 144, 219, 144, 219, 30, 204, 30, 138, 142, 221, 57, 236, 130, 74, 197, 109, 236, 1, 175, 35, 85, 136, 14, 28, 228, 45, 168, 247, 253, 63, 237, 192, 217, 217, 185, 113, 212, 83, 153, 202, 157, 211, 231, 191, 53, 138, 20, 5, 12, 0, 0, 0, 126, 60, 184, 144, 83, 77, 88, 58, 66, 43, 70, 67, 197, 141, 160, 177, 160, 80, 12, 238, 51, 77, 198, 142, 16, 224, 102, 221, 235, 69, 16, 90, 146, 178, 43, 201, 66, 69, 9, 64, 220, 35, 13, 97, 90, 90, 104, 101, 135, 171, 100, 226, 239, 59, 108, 63, 253, 250, 219, 68, 3, 37, 25, 131, 20, 5, 13, 0, 0, 0, 182, 16, 222, 207, 85, 111, 10, 81, 184, 200, 168, 158, 126, 20, 127, 40, 158, 23, 118, 10, 132, 149, 251, 73, 102, 185, 236, 91, 196, 253, 44, 114, 240, 74, 249, 125, 71, 186, 252, 213, 211, 150, 109, 105, 91, 114, 252, 62, 82, 117, 128, 186, 244, 248, 144, 254, 50, 191, 23, 17, 36, 251, 64, 136, 20, 5, 14, 0, 0, 0, 182, 164, 224, 23, 213, 126, 28, 11, 100, 170, 208, 127, 147, 246, 215, 88, 61, 175, 133, 145, 84, 187, 194, 35, 143, 212, 72, 227, 178, 59, 175, 118, 9, 54, 147, 196, 235, 236, 192, 200, 232, 183, 154, 86, 193, 21, 129, 44, 247, 70, 55, 27, 2, 151, 149, 38, 113, 143, 88, 34, 29, 99, 79, 142, 20, 5, 15, 0, 0, 0, 62, 10, 132, 250, 119, 253, 166, 252, 100, 87, 78, 115, 178, 74, 102, 43, 82, 49, 23, 55, 224, 230, 226, 101, 79, 82, 44, 69, 181, 175, 171, 92, 17, 62, 158, 155, 130, 177, 224, 179, 134, 130, 222, 125, 189, 113, 205, 249, 250, 243, 248, 84, 193, 2, 32, 95, 98, 35, 76, 120, 152, 180, 215, 131, 8, 37, 8, 0, 0, 175, 118, 225, 235, 187, 192, 11, 26, 115, 129, 172, 137, 84, 115, 109, 176, 65, 229, 57, 91, 74, 154, 86, 230, 224, 93, 51, 144, 254, 16, 23, 246, 112, 58, 90, 78, 74, 0, 214, 52, 242, 221, 240, 126, 177, 243, 248, 250, 139, 82, 218, 226, 155, 163, 8, 105, 248, 182, 174, 168, 180, 104, 8, 97, 60, 115, 174, 249, 84, 132, 133, 51, 105, 238, 134, 0, 94, 24, 147, 107, 18, 126, 249, 116, 194, 88, 78, 93, 62, 98, 58, 157, 36, 87, 255, 10, 104, 29, 99, 148, 92, 152, 71, 37, 254, 168, 212, 111, 27, 213, 114, 227, 162, 229, 22, 245, 49, 115, 253, 90, 215, 191, 164, 98, 171, 221, 8, 174, 237, 29, 46, 129, 126, 171, 165, 86, 62, 242, 251, 254, 216, 246, 50, 97, 158, 218, 162, 137, 162, 156, 94, 225, 223, 140, 80, 225, 249, 20, 195, 175, 130, 68, 145, 47, 182, 111, 47, 72, 14, 86, 228, 175, 114, 54, 181, 215, 249, 172, 165, 141, 228, 32, 162, 58, 133, 184, 160, 95, 166, 138, 111, 50, 190, 35, 181, 201, 151, 144, 174, 214, 247, 70, 205, 232, 255, 255, 160, 119, 124, 119, 170, 168, 187, 61, 124, 180, 17, 100, 181, 167, 154, 14, 115, 142, 139, 239, 247, 45, 55, 69, 197, 103, 62, 42, 114, 125, 158, 78, 15, 73, 53, 175, 254, 149, 98, 19, 30, 234, 164, 182, 181, 114, 155, 175, 123, 39, 29, 132, 36, 97, 97, 11, 59, 8, 198, 202, 156, 246, 161, 2, 113, 158, 110, 103, 198, 114, 244, 73, 251, 143, 251, 60, 230, 224, 175, 50, 54, 176, 0, 0, 0, 233, 2, 172, 105, 10, 42, 119, 74, 4, 193, 25, 40, 217, 109, 200, 49, 68, 184, 108, 147, 201, 33, 176, 158, 243, 243, 139, 196, 105, 175, 104, 197, 35, 84, 22, 38, 14, 0, 239, 164, 26, 248, 187, 41, 196, 244, 107, 253, 5, 148, 149, 209, 243, 187, 244, 18, 186, 27, 60, 225, 247, 55, 79, 116, 138, 14, 234, 84, 101, 167, 102, 213, 118, 81, 144, 175, 253, 229, 43, 41, 242, 75, 241, 89, 38, 229, 165, 84, 122, 211, 202, 124, 92, 63, 207, 95, 55, 247, 101, 172, 220, 115, 8, 6, 97, 117, 114, 97, 32, 134, 44, 32, 8, 0, 0, 0, 0, 5, 97, 117, 114, 97, 1, 1, 40, 57, 30, 247, 197, 252, 101, 55, 227, 113, 208, 156, 160, 24, 42, 92, 216, 200, 252, 99, 89, 104, 210, 134, 232, 49, 50, 126, 218, 196, 39, 78, 73, 201, 88, 216, 63, 32, 181, 239, 27, 23, 111, 180, 91, 163, 106, 162, 102, 126, 16, 73, 116, 152, 242, 235, 186, 228, 129, 139, 111, 253, 168, 141, 0, 0, 0, 0, 25, 66, 123, 0, 12, 1, 0, 160, 139, 229, 62, 216, 203, 144, 104, 17, 69, 8, 79, 40, 19, 37, 65, 98, 238, 73, 185, 234, 144, 224, 78, 98, 104, 215, 20, 97, 113, 60, 239, 66, 39, 44, 80, 81, 224, 254, 129, 109, 119, 184, 63, 28, 190, 119, 112, 238, 179, 136, 20, 233, 244, 254, 23, 203, 151, 182, 254, 203, 165, 136, 2, 134, 197, 223, 40, 200, 200, 162, 89, 231, 163, 172, 221, 191, 55, 58, 167, 77, 22, 85, 255, 73, 105, 125, 80, 231, 48, 83, 38, 139, 167, 57, 62, 106, 59, 156, 112, 90, 145, 226, 224, 201, 221, 155, 223, 122, 13, 226, 205, 123, 86, 136, 74, 191, 231, 106, 61, 132, 231, 98, 154, 73, 197, 94, 143, 1, 240, 142, 190, 26, 77, 110, 2, 244, 142, 218, 128, 63, 37, 92, 68, 234, 247, 36, 166, 156, 207, 219, 68, 93, 34, 60, 184, 52, 46, 54, 114, 5, 224, 208, 181, 28, 158, 79, 46, 188, 111, 9, 171, 140, 58, 104, 94, 167, 73, 108, 105, 9, 46, 47, 162, 237, 54, 248, 164, 11, 238, 79, 96, 140, 12, 7, 54, 8, 0, 0, 175, 118, 225, 235, 187, 192, 11, 26, 115, 129, 172, 137, 84, 115, 109, 176, 65, 229, 57, 91, 74, 154, 86, 230, 224, 93, 51, 144, 254, 16, 23, 246, 146, 152, 92, 218, 164, 118, 97, 235, 181, 172, 190, 80, 136, 159, 123, 129, 105, 31, 108, 6, 13, 240, 118, 154, 219, 73, 79, 100, 218, 62, 87, 11, 240, 240, 73, 35, 226, 192, 112, 65, 155, 19, 52, 40, 246, 195, 42, 4, 206, 47, 11, 185, 116, 228, 12, 168, 125, 32, 228, 4, 146, 10, 156, 67, 152, 173, 126, 206, 160, 177, 56, 60, 11, 212, 71, 123, 183, 130, 92, 32, 240, 189, 45, 59, 194, 110, 168, 126, 76, 166, 48, 250, 50, 223, 215, 156, 234, 4, 18, 122, 21, 42, 232, 20, 168, 183, 254, 211, 180, 175, 78, 253, 172, 39, 197, 89, 23, 92, 202, 87, 206, 182, 159, 112, 144, 45, 179, 205, 28, 21, 138, 241, 252, 127, 198, 2, 222, 167, 240, 150, 193, 91, 158, 10, 198, 144, 131, 98, 241, 180, 104, 31, 94, 2, 114, 54, 18, 40, 174, 94, 104, 19, 30, 203, 169, 164, 4, 249, 94, 239, 87, 56, 128, 183, 187, 131, 192, 226, 135, 47, 98, 139, 26, 34, 173, 63, 146, 16, 146, 183, 225, 134, 30, 168, 221, 138, 200, 100, 57, 156, 189, 187, 192, 223, 138, 33, 149, 30, 80, 24, 69, 233, 176, 177, 182, 48, 209, 125, 238, 107, 149, 97, 180, 134, 105, 11, 49, 138, 17, 233, 236, 131, 88, 50, 63, 24, 58, 218, 5, 84, 87, 101, 91, 164, 221, 29, 25, 226, 80, 26, 217, 109, 34, 91, 43, 217, 0, 0, 0, 225, 2, 181, 231, 10, 56, 62, 156, 230, 221, 14, 56, 109, 162, 136, 91, 149, 254, 181, 164, 179, 56, 209, 216, 245, 251, 211, 178, 213, 56, 49, 223, 253, 111, 121, 22, 214, 154, 192, 47, 193, 75, 27, 57, 151, 217, 92, 239, 142, 185, 134, 183, 249, 236, 22, 241, 141, 104, 3, 130, 230, 184, 211, 49, 136, 15, 69, 158, 149, 35, 4, 228, 125, 116, 200, 85, 188, 161, 117, 239, 242, 122, 231, 208, 234, 231, 170, 54, 4, 246, 141, 113, 29, 162, 14, 85, 108, 174, 238, 132, 8, 6, 97, 117, 114, 97, 32, 134, 44, 32, 8, 0, 0, 0, 0, 5, 97, 117, 114, 97, 1, 1, 108, 251, 167, 35, 120, 146, 115, 29, 12, 128, 245, 15, 82, 66, 228, 86, 200, 227, 202, 152, 108, 101, 59, 133, 134, 140, 252, 156, 212, 85, 64, 20, 27, 211, 210, 186, 167, 156, 1, 191, 25, 153, 42, 104, 192, 82, 56, 108, 105, 99, 27, 102, 248, 252, 212, 124, 86, 206, 226, 38, 6, 70, 171, 142, 0, 0, 0, 0, 25, 66, 123, 0, 8, 1, 68, 219, 120, 157, 247, 162, 60, 48, 60, 99, 72, 115, 67, 63, 153, 15, 252, 153, 199, 7, 189, 199, 58, 46, 10, 86, 41, 227, 188, 72, 246, 4, 83, 244, 105, 193, 127, 140, 227, 239, 56, 245, 124, 87, 216, 164, 166, 144, 107, 40, 176, 40, 137, 79, 33, 230, 82, 127, 181, 37, 72, 41, 147, 138, 2, 68, 49, 73, 231, 222, 99, 247, 86, 246, 67, 6, 142, 82, 1, 197, 16, 55, 77, 222, 17, 99, 110, 25, 124, 42, 177, 76, 84, 21, 232, 99, 12, 131, 15, 33, 179, 198, 109, 139, 31, 144, 213, 138, 220, 1, 65, 12, 154, 120, 6, 71, 185, 184, 44, 240, 35, 151, 253, 112, 83, 2, 91, 114, 138, 12, 3, 0, 246, 216, 92, 103, 88, 45, 98, 187, 149, 189, 55, 94, 250, 40, 99, 140, 220, 37, 229, 34, 240, 3, 41, 170, 15, 4, 77, 245, 108, 228, 167, 96, 102, 8, 237, 1, 115, 28, 234, 129, 148, 1, 101, 18, 142, 31, 253, 252, 91, 66, 7, 226, 173, 132, 84, 131, 119, 137, 155, 57, 45, 196, 151, 177, 193, 102, 220, 31, 133, 232, 162, 144, 38, 133, 83, 170, 65, 18, 246, 24, 5, 193, 167, 217, 127, 79, 125, 77, 243, 98, 31, 193, 187, 14, 26, 198, 243, 44, 131, 6, 8, 6, 66, 65, 66, 69, 181, 1, 3, 5, 0, 0, 0, 12, 89, 64, 16, 0, 0, 0, 0, 58, 102, 213, 95, 227, 27, 5, 141, 153, 63, 92, 162, 176, 229, 244, 17, 31, 226, 40, 0, 121, 158, 27, 23, 245, 67, 152, 83, 58, 113, 158, 82, 126, 103, 120, 164, 98, 178, 148, 152, 155, 46, 68, 9, 252, 128, 62, 37, 112, 183, 117, 30, 29, 147, 22, 63, 160, 179, 155, 116, 47, 204, 92, 12, 86, 79, 97, 43, 223, 216, 196, 122, 119, 152, 83, 155, 212, 73, 145, 42, 133, 106, 86, 163, 99, 39, 62, 75, 113, 54, 8, 252, 208, 202, 82, 8, 5, 66, 65, 66, 69, 1, 1, 44, 114, 48, 165, 157, 36, 194, 83, 104, 47, 128, 136, 158, 247, 92, 166, 10, 243, 174, 36, 103, 104, 100, 71, 98, 84, 109, 67, 140, 35, 132, 20, 150, 17, 47, 5, 190, 188, 210, 7, 172, 127, 20, 55, 53, 102, 190, 148, 206, 241, 116, 49, 18, 123, 195, 249, 93, 35, 126, 238, 5, 171, 233, 138, 26, 146, 1, 65, 2, 132, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 68, 211, 237, 210, 119, 8, 83, 243, 27, 94, 38, 113, 202, 174, 146, 68, 202, 114, 24, 94, 232, 254, 98, 159, 190, 53, 121, 147, 146, 233, 108, 19, 96, 143, 11, 58, 36, 149, 57, 203, 238, 189, 204, 2, 18, 234, 19, 154, 83, 105, 239, 129, 17, 85, 122, 33, 57, 48, 207, 65, 193, 218, 60, 131, 69, 1, 0, 0, 18, 2, 4, 59, 106, 39, 188, 206, 182, 164, 45, 98, 163, 168, 208, 42, 111, 13, 115, 101, 50, 21, 119, 29, 226, 67, 166, 58, 192, 72, 161, 139, 89, 218, 41, 1, 0, 0, 0, 0, 0} + blockResponseData := new(network.BlockResponseMessage) + err = blockResponseData.Decode(entireBlockData) + require.NoError(t, err) + + block := &types.Block{ + Header: *blockResponseData.BlockData[0].Header, + Body: *blockResponseData.BlockData[0].Body, + } + + exts, err := block.Body.AsEncodedExtrinsics() + require.NoError(t, err) + + expectedExtrinsics := []string{ + "0x8bea0528dc1e7b07896a36d6d2ecb86c6cccbda21064089b5212a081d8b62631", + "0xc0014ff921c3bf55333621237f3058af2d2a696bddf5f703338a7c3b11c1965f", + "0x41b93a99fee24501ddeb1cc2dcfbec938c99a3d94531c7e16b4f4e102a9df38a", + } + + bodyExtrinsicHashes := []string{} + for _, ext := range exts { + bodyExtrinsicHashes = append(bodyExtrinsicHashes, ext.Hash().String()) + } + + require.Equal(t, expectedExtrinsics, bodyExtrinsicHashes) + + _, err = instance.ExecuteBlock(block) + require.NoError(t, err) + +} + func TestInstance_BabeConfiguration_WestendRuntime_WithAuthorities(t *testing.T) { tt := trie.NewEmptyTrie() @@ -967,6 +1043,22 @@ func newTrieFromPairs(t *testing.T, filename string) *trie.Trie { return &tr } +func newTrieFromScaledPairs(t *testing.T, filename string) *trie.Trie { + data, err := os.ReadFile(filename) + require.NoError(t, err) + + decoded := make([][2][]byte, 0) + err = scale.Unmarshal(data, &decoded) + require.NoError(t, err) + + trie, err := trie.LoadFromEntries(decoded) + if err != nil { + panic(err) + } + + return trie +} + func TestInstance_TransactionPaymentCallApi_QueryCallInfo(t *testing.T) { ins := NewTestInstance(t, runtime.WESTEND_RUNTIME_v0929) tests := []struct { From 4dd700e9749cce6488d89cf50acf7d316a8864e3 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 25 Sep 2023 18:51:39 +0300 Subject: [PATCH 02/12] chore: remove giant block data --- .../test_data/westend/block8077850.zip | 3 --- lib/runtime/wazero/block8077850.yaml | 1 + lib/runtime/wazero/instance_test.go | 23 ++++++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) delete mode 100644 lib/runtime/test_data/westend/block8077850.zip create mode 100644 lib/runtime/wazero/block8077850.yaml diff --git a/lib/runtime/test_data/westend/block8077850.zip b/lib/runtime/test_data/westend/block8077850.zip deleted file mode 100644 index 3ff85db914..0000000000 --- a/lib/runtime/test_data/westend/block8077850.zip +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:3abf74e0f1078c5287ee5f7642e79771a629d892783f1772903f9b00252fb8db -size 161571390 diff --git a/lib/runtime/wazero/block8077850.yaml b/lib/runtime/wazero/block8077850.yaml new file mode 100644 index 0000000000..fde2328c3a --- /dev/null +++ b/lib/runtime/wazero/block8077850.yaml @@ -0,0 +1 @@ +blockData: "0x0a91190a200b9220127cd86736564cdc0a513f0dbeac31dbfaa631cc2f3cda5b5941b5d13f12a002af76e1ebbbc00b1a7381ac8954736db041e5395b4a9a56e6e05d3390fe1017f66a08ed016fbc811641487fe2258728ea40d7e8a4469fdc09b7e3f990283e0bc7d32612bd56c48524f36b2a03ff9ecc82cab1809324181ae80558ae46f9e32f2160d52d7f080642414245b50103020000000d594010000000002e37acc5e82ffcc8a9554331ac544793932b71dafbe57960028fae34a6370c27ef3316f1cedd5dc145ac3d1816b5144c8cdc51a3c6a82e9fc3f164eff4a7490e8e928cc4a0f0abeeaafc389995cb94c087eb7d4e8c7aefb34f6ad2b2505ced0905424142450101c2059b255d0cd2e67d1e083516cf30dfafc7691b69723f87e282b846c8b5d630b471000e8f8da1ee292ead5f2e2e3da59ec5d3e21ebfd438a3f0a5507fa186881a0b280402000bb42027e47c011aa715952a042d0040140500000000f45818ef98197100ca6036f3e5f7b042367b575a7d6d501e397157f216fa5a06a7c1a90b1e0bbe118d1cf827f05b565502516fb7e18c2c0a2f5f45d2cbcaee8b1405010000000021628ba81f574b75061af416be8b0cdf6b4963ca5feba406b4fd072c58bb62f8fa59feb9de08e240ddd2c66a118f9e4842737dce6a8975b9a790fbb1f5178a1405020000006a8a7ae20f7a20631d9a44dbcb5003b137461a17453ca0d62846dc751711a745759cddeb4516ba99fbe95c69ad4046deccd32888f3d41076a79f700b142c7a86140503000000162e4ac18181670fdccfcf0931f05733bc70321d8a43816e1509ef50427a4f3232b0892c73f71c7c9831709ccba5bef762b3b71ad756125e60bf6b957ffbf985140504000000ead63a2499fa0f1ac90eaf284e62d0009836eaf2d4ba47d7e53b63d6b8a49209c603c4fdc71d667a21c3dd52b852d8c631dbcc5966c5d6def4cfaf8c8a8b7185140505000000f628891252e6ef7a6a8b711594306bf78d26caeb0b0e40ca5976ff4d6eb8ba0397bd1d2c4f07d76848cca6d944e3ed61654cf71a424297c9945b147659d7238b1401060000007cf0acd39aa1521d8e7873ec69e1b793b1688517a126ce01a4a9480d5ade162ec2b9dfc75cc65a66a1a598562d61d766b3d9ba9b4f3433e8a6a93571d1b9538c140507000000ca9b6c799cd81d35576fef5c6ee87412b673cf0143892aba98cb3147f5d1fd2c0212d99ccf65d77280a99abc008032f4eee3f943aa3f599d764df9384f242e8a140008000000728419c91727f03d6aa7d858bc2e8c6e9dba910e4442fc4506b7308bca6f2e1c6930cfbe3e92bd3afbb9e9926d3bcabc78d9ff6d3c6b27c90e5175167d8ccb80140509000000107f28bcd1d80671c9076f0e99c4bb1c70f3336d485d0648a460cd9a181402265d15b77e40938e96b2f3ddc0f6ab42bfd6270041eadd4e5573751c69fb0a758b14050a00000092dea2960cd1fb2878ae295cd373d4214baa268f31374755677f6cf56a316c482e1e767e47d897c41896977f6e1bc74351749fe0c435078352385070b313f88f14050b0000004c3237449e8195caca8dcae43f0131a6915b90db90db1ecc1e8a8edd39ec824ac56dec01af2355880e1ce42da8f7fd3fedc0d9d9b971d45399ca9dd3e7bf358a14050c0000007e3cb890534d583a422b4643c58da0b1a0500cee334dc68e10e066ddeb45105a92b22bc942450940dc230d615a5a686587ab64e2ef3b6c3ffdfadb440325198314050d000000b610decf556f0a51b8c8a89e7e147f289e17760a8495fb4966b9ec5bc4fd2c72f04af97d47bafcd5d3966d695b72fc3e527580baf4f890fe32bf171124fb408814050e000000b6a4e017d57e1c0b64aad07f93f6d7583daf859154bbc2238fd448e3b23baf76093693c4ebecc0c8e8b79a56c115812cf746371b02979526718f58221d634f8e14050f0000003e0a84fa77fda6fc64574e73b24a662b52311737e0e6e2654f522c45b5afab5c113e9e9b82b1e0b38682de7dbd71cdf9faf3f854c102205f62234c7898b4d7830825080000af76e1ebbbc00b1a7381ac8954736db041e5395b4a9a56e6e05d3390fe1017f6703a5a4e4a00d634f2ddf07eb1f3f8fa8b52dae29ba30869f8b6aea8b46808613c73aef95484853369ee86005e18936b127ef974c2584e5d3e623a9d2457ff0a681d63945c984725fea8d46f1bd572e3a2e516f53173fd5ad7bfa462abdd08aeed1d2e817eaba5563ef2fbfed8f632619edaa289a29c5ee1df8c50e1f914c3af8244912fb66f2f480e56e4af7236b5d7f9aca58de420a23a85b8a05fa68a6f32be23b5c99790aed6f746cde8ffffa0777c77aaa8bb3d7cb41164b5a79a0e738e8beff72d3745c5673e2a727d9e4e0f4935affe9562131eeaa4b6b5729baf7b271d842461610b3b08c6ca9cf6a102719e6e67c672f449fb8ffb3ce6e0af3236b0000000e902ac690a2a774a04c11928d96dc83144b86c93c921b09ef3f38bc469af68c5235416260e00efa41af8bb29c4f46bfd059495d1f3bbf412ba1b3ce1f7374f748a0eea5465a766d5765190affde52b29f24bf15926e5a5547ad3ca7c5c3fcf5f37f765acdc7308066175726120862c2008000000000561757261010128391ef7c5fc6537e371d09ca0182a5cd8c8fc635968d286e831327edac4274e49c958d83f20b5ef1b176fb45ba36aa2667e10497498f2ebbae4818b6ffda88d0000000019427b000c0100a08be53ed8cb90681145084f2813254162ee49b9ea90e04e6268d71461713cef42272c5051e0fe816d77b83f1cbe7770eeb38814e9f4fe17cb97b6fecba5880286c5df28c8c8a259e7a3acddbf373aa74d1655ff49697d50e73053268ba7393e6a3b9c705a91e2e0c9dd9bdf7a0de2cd7b56884abfe76a3d84e7629a49c55e8f01f08ebe1a4d6e02f48eda803f255c44eaf724a69ccfdb445d223cb8342e367205e0d0b51c9e4f2ebc6f09ab8c3a685ea7496c69092e2fa2ed36f8a40bee4f608c0c0736080000af76e1ebbbc00b1a7381ac8954736db041e5395b4a9a56e6e05d3390fe1017f692985cdaa47661ebb5acbe50889f7b81691f6c060df0769adb494f64da3e570bf0f04923e2c070419b133428f6c32a04ce2f0bb974e40ca87d20e404920a9c4398ad7ecea0b1383c0bd4477bb7825c20f0bd2d3bc26ea87e4ca630fa32dfd79cea04127a152ae814a8b7fed3b4af4efdac27c559175cca57ceb69f70902db3cd1c158af1fc7fc602dea7f096c15b9e0ac6908362f1b4681f5e0272361228ae5e68131ecba9a404f95eef573880b7bb83c0e2872f628b1a22ad3f921092b7e1861ea8dd8ac864399cbdbbc0df8a21951e501845e9b0b1b630d17dee6b9561b486690b318a11e9ec8358323f183ada055457655ba4dd1d19e2501ad96d225b2bd9000000e102b5e70a383e9ce6dd0e386da2885b95feb5a4b338d1d8f5fbd3b2d53831dffd6f7916d69ac02fc14b1b3997d95cef8eb986b7f9ec16f18d680382e6b8d331880f459e952304e47d74c855bca175eff27ae7d0eae7aa3604f68d711da20e556caeee8408066175726120862c200800000000056175726101016cfba7237892731d0c80f50f5242e456c8e3ca986c653b85868cfc9cd45540141bd3d2baa79c01bf19992a68c052386c69631b66f8fcd47c56cee2260646ab8e0000000019427b00080144db789df7a23c303c634873433f990ffc99c707bdc73a2e0a5629e3bc48f60453f469c17f8ce3ef38f57c57d8a4a6906b28b028894f21e6527fb5254829938a02443149e7de63f756f643068e5201c510374dde11636e197c2ab14c5415e8630c830f21b3c66d8b1f90d58adc01410c9a780647b9b82cf02397fd7053025b728a0c0300f6d85c67582d62bb95bd375efa28638cdc25e522f00329aa0f044df56ce4a7606608ed01731cea81940165128e1ffdfc5b4207e2ad84548377899b392dc497b1c166dc1f85e8a290268553aa4112f61805c1a7d97f4f7d4df3621fc1bb0e1ac6f32c8306080642414245b50103050000000c594010000000003a66d55fe31b058d993f5ca2b0e5f4111fe22800799e1b17f54398533a719e527e6778a462b294989b2e4409fc803e2570b7751e1d93163fa0b39b742fcc5c0c564f612bdfd8c47a7798539bd449912a856a56a363273e4b713608fcd0ca5208054241424501012c7230a59d24c253682f80889ef75ca60af3ae246768644762546d438c23841496112f05bebcd207ac7f14373566be94cef17431127bc3f95d237eee05abe98a1a92014102840000000000000000000000000000000000000000000000000000000000000000000144d3edd2770853f31b5e2671caae9244ca72185ee8fe629fbe35799392e96c13608f0b3a249539cbeebdcc0212ea139a5369ef8111557a213930cf41c1da3c83450100001202043b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29010000000000" diff --git a/lib/runtime/wazero/instance_test.go b/lib/runtime/wazero/instance_test.go index aef093e1eb..1a5314a59f 100644 --- a/lib/runtime/wazero/instance_test.go +++ b/lib/runtime/wazero/instance_test.go @@ -4,6 +4,9 @@ package wazero_runtime import ( + _ "embed" + "fmt" + "archive/zip" "bytes" "encoding/json" @@ -26,11 +29,15 @@ import ( "github.com/ChainSafe/gossamer/lib/utils" "github.com/ChainSafe/gossamer/pkg/scale" "github.com/centrifuge/go-substrate-rpc-client/v4/signature" + "gopkg.in/yaml.v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) +//go:embed block8077850.yaml +var block8077850 []byte + func mustHexTo64BArray(t *testing.T, inputHex string) (outputArray [64]byte) { t.Helper() copy(outputArray[:], common.MustHexToBytes(inputHex)) @@ -430,8 +437,8 @@ func extractZippedState(t *testing.T, zippedFile, destPath string) { } func TestInstance_ExecuteBlock_WestendRuntime_WestendBlock8077850(t *testing.T) { - stateTrieFile := t.TempDir() + "block8077850.txt" - extractZippedState(t, "../test_data/westend/block8077850.zip", stateTrieFile) + stateTrieFile := t.TempDir() + "state_block8077850.txt" + extractZippedState(t, "../test_data/westend/state_block8077850.zip", stateTrieFile) gossTrie8077850 := newTrieFromScaledPairs(t, stateTrieFile) expectedRoot := common.MustHexToHash("0x731cea81940165128e1ffdfc5b4207e2ad84548377899b392dc497b1c166dc1f") @@ -448,7 +455,17 @@ func TestInstance_ExecuteBlock_WestendRuntime_WestendBlock8077850(t *testing.T) instance, err := NewInstanceFromTrie(gossTrie8077850, cfg) require.NoError(t, err) - entireBlockData := []byte{10, 145, 25, 10, 32, 11, 146, 32, 18, 124, 216, 103, 54, 86, 76, 220, 10, 81, 63, 13, 190, 172, 49, 219, 250, 166, 49, 204, 47, 60, 218, 91, 89, 65, 181, 209, 63, 18, 160, 2, 175, 118, 225, 235, 187, 192, 11, 26, 115, 129, 172, 137, 84, 115, 109, 176, 65, 229, 57, 91, 74, 154, 86, 230, 224, 93, 51, 144, 254, 16, 23, 246, 106, 8, 237, 1, 111, 188, 129, 22, 65, 72, 127, 226, 37, 135, 40, 234, 64, 215, 232, 164, 70, 159, 220, 9, 183, 227, 249, 144, 40, 62, 11, 199, 211, 38, 18, 189, 86, 196, 133, 36, 243, 107, 42, 3, 255, 158, 204, 130, 202, 177, 128, 147, 36, 24, 26, 232, 5, 88, 174, 70, 249, 227, 47, 33, 96, 213, 45, 127, 8, 6, 66, 65, 66, 69, 181, 1, 3, 2, 0, 0, 0, 13, 89, 64, 16, 0, 0, 0, 0, 46, 55, 172, 197, 232, 47, 252, 200, 169, 85, 67, 49, 172, 84, 71, 147, 147, 43, 113, 218, 251, 229, 121, 96, 2, 143, 174, 52, 166, 55, 12, 39, 239, 51, 22, 241, 206, 221, 93, 193, 69, 172, 61, 24, 22, 181, 20, 76, 140, 220, 81, 163, 198, 168, 46, 159, 195, 241, 100, 239, 244, 167, 73, 14, 142, 146, 140, 196, 160, 240, 171, 238, 170, 252, 56, 153, 149, 203, 148, 192, 135, 235, 125, 78, 140, 122, 239, 179, 79, 106, 210, 178, 80, 92, 237, 9, 5, 66, 65, 66, 69, 1, 1, 194, 5, 155, 37, 93, 12, 210, 230, 125, 30, 8, 53, 22, 207, 48, 223, 175, 199, 105, 27, 105, 114, 63, 135, 226, 130, 184, 70, 200, 181, 214, 48, 180, 113, 0, 14, 143, 141, 161, 238, 41, 46, 173, 95, 46, 46, 61, 165, 158, 197, 211, 226, 30, 191, 212, 56, 163, 240, 165, 80, 127, 161, 134, 136, 26, 11, 40, 4, 2, 0, 11, 180, 32, 39, 228, 124, 1, 26, 167, 21, 149, 42, 4, 45, 0, 64, 20, 5, 0, 0, 0, 0, 244, 88, 24, 239, 152, 25, 113, 0, 202, 96, 54, 243, 229, 247, 176, 66, 54, 123, 87, 90, 125, 109, 80, 30, 57, 113, 87, 242, 22, 250, 90, 6, 167, 193, 169, 11, 30, 11, 190, 17, 141, 28, 248, 39, 240, 91, 86, 85, 2, 81, 111, 183, 225, 140, 44, 10, 47, 95, 69, 210, 203, 202, 238, 139, 20, 5, 1, 0, 0, 0, 0, 33, 98, 139, 168, 31, 87, 75, 117, 6, 26, 244, 22, 190, 139, 12, 223, 107, 73, 99, 202, 95, 235, 164, 6, 180, 253, 7, 44, 88, 187, 98, 248, 250, 89, 254, 185, 222, 8, 226, 64, 221, 210, 198, 106, 17, 143, 158, 72, 66, 115, 125, 206, 106, 137, 117, 185, 167, 144, 251, 177, 245, 23, 138, 20, 5, 2, 0, 0, 0, 106, 138, 122, 226, 15, 122, 32, 99, 29, 154, 68, 219, 203, 80, 3, 177, 55, 70, 26, 23, 69, 60, 160, 214, 40, 70, 220, 117, 23, 17, 167, 69, 117, 156, 221, 235, 69, 22, 186, 153, 251, 233, 92, 105, 173, 64, 70, 222, 204, 211, 40, 136, 243, 212, 16, 118, 167, 159, 112, 11, 20, 44, 122, 134, 20, 5, 3, 0, 0, 0, 22, 46, 74, 193, 129, 129, 103, 15, 220, 207, 207, 9, 49, 240, 87, 51, 188, 112, 50, 29, 138, 67, 129, 110, 21, 9, 239, 80, 66, 122, 79, 50, 50, 176, 137, 44, 115, 247, 28, 124, 152, 49, 112, 156, 203, 165, 190, 247, 98, 179, 183, 26, 215, 86, 18, 94, 96, 191, 107, 149, 127, 251, 249, 133, 20, 5, 4, 0, 0, 0, 234, 214, 58, 36, 153, 250, 15, 26, 201, 14, 175, 40, 78, 98, 208, 0, 152, 54, 234, 242, 212, 186, 71, 215, 229, 59, 99, 214, 184, 164, 146, 9, 198, 3, 196, 253, 199, 29, 102, 122, 33, 195, 221, 82, 184, 82, 216, 198, 49, 219, 204, 89, 102, 197, 214, 222, 244, 207, 175, 140, 138, 139, 113, 133, 20, 5, 5, 0, 0, 0, 246, 40, 137, 18, 82, 230, 239, 122, 106, 139, 113, 21, 148, 48, 107, 247, 141, 38, 202, 235, 11, 14, 64, 202, 89, 118, 255, 77, 110, 184, 186, 3, 151, 189, 29, 44, 79, 7, 215, 104, 72, 204, 166, 217, 68, 227, 237, 97, 101, 76, 247, 26, 66, 66, 151, 201, 148, 91, 20, 118, 89, 215, 35, 139, 20, 1, 6, 0, 0, 0, 124, 240, 172, 211, 154, 161, 82, 29, 142, 120, 115, 236, 105, 225, 183, 147, 177, 104, 133, 23, 161, 38, 206, 1, 164, 169, 72, 13, 90, 222, 22, 46, 194, 185, 223, 199, 92, 198, 90, 102, 161, 165, 152, 86, 45, 97, 215, 102, 179, 217, 186, 155, 79, 52, 51, 232, 166, 169, 53, 113, 209, 185, 83, 140, 20, 5, 7, 0, 0, 0, 202, 155, 108, 121, 156, 216, 29, 53, 87, 111, 239, 92, 110, 232, 116, 18, 182, 115, 207, 1, 67, 137, 42, 186, 152, 203, 49, 71, 245, 209, 253, 44, 2, 18, 217, 156, 207, 101, 215, 114, 128, 169, 154, 188, 0, 128, 50, 244, 238, 227, 249, 67, 170, 63, 89, 157, 118, 77, 249, 56, 79, 36, 46, 138, 20, 0, 8, 0, 0, 0, 114, 132, 25, 201, 23, 39, 240, 61, 106, 167, 216, 88, 188, 46, 140, 110, 157, 186, 145, 14, 68, 66, 252, 69, 6, 183, 48, 139, 202, 111, 46, 28, 105, 48, 207, 190, 62, 146, 189, 58, 251, 185, 233, 146, 109, 59, 202, 188, 120, 217, 255, 109, 60, 107, 39, 201, 14, 81, 117, 22, 125, 140, 203, 128, 20, 5, 9, 0, 0, 0, 16, 127, 40, 188, 209, 216, 6, 113, 201, 7, 111, 14, 153, 196, 187, 28, 112, 243, 51, 109, 72, 93, 6, 72, 164, 96, 205, 154, 24, 20, 2, 38, 93, 21, 183, 126, 64, 147, 142, 150, 178, 243, 221, 192, 246, 171, 66, 191, 214, 39, 0, 65, 234, 221, 78, 85, 115, 117, 28, 105, 251, 10, 117, 139, 20, 5, 10, 0, 0, 0, 146, 222, 162, 150, 12, 209, 251, 40, 120, 174, 41, 92, 211, 115, 212, 33, 75, 170, 38, 143, 49, 55, 71, 85, 103, 127, 108, 245, 106, 49, 108, 72, 46, 30, 118, 126, 71, 216, 151, 196, 24, 150, 151, 127, 110, 27, 199, 67, 81, 116, 159, 224, 196, 53, 7, 131, 82, 56, 80, 112, 179, 19, 248, 143, 20, 5, 11, 0, 0, 0, 76, 50, 55, 68, 158, 129, 149, 202, 202, 141, 202, 228, 63, 1, 49, 166, 145, 91, 144, 219, 144, 219, 30, 204, 30, 138, 142, 221, 57, 236, 130, 74, 197, 109, 236, 1, 175, 35, 85, 136, 14, 28, 228, 45, 168, 247, 253, 63, 237, 192, 217, 217, 185, 113, 212, 83, 153, 202, 157, 211, 231, 191, 53, 138, 20, 5, 12, 0, 0, 0, 126, 60, 184, 144, 83, 77, 88, 58, 66, 43, 70, 67, 197, 141, 160, 177, 160, 80, 12, 238, 51, 77, 198, 142, 16, 224, 102, 221, 235, 69, 16, 90, 146, 178, 43, 201, 66, 69, 9, 64, 220, 35, 13, 97, 90, 90, 104, 101, 135, 171, 100, 226, 239, 59, 108, 63, 253, 250, 219, 68, 3, 37, 25, 131, 20, 5, 13, 0, 0, 0, 182, 16, 222, 207, 85, 111, 10, 81, 184, 200, 168, 158, 126, 20, 127, 40, 158, 23, 118, 10, 132, 149, 251, 73, 102, 185, 236, 91, 196, 253, 44, 114, 240, 74, 249, 125, 71, 186, 252, 213, 211, 150, 109, 105, 91, 114, 252, 62, 82, 117, 128, 186, 244, 248, 144, 254, 50, 191, 23, 17, 36, 251, 64, 136, 20, 5, 14, 0, 0, 0, 182, 164, 224, 23, 213, 126, 28, 11, 100, 170, 208, 127, 147, 246, 215, 88, 61, 175, 133, 145, 84, 187, 194, 35, 143, 212, 72, 227, 178, 59, 175, 118, 9, 54, 147, 196, 235, 236, 192, 200, 232, 183, 154, 86, 193, 21, 129, 44, 247, 70, 55, 27, 2, 151, 149, 38, 113, 143, 88, 34, 29, 99, 79, 142, 20, 5, 15, 0, 0, 0, 62, 10, 132, 250, 119, 253, 166, 252, 100, 87, 78, 115, 178, 74, 102, 43, 82, 49, 23, 55, 224, 230, 226, 101, 79, 82, 44, 69, 181, 175, 171, 92, 17, 62, 158, 155, 130, 177, 224, 179, 134, 130, 222, 125, 189, 113, 205, 249, 250, 243, 248, 84, 193, 2, 32, 95, 98, 35, 76, 120, 152, 180, 215, 131, 8, 37, 8, 0, 0, 175, 118, 225, 235, 187, 192, 11, 26, 115, 129, 172, 137, 84, 115, 109, 176, 65, 229, 57, 91, 74, 154, 86, 230, 224, 93, 51, 144, 254, 16, 23, 246, 112, 58, 90, 78, 74, 0, 214, 52, 242, 221, 240, 126, 177, 243, 248, 250, 139, 82, 218, 226, 155, 163, 8, 105, 248, 182, 174, 168, 180, 104, 8, 97, 60, 115, 174, 249, 84, 132, 133, 51, 105, 238, 134, 0, 94, 24, 147, 107, 18, 126, 249, 116, 194, 88, 78, 93, 62, 98, 58, 157, 36, 87, 255, 10, 104, 29, 99, 148, 92, 152, 71, 37, 254, 168, 212, 111, 27, 213, 114, 227, 162, 229, 22, 245, 49, 115, 253, 90, 215, 191, 164, 98, 171, 221, 8, 174, 237, 29, 46, 129, 126, 171, 165, 86, 62, 242, 251, 254, 216, 246, 50, 97, 158, 218, 162, 137, 162, 156, 94, 225, 223, 140, 80, 225, 249, 20, 195, 175, 130, 68, 145, 47, 182, 111, 47, 72, 14, 86, 228, 175, 114, 54, 181, 215, 249, 172, 165, 141, 228, 32, 162, 58, 133, 184, 160, 95, 166, 138, 111, 50, 190, 35, 181, 201, 151, 144, 174, 214, 247, 70, 205, 232, 255, 255, 160, 119, 124, 119, 170, 168, 187, 61, 124, 180, 17, 100, 181, 167, 154, 14, 115, 142, 139, 239, 247, 45, 55, 69, 197, 103, 62, 42, 114, 125, 158, 78, 15, 73, 53, 175, 254, 149, 98, 19, 30, 234, 164, 182, 181, 114, 155, 175, 123, 39, 29, 132, 36, 97, 97, 11, 59, 8, 198, 202, 156, 246, 161, 2, 113, 158, 110, 103, 198, 114, 244, 73, 251, 143, 251, 60, 230, 224, 175, 50, 54, 176, 0, 0, 0, 233, 2, 172, 105, 10, 42, 119, 74, 4, 193, 25, 40, 217, 109, 200, 49, 68, 184, 108, 147, 201, 33, 176, 158, 243, 243, 139, 196, 105, 175, 104, 197, 35, 84, 22, 38, 14, 0, 239, 164, 26, 248, 187, 41, 196, 244, 107, 253, 5, 148, 149, 209, 243, 187, 244, 18, 186, 27, 60, 225, 247, 55, 79, 116, 138, 14, 234, 84, 101, 167, 102, 213, 118, 81, 144, 175, 253, 229, 43, 41, 242, 75, 241, 89, 38, 229, 165, 84, 122, 211, 202, 124, 92, 63, 207, 95, 55, 247, 101, 172, 220, 115, 8, 6, 97, 117, 114, 97, 32, 134, 44, 32, 8, 0, 0, 0, 0, 5, 97, 117, 114, 97, 1, 1, 40, 57, 30, 247, 197, 252, 101, 55, 227, 113, 208, 156, 160, 24, 42, 92, 216, 200, 252, 99, 89, 104, 210, 134, 232, 49, 50, 126, 218, 196, 39, 78, 73, 201, 88, 216, 63, 32, 181, 239, 27, 23, 111, 180, 91, 163, 106, 162, 102, 126, 16, 73, 116, 152, 242, 235, 186, 228, 129, 139, 111, 253, 168, 141, 0, 0, 0, 0, 25, 66, 123, 0, 12, 1, 0, 160, 139, 229, 62, 216, 203, 144, 104, 17, 69, 8, 79, 40, 19, 37, 65, 98, 238, 73, 185, 234, 144, 224, 78, 98, 104, 215, 20, 97, 113, 60, 239, 66, 39, 44, 80, 81, 224, 254, 129, 109, 119, 184, 63, 28, 190, 119, 112, 238, 179, 136, 20, 233, 244, 254, 23, 203, 151, 182, 254, 203, 165, 136, 2, 134, 197, 223, 40, 200, 200, 162, 89, 231, 163, 172, 221, 191, 55, 58, 167, 77, 22, 85, 255, 73, 105, 125, 80, 231, 48, 83, 38, 139, 167, 57, 62, 106, 59, 156, 112, 90, 145, 226, 224, 201, 221, 155, 223, 122, 13, 226, 205, 123, 86, 136, 74, 191, 231, 106, 61, 132, 231, 98, 154, 73, 197, 94, 143, 1, 240, 142, 190, 26, 77, 110, 2, 244, 142, 218, 128, 63, 37, 92, 68, 234, 247, 36, 166, 156, 207, 219, 68, 93, 34, 60, 184, 52, 46, 54, 114, 5, 224, 208, 181, 28, 158, 79, 46, 188, 111, 9, 171, 140, 58, 104, 94, 167, 73, 108, 105, 9, 46, 47, 162, 237, 54, 248, 164, 11, 238, 79, 96, 140, 12, 7, 54, 8, 0, 0, 175, 118, 225, 235, 187, 192, 11, 26, 115, 129, 172, 137, 84, 115, 109, 176, 65, 229, 57, 91, 74, 154, 86, 230, 224, 93, 51, 144, 254, 16, 23, 246, 146, 152, 92, 218, 164, 118, 97, 235, 181, 172, 190, 80, 136, 159, 123, 129, 105, 31, 108, 6, 13, 240, 118, 154, 219, 73, 79, 100, 218, 62, 87, 11, 240, 240, 73, 35, 226, 192, 112, 65, 155, 19, 52, 40, 246, 195, 42, 4, 206, 47, 11, 185, 116, 228, 12, 168, 125, 32, 228, 4, 146, 10, 156, 67, 152, 173, 126, 206, 160, 177, 56, 60, 11, 212, 71, 123, 183, 130, 92, 32, 240, 189, 45, 59, 194, 110, 168, 126, 76, 166, 48, 250, 50, 223, 215, 156, 234, 4, 18, 122, 21, 42, 232, 20, 168, 183, 254, 211, 180, 175, 78, 253, 172, 39, 197, 89, 23, 92, 202, 87, 206, 182, 159, 112, 144, 45, 179, 205, 28, 21, 138, 241, 252, 127, 198, 2, 222, 167, 240, 150, 193, 91, 158, 10, 198, 144, 131, 98, 241, 180, 104, 31, 94, 2, 114, 54, 18, 40, 174, 94, 104, 19, 30, 203, 169, 164, 4, 249, 94, 239, 87, 56, 128, 183, 187, 131, 192, 226, 135, 47, 98, 139, 26, 34, 173, 63, 146, 16, 146, 183, 225, 134, 30, 168, 221, 138, 200, 100, 57, 156, 189, 187, 192, 223, 138, 33, 149, 30, 80, 24, 69, 233, 176, 177, 182, 48, 209, 125, 238, 107, 149, 97, 180, 134, 105, 11, 49, 138, 17, 233, 236, 131, 88, 50, 63, 24, 58, 218, 5, 84, 87, 101, 91, 164, 221, 29, 25, 226, 80, 26, 217, 109, 34, 91, 43, 217, 0, 0, 0, 225, 2, 181, 231, 10, 56, 62, 156, 230, 221, 14, 56, 109, 162, 136, 91, 149, 254, 181, 164, 179, 56, 209, 216, 245, 251, 211, 178, 213, 56, 49, 223, 253, 111, 121, 22, 214, 154, 192, 47, 193, 75, 27, 57, 151, 217, 92, 239, 142, 185, 134, 183, 249, 236, 22, 241, 141, 104, 3, 130, 230, 184, 211, 49, 136, 15, 69, 158, 149, 35, 4, 228, 125, 116, 200, 85, 188, 161, 117, 239, 242, 122, 231, 208, 234, 231, 170, 54, 4, 246, 141, 113, 29, 162, 14, 85, 108, 174, 238, 132, 8, 6, 97, 117, 114, 97, 32, 134, 44, 32, 8, 0, 0, 0, 0, 5, 97, 117, 114, 97, 1, 1, 108, 251, 167, 35, 120, 146, 115, 29, 12, 128, 245, 15, 82, 66, 228, 86, 200, 227, 202, 152, 108, 101, 59, 133, 134, 140, 252, 156, 212, 85, 64, 20, 27, 211, 210, 186, 167, 156, 1, 191, 25, 153, 42, 104, 192, 82, 56, 108, 105, 99, 27, 102, 248, 252, 212, 124, 86, 206, 226, 38, 6, 70, 171, 142, 0, 0, 0, 0, 25, 66, 123, 0, 8, 1, 68, 219, 120, 157, 247, 162, 60, 48, 60, 99, 72, 115, 67, 63, 153, 15, 252, 153, 199, 7, 189, 199, 58, 46, 10, 86, 41, 227, 188, 72, 246, 4, 83, 244, 105, 193, 127, 140, 227, 239, 56, 245, 124, 87, 216, 164, 166, 144, 107, 40, 176, 40, 137, 79, 33, 230, 82, 127, 181, 37, 72, 41, 147, 138, 2, 68, 49, 73, 231, 222, 99, 247, 86, 246, 67, 6, 142, 82, 1, 197, 16, 55, 77, 222, 17, 99, 110, 25, 124, 42, 177, 76, 84, 21, 232, 99, 12, 131, 15, 33, 179, 198, 109, 139, 31, 144, 213, 138, 220, 1, 65, 12, 154, 120, 6, 71, 185, 184, 44, 240, 35, 151, 253, 112, 83, 2, 91, 114, 138, 12, 3, 0, 246, 216, 92, 103, 88, 45, 98, 187, 149, 189, 55, 94, 250, 40, 99, 140, 220, 37, 229, 34, 240, 3, 41, 170, 15, 4, 77, 245, 108, 228, 167, 96, 102, 8, 237, 1, 115, 28, 234, 129, 148, 1, 101, 18, 142, 31, 253, 252, 91, 66, 7, 226, 173, 132, 84, 131, 119, 137, 155, 57, 45, 196, 151, 177, 193, 102, 220, 31, 133, 232, 162, 144, 38, 133, 83, 170, 65, 18, 246, 24, 5, 193, 167, 217, 127, 79, 125, 77, 243, 98, 31, 193, 187, 14, 26, 198, 243, 44, 131, 6, 8, 6, 66, 65, 66, 69, 181, 1, 3, 5, 0, 0, 0, 12, 89, 64, 16, 0, 0, 0, 0, 58, 102, 213, 95, 227, 27, 5, 141, 153, 63, 92, 162, 176, 229, 244, 17, 31, 226, 40, 0, 121, 158, 27, 23, 245, 67, 152, 83, 58, 113, 158, 82, 126, 103, 120, 164, 98, 178, 148, 152, 155, 46, 68, 9, 252, 128, 62, 37, 112, 183, 117, 30, 29, 147, 22, 63, 160, 179, 155, 116, 47, 204, 92, 12, 86, 79, 97, 43, 223, 216, 196, 122, 119, 152, 83, 155, 212, 73, 145, 42, 133, 106, 86, 163, 99, 39, 62, 75, 113, 54, 8, 252, 208, 202, 82, 8, 5, 66, 65, 66, 69, 1, 1, 44, 114, 48, 165, 157, 36, 194, 83, 104, 47, 128, 136, 158, 247, 92, 166, 10, 243, 174, 36, 103, 104, 100, 71, 98, 84, 109, 67, 140, 35, 132, 20, 150, 17, 47, 5, 190, 188, 210, 7, 172, 127, 20, 55, 53, 102, 190, 148, 206, 241, 116, 49, 18, 123, 195, 249, 93, 35, 126, 238, 5, 171, 233, 138, 26, 146, 1, 65, 2, 132, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 68, 211, 237, 210, 119, 8, 83, 243, 27, 94, 38, 113, 202, 174, 146, 68, 202, 114, 24, 94, 232, 254, 98, 159, 190, 53, 121, 147, 146, 233, 108, 19, 96, 143, 11, 58, 36, 149, 57, 203, 238, 189, 204, 2, 18, 234, 19, 154, 83, 105, 239, 129, 17, 85, 122, 33, 57, 48, 207, 65, 193, 218, 60, 131, 69, 1, 0, 0, 18, 2, 4, 59, 106, 39, 188, 206, 182, 164, 45, 98, 163, 168, 208, 42, 111, 13, 115, 101, 50, 21, 119, 29, 226, 67, 166, 58, 192, 72, 161, 139, 89, 218, 41, 1, 0, 0, 0, 0, 0} + block8077850Data := struct { + BlockData string `yaml:"blockData"` + }{} + + err = yaml.NewDecoder(bytes.NewReader(block8077850)).Decode(&block8077850Data) + require.NoError(t, err) + + fmt.Println(block8077850Data.BlockData) + + entireBlockData := common.MustHexToBytes(block8077850Data.BlockData) + blockResponseData := new(network.BlockResponseMessage) err = blockResponseData.Decode(entireBlockData) require.NoError(t, err) From 7cae04db2c4a0add9788f57ef7b5d5792c15427a Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Wed, 27 Sep 2023 15:21:00 +0200 Subject: [PATCH 03/12] chore: remove unneeded println --- lib/runtime/wazero/instance_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/runtime/wazero/instance_test.go b/lib/runtime/wazero/instance_test.go index 1a5314a59f..2b559d3218 100644 --- a/lib/runtime/wazero/instance_test.go +++ b/lib/runtime/wazero/instance_test.go @@ -5,7 +5,6 @@ package wazero_runtime import ( _ "embed" - "fmt" "archive/zip" "bytes" @@ -462,8 +461,6 @@ func TestInstance_ExecuteBlock_WestendRuntime_WestendBlock8077850(t *testing.T) err = yaml.NewDecoder(bytes.NewReader(block8077850)).Decode(&block8077850Data) require.NoError(t, err) - fmt.Println(block8077850Data.BlockData) - entireBlockData := common.MustHexToBytes(block8077850Data.BlockData) blockResponseData := new(network.BlockResponseMessage) From 0b36303fb7493a02b4cf81b45fb4a0ffe373ba6f Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Wed, 27 Sep 2023 17:55:33 +0200 Subject: [PATCH 04/12] wip: improving `TestInstance_ExecuteBlock_WestendRuntime_WestendBlock8077850` --- .gitattributes | 3 +-- lib/runtime/wazero/instance_test.go | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.gitattributes b/.gitattributes index a0384c9ffb..a2d9592b51 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,4 @@ *.go -text diff=golang lib/runtime/test_data/kusama/ filter=lfs diff=lfs merge=lfs -text -lib/runtime/test_data/polkadot/ filter=lfs diff=lfs merge=lfs -text -lib/runtime/test_data/westend/block8077850.zip filter=lfs diff=lfs merge=lfs -text +lib/runtime/test_data/polkadot/ filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/lib/runtime/wazero/instance_test.go b/lib/runtime/wazero/instance_test.go index 2b559d3218..502d01d9af 100644 --- a/lib/runtime/wazero/instance_test.go +++ b/lib/runtime/wazero/instance_test.go @@ -415,24 +415,23 @@ func TestInstance_BabeConfiguration_WestendRuntime_NoAuthorities(t *testing.T) { func extractZippedState(t *testing.T, zippedFile, destPath string) { r, err := zip.OpenReader(zippedFile) require.NoError(t, err) - defer r.Close() + require.Equal(t, len(r.File), 1) - for _, f := range r.File { - outFile, err := os.OpenFile(destPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) - require.NoError(t, err) - - defer outFile.Close() + f := r.File[0] + outFile, err := os.OpenFile(destPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) + require.NoError(t, err) - rc, err := f.Open() - require.NoError(t, err) - defer rc.Close() + rc, err := f.Open() + require.NoError(t, err) - _, err = io.Copy(outFile, rc) - require.NoError(t, err) + _, err = io.CopyN(outFile, rc, rc) + require.NoError(t, err) - // File extracted, no need to loop further - return - } + t.Cleanup(func() { + require.NoError(t, outFile.Close()) + require.NoError(t, rc.Close()) + require.NoError(t, r.Close()) + }) } func TestInstance_ExecuteBlock_WestendRuntime_WestendBlock8077850(t *testing.T) { @@ -481,7 +480,7 @@ func TestInstance_ExecuteBlock_WestendRuntime_WestendBlock8077850(t *testing.T) "0x41b93a99fee24501ddeb1cc2dcfbec938c99a3d94531c7e16b4f4e102a9df38a", } - bodyExtrinsicHashes := []string{} + var bodyExtrinsicHashes []string for _, ext := range exts { bodyExtrinsicHashes = append(bodyExtrinsicHashes, ext.Hash().String()) } From 59c29fac41e080b71458104ab554d6e333c6a584 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 2 Oct 2023 07:55:40 -0400 Subject: [PATCH 05/12] chore: simulate a all zeroes public key without huge state trie --- lib/babe/errors.go | 13 +- lib/runtime/constants.go | 6 + lib/runtime/test_helpers.go | 4 + lib/runtime/wazero/block8077850.yaml | 1 - lib/runtime/wazero/instance_test.go | 187 +++++++++++++++------------ 5 files changed, 129 insertions(+), 82 deletions(-) delete mode 100644 lib/runtime/wazero/block8077850.yaml diff --git a/lib/babe/errors.go b/lib/babe/errors.go index e30f8d0287..273574c234 100644 --- a/lib/babe/errors.go +++ b/lib/babe/errors.go @@ -110,6 +110,7 @@ var ( errInvalidMandatoryDispatch = errors.New("invalid mandatory dispatch") errLookupFailed = errors.New("lookup failed") errValidatorNotFound = errors.New("validator not found") + errBadSigner = errors.New("invalid signing address") ) func newUnknownError(data scale.VaryingDataTypeValue) error { @@ -271,6 +272,14 @@ func (MandatoryDispatch) Index() uint { return 9 } func (MandatoryDispatch) String() string { return "mandatory dispatch" } +// MandatoryDispatch A transaction with a mandatory dispatch +type BadSigner struct{} + +// Index returns VDT index +func (BadSigner) Index() uint { return 10 } + +func (BadSigner) String() string { return "invalid signing address" } + func determineErrType(vdt scale.VaryingDataType) error { vdtVal, err := vdt.Value() if err != nil { @@ -311,6 +320,8 @@ func determineErrType(vdt scale.VaryingDataType) error { return &TransactionValidityError{errValidatorNotFound} case UnknownCustom: return &TransactionValidityError{newUnknownError(val)} + case BadSigner: + return &TransactionValidityError{errBadSigner} } return errInvalidResult @@ -319,7 +330,7 @@ func determineErrType(vdt scale.VaryingDataType) error { func determineErr(res []byte) error { dispatchError := scale.MustNewVaryingDataType(other, CannotLookup{}, BadOrigin{}, Module{}) invalid := scale.MustNewVaryingDataType(Call{}, Payment{}, Future{}, Stale{}, BadProof{}, AncientBirthBlock{}, - ExhaustsResources{}, invalidCustom, BadMandatory{}, MandatoryDispatch{}) + ExhaustsResources{}, invalidCustom, BadMandatory{}, MandatoryDispatch{}, BadSigner{}) unknown := scale.MustNewVaryingDataType(ValidityCannotLookup{}, NoUnsignedValidator{}, unknownCustom) okRes := scale.NewResult(nil, dispatchError) diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index 26d0ccd267..1c2ee7aaec 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -22,6 +22,12 @@ const ( WESTEND_RUNTIME_V0929_FP = "westend_runtime-v929.compact.wasm" WESTEND_RUNTIME_V0929_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9." + "29/westend_runtime-v9290.compact.compressed.wasm?raw=true" + + // v0.9.12 westend used for zero-address bug + WESTEND_RUNTIME_v0912 = "westend_runtime-v9111" + WESTEND_RUNTIME_V0912_FP = "westend_runtime-v9111.compact.wasm" + WESTEND_RUNTIME_V0912_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9." + + "11/westend_runtime-v9111.compact.compressed.wasm?raw=true" ) const ( diff --git a/lib/runtime/test_helpers.go b/lib/runtime/test_helpers.go index c6a5e836ac..5734761d81 100644 --- a/lib/runtime/test_helpers.go +++ b/lib/runtime/test_helpers.go @@ -78,6 +78,10 @@ func GetRuntime(ctx context.Context, runtime string) ( case WESTEND_RUNTIME_v0929: runtimeFilename = WESTEND_RUNTIME_V0929_FP url = WESTEND_RUNTIME_V0929_URL + // only used for TestInstance_BadSignatureExtrinsic_On_WestendBlock8077850 + case WESTEND_RUNTIME_v0912: + runtimeFilename = WESTEND_RUNTIME_V0912_FP + url = WESTEND_RUNTIME_V0912_URL default: return "", fmt.Errorf("%w: %s", ErrRuntimeUnknown, runtime) } diff --git a/lib/runtime/wazero/block8077850.yaml b/lib/runtime/wazero/block8077850.yaml deleted file mode 100644 index fde2328c3a..0000000000 --- a/lib/runtime/wazero/block8077850.yaml +++ /dev/null @@ -1 +0,0 @@ -blockData: "0x0a91190a200b9220127cd86736564cdc0a513f0dbeac31dbfaa631cc2f3cda5b5941b5d13f12a002af76e1ebbbc00b1a7381ac8954736db041e5395b4a9a56e6e05d3390fe1017f66a08ed016fbc811641487fe2258728ea40d7e8a4469fdc09b7e3f990283e0bc7d32612bd56c48524f36b2a03ff9ecc82cab1809324181ae80558ae46f9e32f2160d52d7f080642414245b50103020000000d594010000000002e37acc5e82ffcc8a9554331ac544793932b71dafbe57960028fae34a6370c27ef3316f1cedd5dc145ac3d1816b5144c8cdc51a3c6a82e9fc3f164eff4a7490e8e928cc4a0f0abeeaafc389995cb94c087eb7d4e8c7aefb34f6ad2b2505ced0905424142450101c2059b255d0cd2e67d1e083516cf30dfafc7691b69723f87e282b846c8b5d630b471000e8f8da1ee292ead5f2e2e3da59ec5d3e21ebfd438a3f0a5507fa186881a0b280402000bb42027e47c011aa715952a042d0040140500000000f45818ef98197100ca6036f3e5f7b042367b575a7d6d501e397157f216fa5a06a7c1a90b1e0bbe118d1cf827f05b565502516fb7e18c2c0a2f5f45d2cbcaee8b1405010000000021628ba81f574b75061af416be8b0cdf6b4963ca5feba406b4fd072c58bb62f8fa59feb9de08e240ddd2c66a118f9e4842737dce6a8975b9a790fbb1f5178a1405020000006a8a7ae20f7a20631d9a44dbcb5003b137461a17453ca0d62846dc751711a745759cddeb4516ba99fbe95c69ad4046deccd32888f3d41076a79f700b142c7a86140503000000162e4ac18181670fdccfcf0931f05733bc70321d8a43816e1509ef50427a4f3232b0892c73f71c7c9831709ccba5bef762b3b71ad756125e60bf6b957ffbf985140504000000ead63a2499fa0f1ac90eaf284e62d0009836eaf2d4ba47d7e53b63d6b8a49209c603c4fdc71d667a21c3dd52b852d8c631dbcc5966c5d6def4cfaf8c8a8b7185140505000000f628891252e6ef7a6a8b711594306bf78d26caeb0b0e40ca5976ff4d6eb8ba0397bd1d2c4f07d76848cca6d944e3ed61654cf71a424297c9945b147659d7238b1401060000007cf0acd39aa1521d8e7873ec69e1b793b1688517a126ce01a4a9480d5ade162ec2b9dfc75cc65a66a1a598562d61d766b3d9ba9b4f3433e8a6a93571d1b9538c140507000000ca9b6c799cd81d35576fef5c6ee87412b673cf0143892aba98cb3147f5d1fd2c0212d99ccf65d77280a99abc008032f4eee3f943aa3f599d764df9384f242e8a140008000000728419c91727f03d6aa7d858bc2e8c6e9dba910e4442fc4506b7308bca6f2e1c6930cfbe3e92bd3afbb9e9926d3bcabc78d9ff6d3c6b27c90e5175167d8ccb80140509000000107f28bcd1d80671c9076f0e99c4bb1c70f3336d485d0648a460cd9a181402265d15b77e40938e96b2f3ddc0f6ab42bfd6270041eadd4e5573751c69fb0a758b14050a00000092dea2960cd1fb2878ae295cd373d4214baa268f31374755677f6cf56a316c482e1e767e47d897c41896977f6e1bc74351749fe0c435078352385070b313f88f14050b0000004c3237449e8195caca8dcae43f0131a6915b90db90db1ecc1e8a8edd39ec824ac56dec01af2355880e1ce42da8f7fd3fedc0d9d9b971d45399ca9dd3e7bf358a14050c0000007e3cb890534d583a422b4643c58da0b1a0500cee334dc68e10e066ddeb45105a92b22bc942450940dc230d615a5a686587ab64e2ef3b6c3ffdfadb440325198314050d000000b610decf556f0a51b8c8a89e7e147f289e17760a8495fb4966b9ec5bc4fd2c72f04af97d47bafcd5d3966d695b72fc3e527580baf4f890fe32bf171124fb408814050e000000b6a4e017d57e1c0b64aad07f93f6d7583daf859154bbc2238fd448e3b23baf76093693c4ebecc0c8e8b79a56c115812cf746371b02979526718f58221d634f8e14050f0000003e0a84fa77fda6fc64574e73b24a662b52311737e0e6e2654f522c45b5afab5c113e9e9b82b1e0b38682de7dbd71cdf9faf3f854c102205f62234c7898b4d7830825080000af76e1ebbbc00b1a7381ac8954736db041e5395b4a9a56e6e05d3390fe1017f6703a5a4e4a00d634f2ddf07eb1f3f8fa8b52dae29ba30869f8b6aea8b46808613c73aef95484853369ee86005e18936b127ef974c2584e5d3e623a9d2457ff0a681d63945c984725fea8d46f1bd572e3a2e516f53173fd5ad7bfa462abdd08aeed1d2e817eaba5563ef2fbfed8f632619edaa289a29c5ee1df8c50e1f914c3af8244912fb66f2f480e56e4af7236b5d7f9aca58de420a23a85b8a05fa68a6f32be23b5c99790aed6f746cde8ffffa0777c77aaa8bb3d7cb41164b5a79a0e738e8beff72d3745c5673e2a727d9e4e0f4935affe9562131eeaa4b6b5729baf7b271d842461610b3b08c6ca9cf6a102719e6e67c672f449fb8ffb3ce6e0af3236b0000000e902ac690a2a774a04c11928d96dc83144b86c93c921b09ef3f38bc469af68c5235416260e00efa41af8bb29c4f46bfd059495d1f3bbf412ba1b3ce1f7374f748a0eea5465a766d5765190affde52b29f24bf15926e5a5547ad3ca7c5c3fcf5f37f765acdc7308066175726120862c2008000000000561757261010128391ef7c5fc6537e371d09ca0182a5cd8c8fc635968d286e831327edac4274e49c958d83f20b5ef1b176fb45ba36aa2667e10497498f2ebbae4818b6ffda88d0000000019427b000c0100a08be53ed8cb90681145084f2813254162ee49b9ea90e04e6268d71461713cef42272c5051e0fe816d77b83f1cbe7770eeb38814e9f4fe17cb97b6fecba5880286c5df28c8c8a259e7a3acddbf373aa74d1655ff49697d50e73053268ba7393e6a3b9c705a91e2e0c9dd9bdf7a0de2cd7b56884abfe76a3d84e7629a49c55e8f01f08ebe1a4d6e02f48eda803f255c44eaf724a69ccfdb445d223cb8342e367205e0d0b51c9e4f2ebc6f09ab8c3a685ea7496c69092e2fa2ed36f8a40bee4f608c0c0736080000af76e1ebbbc00b1a7381ac8954736db041e5395b4a9a56e6e05d3390fe1017f692985cdaa47661ebb5acbe50889f7b81691f6c060df0769adb494f64da3e570bf0f04923e2c070419b133428f6c32a04ce2f0bb974e40ca87d20e404920a9c4398ad7ecea0b1383c0bd4477bb7825c20f0bd2d3bc26ea87e4ca630fa32dfd79cea04127a152ae814a8b7fed3b4af4efdac27c559175cca57ceb69f70902db3cd1c158af1fc7fc602dea7f096c15b9e0ac6908362f1b4681f5e0272361228ae5e68131ecba9a404f95eef573880b7bb83c0e2872f628b1a22ad3f921092b7e1861ea8dd8ac864399cbdbbc0df8a21951e501845e9b0b1b630d17dee6b9561b486690b318a11e9ec8358323f183ada055457655ba4dd1d19e2501ad96d225b2bd9000000e102b5e70a383e9ce6dd0e386da2885b95feb5a4b338d1d8f5fbd3b2d53831dffd6f7916d69ac02fc14b1b3997d95cef8eb986b7f9ec16f18d680382e6b8d331880f459e952304e47d74c855bca175eff27ae7d0eae7aa3604f68d711da20e556caeee8408066175726120862c200800000000056175726101016cfba7237892731d0c80f50f5242e456c8e3ca986c653b85868cfc9cd45540141bd3d2baa79c01bf19992a68c052386c69631b66f8fcd47c56cee2260646ab8e0000000019427b00080144db789df7a23c303c634873433f990ffc99c707bdc73a2e0a5629e3bc48f60453f469c17f8ce3ef38f57c57d8a4a6906b28b028894f21e6527fb5254829938a02443149e7de63f756f643068e5201c510374dde11636e197c2ab14c5415e8630c830f21b3c66d8b1f90d58adc01410c9a780647b9b82cf02397fd7053025b728a0c0300f6d85c67582d62bb95bd375efa28638cdc25e522f00329aa0f044df56ce4a7606608ed01731cea81940165128e1ffdfc5b4207e2ad84548377899b392dc497b1c166dc1f85e8a290268553aa4112f61805c1a7d97f4f7d4df3621fc1bb0e1ac6f32c8306080642414245b50103050000000c594010000000003a66d55fe31b058d993f5ca2b0e5f4111fe22800799e1b17f54398533a719e527e6778a462b294989b2e4409fc803e2570b7751e1d93163fa0b39b742fcc5c0c564f612bdfd8c47a7798539bd449912a856a56a363273e4b713608fcd0ca5208054241424501012c7230a59d24c253682f80889ef75ca60af3ae246768644762546d438c23841496112f05bebcd207ac7f14373566be94cef17431127bc3f95d237eee05abe98a1a92014102840000000000000000000000000000000000000000000000000000000000000000000144d3edd2770853f31b5e2671caae9244ca72185ee8fe629fbe35799392e96c13608f0b3a249539cbeebdcc0212ea139a5369ef8111557a213930cf41c1da3c83450100001202043b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29010000000000" diff --git a/lib/runtime/wazero/instance_test.go b/lib/runtime/wazero/instance_test.go index 502d01d9af..e2686c863c 100644 --- a/lib/runtime/wazero/instance_test.go +++ b/lib/runtime/wazero/instance_test.go @@ -6,16 +6,13 @@ package wazero_runtime import ( _ "embed" - "archive/zip" "bytes" "encoding/json" - "io" "math/big" "os" "path/filepath" "testing" - "github.com/ChainSafe/gossamer/dot/network" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/internal/log" "github.com/ChainSafe/gossamer/lib/common" @@ -28,15 +25,11 @@ import ( "github.com/ChainSafe/gossamer/lib/utils" "github.com/ChainSafe/gossamer/pkg/scale" "github.com/centrifuge/go-substrate-rpc-client/v4/signature" - "gopkg.in/yaml.v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) -//go:embed block8077850.yaml -var block8077850 []byte - func mustHexTo64BArray(t *testing.T, inputHex string) (outputArray [64]byte) { t.Helper() copy(outputArray[:], common.MustHexToBytes(inputHex)) @@ -412,83 +405,133 @@ func TestInstance_BabeConfiguration_WestendRuntime_NoAuthorities(t *testing.T) { require.Equal(t, expected, cfg) } -func extractZippedState(t *testing.T, zippedFile, destPath string) { - r, err := zip.OpenReader(zippedFile) - require.NoError(t, err) - require.Equal(t, len(r.File), 1) +func TestInstance_BadSignature_WestendBlock8077850(t *testing.T) { + tests := map[string]struct { + setupRuntime func(t *testing.T) (*Instance, *types.Header) + expectedError []byte + }{ + "westend_dev_runtime_should_fail_with_bad_signature": { + expectedError: []byte{1, 0, 0xa}, + setupRuntime: func(t *testing.T) (*Instance, *types.Header) { + genesisPath := utils.GetWestendDevRawGenesisPath(t) + gen := genesisFromRawJSON(t, genesisPath) + genTrie, err := runtime.NewTrieFromGenesis(gen) + require.NoError(t, err) - f := r.File[0] - outFile, err := os.OpenFile(destPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) - require.NoError(t, err) + //set state to genesis state + genState := storage.NewTrieState(&genTrie) - rc, err := f.Open() - require.NoError(t, err) + cfg := Config{ + Storage: genState, + LogLvl: log.Critical, + } - _, err = io.CopyN(outFile, rc, rc) - require.NoError(t, err) + rt, err := NewRuntimeFromGenesis(cfg) + require.NoError(t, err) - t.Cleanup(func() { - require.NoError(t, outFile.Close()) - require.NoError(t, rc.Close()) - require.NoError(t, r.Close()) - }) -} + // reset state back to parent state before executing + parentState := storage.NewTrieState(&genTrie) + rt.SetContextStorage(parentState) -func TestInstance_ExecuteBlock_WestendRuntime_WestendBlock8077850(t *testing.T) { - stateTrieFile := t.TempDir() + "state_block8077850.txt" - extractZippedState(t, "../test_data/westend/state_block8077850.zip", stateTrieFile) + genesisHeader := &types.Header{ + Number: 0, + StateRoot: genTrie.MustHash(), + } - gossTrie8077850 := newTrieFromScaledPairs(t, stateTrieFile) - expectedRoot := common.MustHexToHash("0x731cea81940165128e1ffdfc5b4207e2ad84548377899b392dc497b1c166dc1f") + header := &types.Header{ + ParentHash: genesisHeader.Hash(), + Number: 1, + Digest: types.NewDigest(), + } - require.Equal(t, expectedRoot, gossTrie8077850.MustHash()) + return rt, header + }, + }, + "westend_0912_runtime_should_fail_with_invalid_payment": { + expectedError: []byte{1, 0, 1}, + setupRuntime: func(t *testing.T) (*Instance, *types.Header) { + genesisPath := utils.GetWestendDevRawGenesisPath(t) + gen := genesisFromRawJSON(t, genesisPath) + genTrie, err := runtime.NewTrieFromGenesis(gen) + require.NoError(t, err) - // set state to genesis state - state8077850 := storage.NewTrieState(gossTrie8077850) - cfg := Config{ - Storage: state8077850, - LogLvl: log.Critical, + rt := NewTestInstance(t, runtime.WESTEND_RUNTIME_v0912) + parentState := storage.NewTrieState(&genTrie) + rt.SetContextStorage(parentState) + + genesisHeader := &types.Header{ + Number: 0, + StateRoot: genTrie.MustHash(), + } + + header := &types.Header{ + ParentHash: genesisHeader.Hash(), + Number: 1, + Digest: types.NewDigest(), + } + + return rt, header + }, + }, } - instance, err := NewInstanceFromTrie(gossTrie8077850, cfg) - require.NoError(t, err) + for tname, tt := range tests { + tt := tt - block8077850Data := struct { - BlockData string `yaml:"blockData"` - }{} + t.Run(tname, func(t *testing.T) { + instance, header := tt.setupRuntime(t) - err = yaml.NewDecoder(bytes.NewReader(block8077850)).Decode(&block8077850Data) - require.NoError(t, err) + err := instance.InitializeBlock(header) + require.NoError(t, err) + + idata := types.NewInherentData() + err = idata.SetInherent(types.Timstap0, uint64(5)) + require.NoError(t, err) - entireBlockData := common.MustHexToBytes(block8077850Data.BlockData) + err = idata.SetInherent(types.Babeslot, uint64(1)) + require.NoError(t, err) - blockResponseData := new(network.BlockResponseMessage) - err = blockResponseData.Decode(entireBlockData) - require.NoError(t, err) + ienc, err := idata.Encode() + require.NoError(t, err) - block := &types.Block{ - Header: *blockResponseData.BlockData[0].Header, - Body: *blockResponseData.BlockData[0].Body, - } + // Call BlockBuilder_inherent_extrinsics which returns the inherents as encoded extrinsics + inherentExts, err := instance.InherentExtrinsics(ienc) + require.NoError(t, err) - exts, err := block.Body.AsEncodedExtrinsics() - require.NoError(t, err) + // decode inherent extrinsics + cp := make([]byte, len(inherentExts)) + copy(cp, inherentExts) + var inExts [][]byte + err = scale.Unmarshal(cp, &inExts) + require.NoError(t, err) - expectedExtrinsics := []string{ - "0x8bea0528dc1e7b07896a36d6d2ecb86c6cccbda21064089b5212a081d8b62631", - "0xc0014ff921c3bf55333621237f3058af2d2a696bddf5f703338a7c3b11c1965f", - "0x41b93a99fee24501ddeb1cc2dcfbec938c99a3d94531c7e16b4f4e102a9df38a", - } + // apply each inherent extrinsic + for _, inherent := range inExts { + in, err := scale.Marshal(inherent) + require.NoError(t, err) - var bodyExtrinsicHashes []string - for _, ext := range exts { - bodyExtrinsicHashes = append(bodyExtrinsicHashes, ext.Hash().String()) - } + ret, err := instance.ApplyExtrinsic(in) + require.NoError(t, err) + require.Equal(t, ret, []byte{0, 0}) + } - require.Equal(t, expectedExtrinsics, bodyExtrinsicHashes) + keyring, err := signature.KeyringPairFromSecret( + "0x00000000000000000000000000000000000000000000000000000"+ + "00000000000000000000000000000000000000000000000000000"+ + "0000000000000000000000", 42) + require.NoError(t, err) - _, err = instance.ExecuteBlock(block) - require.NoError(t, err) + extHex := runtime.NewTestExtrinsic(t, instance, header.ParentHash, header.ParentHash, + 0, keyring, "System.remark", []byte{0xab, 0xcd}) + + res, err := instance.ApplyExtrinsic(common.MustHexToBytes(extHex)) + require.NoError(t, err) + + // should fail with transaction validity error: invalid payment for runtime 0.9.12 + // should fail with transaction validity error: bad signature for runtime version greater than 0.9.12 + require.Equal(t, tt.expectedError, res) + }) + } } @@ -1056,22 +1099,6 @@ func newTrieFromPairs(t *testing.T, filename string) *trie.Trie { return &tr } -func newTrieFromScaledPairs(t *testing.T, filename string) *trie.Trie { - data, err := os.ReadFile(filename) - require.NoError(t, err) - - decoded := make([][2][]byte, 0) - err = scale.Unmarshal(data, &decoded) - require.NoError(t, err) - - trie, err := trie.LoadFromEntries(decoded) - if err != nil { - panic(err) - } - - return trie -} - func TestInstance_TransactionPaymentCallApi_QueryCallInfo(t *testing.T) { ins := NewTestInstance(t, runtime.WESTEND_RUNTIME_v0929) tests := []struct { From 21484ebad3b87a35047433fb1ca839fdb23c735c Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 2 Oct 2023 11:17:39 -0400 Subject: [PATCH 06/12] chore: insert new line at end --- .gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index a2d9592b51..0c10a94057 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ *.go -text diff=golang lib/runtime/test_data/kusama/ filter=lfs diff=lfs merge=lfs -text -lib/runtime/test_data/polkadot/ filter=lfs diff=lfs merge=lfs -text \ No newline at end of file +lib/runtime/test_data/polkadot/ filter=lfs diff=lfs merge=lfs -text From d45ee3426ef2d941baa7f5e2e190c474ef60c6a3 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 2 Oct 2023 11:19:15 -0400 Subject: [PATCH 07/12] chore: better version formatting --- lib/runtime/constants.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index 1c2ee7aaec..132f6ce7e7 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -14,20 +14,20 @@ const ( // v0.9.29 polkadot POLKADOT_RUNTIME_v0929 = "polkadot_runtime-v929" POLKADOT_RUNTIME_V0929_FP = "polkadot_runtime-v929.compact.wasm" - POLKADOT_RUNTIME_V0929_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9." + - "29/polkadot_runtime-v9290.compact.compressed.wasm?raw=true" + POLKADOT_RUNTIME_V0929_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9.29/" + + "polkadot_runtime-v9290.compact.compressed.wasm?raw=true" // v0.9.29 westend WESTEND_RUNTIME_v0929 = "westend_runtime-v929" WESTEND_RUNTIME_V0929_FP = "westend_runtime-v929.compact.wasm" - WESTEND_RUNTIME_V0929_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9." + - "29/westend_runtime-v9290.compact.compressed.wasm?raw=true" + WESTEND_RUNTIME_V0929_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9.29/" + + "westend_runtime-v9290.compact.compressed.wasm?raw=true" - // v0.9.12 westend used for zero-address bug + // v0.9.12 westend used for zero-address bug test WESTEND_RUNTIME_v0912 = "westend_runtime-v9111" WESTEND_RUNTIME_V0912_FP = "westend_runtime-v9111.compact.wasm" - WESTEND_RUNTIME_V0912_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9." + - "11/westend_runtime-v9111.compact.compressed.wasm?raw=true" + WESTEND_RUNTIME_V0912_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9.11/" + + "westend_runtime-v9111.compact.compressed.wasm?raw=true" ) const ( From 83b63dfaea6a182659b4a992067b313124135b85 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 2 Oct 2023 14:20:35 -0400 Subject: [PATCH 08/12] chore filepath.Join --- lib/runtime/test_helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime/test_helpers.go b/lib/runtime/test_helpers.go index 5734761d81..099fb9b6fc 100644 --- a/lib/runtime/test_helpers.go +++ b/lib/runtime/test_helpers.go @@ -60,7 +60,7 @@ func GetRuntime(ctx context.Context, runtime string) ( return runtime, nil } - basePath := filepath.Join(os.TempDir(), "/gossamer/runtimes/") + basePath := filepath.Join(os.TempDir(), "gossamer", "runtimes") const perm = os.FileMode(0777) err = os.MkdirAll(basePath, perm) if err != nil { From 3de1da9701e1754367cf3f2120621414b7bff009 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 2 Oct 2023 14:21:13 -0400 Subject: [PATCH 09/12] chore: use `http.NoBody` --- lib/runtime/test_helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime/test_helpers.go b/lib/runtime/test_helpers.go index 099fb9b6fc..bc54385a55 100644 --- a/lib/runtime/test_helpers.go +++ b/lib/runtime/test_helpers.go @@ -100,7 +100,7 @@ func GetRuntime(ctx context.Context, runtime string) ( ctx, cancel := context.WithTimeout(ctx, requestTimeout) defer cancel() - request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody) if err != nil { return "", fmt.Errorf("cannot make HTTP request: %w", err) } From 538a584433275d1b8adcff6ff90a313b4e35b534 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 2 Oct 2023 14:36:28 -0400 Subject: [PATCH 10/12] chore: fix bad signer export comment --- lib/babe/errors.go | 2 +- lib/runtime/invalid_transaction.go | 15 ++++++++++----- lib/runtime/wazero/instance_test.go | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/babe/errors.go b/lib/babe/errors.go index 273574c234..e13ea92c1a 100644 --- a/lib/babe/errors.go +++ b/lib/babe/errors.go @@ -272,7 +272,7 @@ func (MandatoryDispatch) Index() uint { return 9 } func (MandatoryDispatch) String() string { return "mandatory dispatch" } -// MandatoryDispatch A transaction with a mandatory dispatch +// BadSigner A transaction with a mandatory dispatch type BadSigner struct{} // Index returns VDT index diff --git a/lib/runtime/invalid_transaction.go b/lib/runtime/invalid_transaction.go index 979f4d175c..b3430d62ad 100644 --- a/lib/runtime/invalid_transaction.go +++ b/lib/runtime/invalid_transaction.go @@ -51,11 +51,8 @@ func (i InvalidTransaction) Error() string { //skipcq: GO-W1029 // NewInvalidTransaction is constructor for InvalidTransaction func NewInvalidTransaction() InvalidTransaction { - vdt, err := scale.NewVaryingDataType(Call{}, Payment{}, Future{}, Stale{}, BadProof{}, AncientBirthBlock{}, - ExhaustsResources{}, InvalidCustom(0), BadMandatory{}, MandatoryDispatch{}) - if err != nil { - panic(err) - } + vdt := scale.MustNewVaryingDataType(Call{}, Payment{}, Future{}, Stale{}, BadProof{}, AncientBirthBlock{}, + ExhaustsResources{}, InvalidCustom(0), BadMandatory{}, MandatoryDispatch{}, BadSigner{}) return InvalidTransaction(vdt) } @@ -188,3 +185,11 @@ func (m MandatoryDispatch) String() string { return m.Error() } func (MandatoryDispatch) Error() string { return "invalid mandatory dispatch" } + +// BadSigner A transaction with a mandatory dispatch +type BadSigner struct{} + +// Index returns VDT index +func (BadSigner) Index() uint { return 10 } + +func (BadSigner) String() string { return "invalid signing address" } diff --git a/lib/runtime/wazero/instance_test.go b/lib/runtime/wazero/instance_test.go index e2686c863c..511dfc3ed8 100644 --- a/lib/runtime/wazero/instance_test.go +++ b/lib/runtime/wazero/instance_test.go @@ -418,7 +418,7 @@ func TestInstance_BadSignature_WestendBlock8077850(t *testing.T) { genTrie, err := runtime.NewTrieFromGenesis(gen) require.NoError(t, err) - //set state to genesis state + // set state to genesis state genState := storage.NewTrieState(&genTrie) cfg := Config{ From e8a98661b792a20ddb8df780a39fd23a8a420ec6 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 2 Oct 2023 15:00:29 -0400 Subject: [PATCH 11/12] chore: fix deepsource `cyclomatic complexity` --- lib/babe/errors.go | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/lib/babe/errors.go b/lib/babe/errors.go index e13ea92c1a..46ea569a9d 100644 --- a/lib/babe/errors.go +++ b/lib/babe/errors.go @@ -280,51 +280,54 @@ func (BadSigner) Index() uint { return 10 } func (BadSigner) String() string { return "invalid signing address" } -func determineErrType(vdt scale.VaryingDataType) error { +func determineErrType(vdt scale.VaryingDataType) (err error) { vdtVal, err := vdt.Value() if err != nil { return fmt.Errorf("getting vdt value: %w", err) } + switch val := vdtVal.(type) { case Other: - return &DispatchOutcomeError{fmt.Sprintf("unknown error: %s", val)} + err = &DispatchOutcomeError{fmt.Sprintf("unknown error: %s", val)} case CannotLookup: - return &DispatchOutcomeError{"failed lookup"} + err = &DispatchOutcomeError{"failed lookup"} case BadOrigin: - return &DispatchOutcomeError{"bad origin"} + err = &DispatchOutcomeError{"bad origin"} case Module: - return &DispatchOutcomeError{fmt.Sprintf("custom module error: %s", val)} + err = &DispatchOutcomeError{fmt.Sprintf("custom module error: %s", val)} case Call: - return &TransactionValidityError{errUnexpectedTxCall} + err = &TransactionValidityError{errUnexpectedTxCall} case Payment: - return &TransactionValidityError{errInvalidPayment} + err = &TransactionValidityError{errInvalidPayment} case Future: - return &TransactionValidityError{errInvalidTransaction} + err = &TransactionValidityError{errInvalidTransaction} case Stale: - return &TransactionValidityError{errOutdatedTransaction} + err = &TransactionValidityError{errOutdatedTransaction} case BadProof: - return &TransactionValidityError{errBadProof} + err = &TransactionValidityError{errBadProof} case AncientBirthBlock: - return &TransactionValidityError{errAncientBirthBlock} + err = &TransactionValidityError{errAncientBirthBlock} case ExhaustsResources: - return &TransactionValidityError{errExhaustsResources} + err = &TransactionValidityError{errExhaustsResources} case InvalidCustom: - return &TransactionValidityError{newUnknownError(val)} + err = &TransactionValidityError{newUnknownError(val)} case BadMandatory: - return &TransactionValidityError{errMandatoryDispatchError} + err = &TransactionValidityError{errMandatoryDispatchError} case MandatoryDispatch: - return &TransactionValidityError{errInvalidMandatoryDispatch} + err = &TransactionValidityError{errInvalidMandatoryDispatch} case ValidityCannotLookup: - return &TransactionValidityError{errLookupFailed} + err = &TransactionValidityError{errLookupFailed} case NoUnsignedValidator: - return &TransactionValidityError{errValidatorNotFound} + err = &TransactionValidityError{errValidatorNotFound} case UnknownCustom: - return &TransactionValidityError{newUnknownError(val)} + err = &TransactionValidityError{newUnknownError(val)} case BadSigner: - return &TransactionValidityError{errBadSigner} + err = &TransactionValidityError{errBadSigner} + default: + err = errInvalidResult } - return errInvalidResult + return err } func determineErr(res []byte) error { From 5958b6e3adc2285c7cd44cc84f0f9db451c25515 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 2 Oct 2023 16:46:39 -0400 Subject: [PATCH 12/12] chore: make `BadSigner` an error --- lib/runtime/invalid_transaction.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/runtime/invalid_transaction.go b/lib/runtime/invalid_transaction.go index b3430d62ad..ff3dd81784 100644 --- a/lib/runtime/invalid_transaction.go +++ b/lib/runtime/invalid_transaction.go @@ -192,4 +192,9 @@ type BadSigner struct{} // Index returns VDT index func (BadSigner) Index() uint { return 10 } -func (BadSigner) String() string { return "invalid signing address" } +func (b BadSigner) String() string { return b.Error() } + +// Error returns the error message associated with the MandatoryDispatch +func (BadSigner) Error() string { + return "invalid signing address" +}