node/admin: check address lengths and fix typo in governance handler
This commit is contained in:
parent
3c3de23501
commit
e1c8bc8299
|
@ -604,6 +604,9 @@ func solanaCallToVaa(solanaCall *nodev1.SolanaCall, timestamp time.Time, guardia
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode base58 governance contract address: %w", err)
|
||||
}
|
||||
if len(address) != 32 {
|
||||
return nil, errors.New("invalid governance contract address length (expected 32 bytes)")
|
||||
}
|
||||
|
||||
var governanceContract [32]byte
|
||||
copy(governanceContract[:], address)
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/holiman/uint256"
|
||||
|
@ -427,11 +428,31 @@ func (r BodyWormholeRelayerSetDefaultDeliveryProvider) Serialize() []byte {
|
|||
return serializeBridgeGovernanceVaa(WormholeRelayerModuleStr, WormholeRelayerSetDefaultDeliveryProvider, r.ChainID, payload.Bytes())
|
||||
}
|
||||
|
||||
func allZero(b []byte) bool {
|
||||
for _, v := range b {
|
||||
if v != 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (r BodyGeneralPurposeGovernanceEvm) Serialize() []byte {
|
||||
payload := &bytes.Buffer{}
|
||||
payload.Write(r.GovernanceContract[:])
|
||||
payload.Write(r.TargetContract[:])
|
||||
if !allZero(r.GovernanceContract[0:12]) {
|
||||
panic("governance contract address must be 0-padded")
|
||||
}
|
||||
|
||||
if !allZero(r.TargetContract[0:12]) {
|
||||
panic("target contract address must be 0-padded")
|
||||
}
|
||||
|
||||
payload.Write(r.GovernanceContract[12:])
|
||||
payload.Write(r.TargetContract[12:])
|
||||
// write payload len as uint16
|
||||
if len(r.Payload) > math.MaxUint16 {
|
||||
panic("payload too long")
|
||||
}
|
||||
MustWrite(payload, binary.BigEndian, uint16(len(r.Payload)))
|
||||
payload.Write(r.Payload)
|
||||
return serializeBridgeGovernanceVaa(GeneralPurposeGovernanceModuleStr, GovernanceAction(1), r.ChainID, payload.Bytes())
|
||||
|
@ -440,7 +461,7 @@ func (r BodyGeneralPurposeGovernanceEvm) Serialize() []byte {
|
|||
func (r BodyGeneralPurposeGovernanceSolana) Serialize() []byte {
|
||||
payload := &bytes.Buffer{}
|
||||
payload.Write(r.GovernanceContract[:])
|
||||
// NOTE: unlike in EVM, we don't write the payload here, because we're using
|
||||
// NOTE: unlike in EVM, we don't write the payload length here, because we're using
|
||||
// a custom instruction encoding (there is no standard encoding like evm ABI
|
||||
// encoding), generated by an external tool. That tool length-prefixes all
|
||||
// the relevant dynamic fields.
|
||||
|
|
Loading…
Reference in New Issue