From 0dc2dde2851fe482b05a3d8383c3b8cf51846352 Mon Sep 17 00:00:00 2001 From: Bui Quang Minh Date: Mon, 28 Aug 2023 13:00:52 +0700 Subject: [PATCH] consortium_precompiled: fix typo in the validate finality proof function --- core/vm/consortium_precompiled_contracts.go | 8 ++++---- .../consortium_precompiled_contracts_test.go | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/vm/consortium_precompiled_contracts.go b/core/vm/consortium_precompiled_contracts.go index df644fd127..28f6cea120 100644 --- a/core/vm/consortium_precompiled_contracts.go +++ b/core/vm/consortium_precompiled_contracts.go @@ -30,7 +30,7 @@ var ( consortiumVerifyHeadersAbi = `[{"outputs":[],"name":"getHeader","inputs":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"bytes32","name":"parentHash","type":"bytes32"},{"internalType":"bytes32","name":"ommersHash","type":"bytes32"},{"internalType":"address","name":"coinbase","type":"address"},{"internalType":"bytes32","name":"stateRoot","type":"bytes32"},{"internalType":"bytes32","name":"transactionsRoot","type":"bytes32"},{"internalType":"bytes32","name":"receiptsRoot","type":"bytes32"},{"internalType":"uint8[256]","name":"logsBloom","type":"uint8[256]"},{"internalType":"uint256","name":"difficulty","type":"uint256"},{"internalType":"uint256","name":"number","type":"uint256"},{"internalType":"uint64","name":"gasLimit","type":"uint64"},{"internalType":"uint64","name":"gasUsed","type":"uint64"},{"internalType":"uint64","name":"timestamp","type":"uint64"},{"internalType":"bytes","name":"extraData","type":"bytes"},{"internalType":"bytes32","name":"mixHash","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"consensusAddr","type":"address"},{"internalType":"bytes","name":"header1","type":"bytes"},{"internalType":"bytes","name":"header2","type":"bytes"}],"name":"validatingDoubleSignProof","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]` consortiumPickValidatorSetAbi = `[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address[]","name":"_candidates","type":"address[]"},{"internalType":"uint256[]","name":"_weights","type":"uint256[]"},{"internalType":"uint256[]","name":"_trustedWeights","type":"uint256[]"},{"internalType":"uint256","name":"_maxValidatorNumber","type":"uint256"},{"internalType":"uint256","name":"_maxPrioritizedValidatorNumber","type":"uint256"}],"name":"pickValidatorSet","outputs":[{"internalType":"address[]","name":"_validators","type":"address[]"}],"stateMutability":"view","type":"function"}]` getDoubleSignSlashingConfigsAbi = `[{"inputs":[],"name":"getDoubleSignSlashingConfigs","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]` - validateFinaltyVoteProofAbi = `[{"inputs":[{"internalType":"bytes","name":"voterPublicKey","type":"bytes"},{"internalType":"uint256","name":"targetBlockNumber","type":"uint256"},{"internalType":"bytes32[2]","name":"targetBlockHash","type":"bytes32[2]"},{"internalType":"bytes[][2]","name":"listOfPublicKey","type":"bytes[][2]"},{"internalType":"bytes[2]","name":"aggregatedSignature","type":"bytes[2]"}],"name":"validateFinaltyVoteProof","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]` + validateFinalityVoteProofAbi = `[{"inputs":[{"internalType":"bytes","name":"voterPublicKey","type":"bytes"},{"internalType":"uint256","name":"targetBlockNumber","type":"uint256"},{"internalType":"bytes32[2]","name":"targetBlockHash","type":"bytes32[2]"},{"internalType":"bytes[][2]","name":"listOfPublicKey","type":"bytes[][2]"},{"internalType":"bytes[2]","name":"aggregatedSignature","type":"bytes[2]"}],"name":"validateFinalityVoteProof","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]` ) const ( @@ -44,7 +44,7 @@ const ( getDoubleSignSlashingConfigs = "getDoubleSignSlashingConfigs" extraVanity = 32 - validateFinaltyVoteProof = "validateFinaltyVoteProof" + validateFinalityVoteProof = "validateFinalityVoteProof" maxBlsPublicKeyListLength = 100 ) @@ -550,11 +550,11 @@ func (contract *consortiumValidateFinalityProof) Run(input []byte) ([]byte, erro } } - _, method, args, err := loadMethodAndArgs(validateFinaltyVoteProofAbi, input) + _, method, args, err := loadMethodAndArgs(validateFinalityVoteProofAbi, input) if err != nil { return nil, err } - if method.Name != validateFinaltyVoteProof { + if method.Name != validateFinalityVoteProof { return nil, errors.New("invalid method") } if len(args) != 5 { diff --git a/core/vm/consortium_precompiled_contracts_test.go b/core/vm/consortium_precompiled_contracts_test.go index 51c0eefd2a..a7106b2829 100644 --- a/core/vm/consortium_precompiled_contracts_test.go +++ b/core/vm/consortium_precompiled_contracts_test.go @@ -1731,7 +1731,7 @@ func addressesToByte(addresses []common.Address) [][]byte { func TestValidateFinalityVoteProof(t *testing.T) { contract := consortiumValidateFinalityProof{} - contractAbi, err := abi.JSON(strings.NewReader(validateFinaltyVoteProofAbi)) + contractAbi, err := abi.JSON(strings.NewReader(validateFinalityVoteProofAbi)) if err != nil { t.Fatalf("Failed to parse ABI, err %s", err) } @@ -1773,7 +1773,7 @@ func TestValidateFinalityVoteProof(t *testing.T) { } input, err := contractAbi.Pack( - validateFinaltyVoteProof, + validateFinalityVoteProof, voterPublicKey, new(big.Int).Add(new(big.Int).SetUint64(1<<64-1), common.Big1), targetBlockHashes, @@ -1790,7 +1790,7 @@ func TestValidateFinalityVoteProof(t *testing.T) { } input, err = contractAbi.Pack( - validateFinaltyVoteProof, + validateFinalityVoteProof, voterPublicKey, big.NewInt(int64(blockNumber)), targetBlockHashes, @@ -1824,7 +1824,7 @@ func TestValidateFinalityVoteProof(t *testing.T) { } input, err = contractAbi.Pack( - validateFinaltyVoteProof, + validateFinalityVoteProof, voterPublicKey, big.NewInt(int64(blockNumber)), targetBlockHashes, @@ -1863,7 +1863,7 @@ func TestValidateFinalityVoteProof(t *testing.T) { } input, err = contractAbi.Pack( - validateFinaltyVoteProof, + validateFinalityVoteProof, voterPublicKey, big.NewInt(int64(blockNumber)), targetBlockHashes, @@ -1879,7 +1879,7 @@ func TestValidateFinalityVoteProof(t *testing.T) { t.Fatalf("Expect to successfully verify proof, get %s", err) } - ret, err := contractAbi.Unpack(validateFinaltyVoteProof, rawReturn) + ret, err := contractAbi.Unpack(validateFinalityVoteProof, rawReturn) if err != nil { t.Fatalf("Failed to unpack output, err: %s", err) } @@ -1891,7 +1891,7 @@ func TestValidateFinalityVoteProof(t *testing.T) { } func BenchmarkPrecompiledValidateFinalityVoteProof(b *testing.B) { - contractAbi, err := abi.JSON(strings.NewReader(validateFinaltyVoteProofAbi)) + contractAbi, err := abi.JSON(strings.NewReader(validateFinalityVoteProofAbi)) if err != nil { b.Fatalf("Failed to parse ABI, err %s", err) } @@ -1937,7 +1937,7 @@ func BenchmarkPrecompiledValidateFinalityVoteProof(b *testing.B) { aggregatedSignature2 := blst.AggregateSignatures(signature[:]) input, err := contractAbi.Pack( - validateFinaltyVoteProof, + validateFinalityVoteProof, secretKeys[0].PublicKey().Marshal(), big.NewInt(int64(blockNumber)), [2]common.Hash{ @@ -1954,7 +1954,7 @@ func BenchmarkPrecompiledValidateFinalityVoteProof(b *testing.B) { b.Fatalf("Failed to pack contract input, err: %s", err) } - output, err := contractAbi.Methods[validateFinaltyVoteProof].Outputs.Pack(true) + output, err := contractAbi.Methods[validateFinalityVoteProof].Outputs.Pack(true) if err != nil { b.Fatalf("Failed to pack contract output, err: %s", err) }