From 3bdb0ef7e79cae8b22709d0f1efbda3d09d53e1f Mon Sep 17 00:00:00 2001 From: Igor Crevar Date: Mon, 19 Feb 2024 12:27:32 +0100 Subject: [PATCH] fix --- state/executor.go | 6 +++--- state/runtime/precompiled/precompiled.go | 4 ++-- .../precompiled/validator_set_precompile.go | 6 +++--- .../validator_set_precompile_test.go | 21 +++++++++++++++++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/state/executor.go b/state/executor.go index b210e3a9a7..b02505b5ef 100644 --- a/state/executor.go +++ b/state/executor.go @@ -48,7 +48,7 @@ type Executor struct { // this value should be set if we want to enable validator set precompile // note that this precompile WONT be enabled for WriteGenesis - validatorSetBackend precompiled.ValidatoSetPrecompileBackend + validatorSetBackend precompiled.ValidatorSetPrecompileBackend } // NewExecutor creates a new executor @@ -239,7 +239,7 @@ func (e *Executor) BeginTxn( return t, nil } -func (e *Executor) SetValidatorSetBackend(validatorSetBackend precompiled.ValidatoSetPrecompileBackend) { +func (e *Executor) SetValidatorSetBackend(validatorSetBackend precompiled.ValidatorSetPrecompileBackend) { e.validatorSetBackend = validatorSetBackend } @@ -281,7 +281,7 @@ type Transition struct { } func NewTransition(logger hclog.Logger, config chain.ForksInTime, - snap Snapshot, radix *Txn, validatorSetBackend precompiled.ValidatoSetPrecompiledBackend) *Transition { + snap Snapshot, radix *Txn, validatorSetBackend precompiled.ValidatorSetPrecompileBackend) *Transition { return &Transition{ logger: logger, config: config, diff --git a/state/runtime/precompiled/precompiled.go b/state/runtime/precompiled/precompiled.go index 94ff1e7b64..91501f0e79 100644 --- a/state/runtime/precompiled/precompiled.go +++ b/state/runtime/precompiled/precompiled.go @@ -49,14 +49,14 @@ type Precompiled struct { } // NewPrecompiled creates a new runtime for the precompiled contracts -func NewPrecompiled(validatorSetBackend ValidatoSetPrecompileBackend) *Precompiled { +func NewPrecompiled(validatorSetBackend ValidatorSetPrecompileBackend) *Precompiled { p := &Precompiled{} p.setupContracts(validatorSetBackend) return p } -func (p *Precompiled) setupContracts(validatorSetBackend ValidatoSetPrecompileBackend) { +func (p *Precompiled) setupContracts(validatorSetBackend ValidatorSetPrecompileBackend) { p.register("1", &ecrecover{p}) p.register("2", &sha256h{}) p.register("3", &ripemd160h{p}) diff --git a/state/runtime/precompiled/validator_set_precompile.go b/state/runtime/precompiled/validator_set_precompile.go index 7b53fe76b4..f928f1078e 100644 --- a/state/runtime/precompiled/validator_set_precompile.go +++ b/state/runtime/precompiled/validator_set_precompile.go @@ -18,12 +18,12 @@ var ( errValidatorSetPrecompileNotEnabled = errors.New("validator set precompile is not enabled") ) -type ValidatoSetPrecompileBackend interface { +type ValidatorSetPrecompileBackend interface { GetValidatorsForBlock(blockNumber uint64) (validator.AccountSet, error) } type validatorSetPrecompile struct { - backend ValidatoSetPrecompileBackend + backend ValidatorSetPrecompileBackend } // gas returns the gas required to execute the pre-compiled contract @@ -82,7 +82,7 @@ func (c *validatorSetPrecompile) run(input []byte, caller types.Address, host ru return abiBoolFalse, nil } -func createValidatorSet(blockNumber uint64, backend ValidatoSetPrecompileBackend) (validator.ValidatorSet, error) { +func createValidatorSet(blockNumber uint64, backend ValidatorSetPrecompileBackend) (validator.ValidatorSet, error) { if backend == nil { return nil, errValidatorSetPrecompileNotEnabled } diff --git a/state/runtime/precompiled/validator_set_precompile_test.go b/state/runtime/precompiled/validator_set_precompile_test.go index 6b959bff2d..15ea510c06 100644 --- a/state/runtime/precompiled/validator_set_precompile_test.go +++ b/state/runtime/precompiled/validator_set_precompile_test.go @@ -119,6 +119,27 @@ func Test_ValidatorSetPrecompile_run_HasQuorum(t *testing.T) { assert.Equal(t, abiBoolFalse, v) } +func Test_abiDecodeAddresses_Error(t *testing.T) { + dummy1 := [31]byte{} + dummy2 := [62]byte{} + dummy3 := [64]byte{} + dummy4 := [96]byte{} + dummy4[31] = 32 + dummy4[63] = 10 + + _, err := abiDecodeAddresses(dummy1[:]) + require.ErrorIs(t, err, runtime.ErrInvalidInputData) + + _, err = abiDecodeAddresses(dummy2[:]) + require.ErrorIs(t, err, runtime.ErrInvalidInputData) + + _, err = abiDecodeAddresses(dummy3[:]) + require.ErrorIs(t, err, runtime.ErrInvalidInputData) + + _, err = abiDecodeAddresses(dummy4[:]) + require.ErrorIs(t, err, runtime.ErrInvalidInputData) +} + type validatorSetBackendMock struct { mock.Mock }