Skip to content

Commit

Permalink
Merge pull request bnb-chain#18 from Ankr-network/audit-fixes
Browse files Browse the repository at this point in the history
Certik Audit Fixes
  • Loading branch information
hedwig0x authored Jul 26, 2022
2 parents b0ca4dc + 57ef9e7 commit 10d2bac
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 304 deletions.
Binary file added audit/2022-07-26-Certik.pdf
Binary file not shown.
6 changes: 5 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,11 @@ func unlockAccounts(ctx *cli.Context, stack *node.Node) {
}
// If insecure account unlocking is not allowed if node's APIs are exposed to external.
// Print warning log to user and skip unlocking.
if !stack.Config().InsecureUnlockAllowed && stack.Config().ExtRPCEnabled() {
isDevMode := false
if ctx.GlobalIsSet(utils.NetworkIdFlag.Name) && ctx.GlobalUint64(utils.NetworkIdFlag.Name) == 1337 {
isDevMode = true
}
if !stack.Config().InsecureUnlockAllowed && stack.Config().ExtRPCEnabled() && !isDevMode {
utils.Fatalf("Account unlock with HTTP access is forbidden!")
}
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
Expand Down
10 changes: 9 additions & 1 deletion consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,14 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he
state.SetBalance(consensus.SystemAddress, big.NewInt(0))
state.AddBalance(coinbase, balance)

if rules := p.chainConfig.Rules(header.Number); rules.HasBlockRewards {
blockRewards := p.chainConfig.Parlia.BlockRewards
// if we have enabled block rewards and rewards are greater than 0 then
if blockRewards != nil && blockRewards.Cmp(common.Big0) > 0 {
state.AddBalance(coinbase, blockRewards)
}
}

doDistributeSysReward := state.GetBalance(common.HexToAddress(systemcontract.SystemRewardContract)).Cmp(maxSystemBalance) < 0
if doDistributeSysReward {
var rewards = new(big.Int)
Expand Down Expand Up @@ -1346,7 +1354,7 @@ func applyMessage(
msg.Gas(),
msg.Value(),
)
if err != nil {
if err != nil && len(ret) > 64 {
log.Error("apply message failed", "msg", string(ret[64+4:]), "err", err)
}
return msg.Gas() - returnGas, err
Expand Down
34 changes: 0 additions & 34 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,40 +109,6 @@ type genesisAccountMarshaling struct {
PrivateKey hexutil.Bytes
}

//type logJSON struct {
// Address common.Address `json:"address" gencodec:"required"`
// Topics []common.Hash `json:"topics" gencodec:"required"`
// Data hexutil.Bytes `json:"data" gencodec:"required"`
// // remove fields
// BlockNumber uint64 `json:"blockNumber,omitempty"`
// TxHash common.Hash `json:"transactionHash,omitempty"`
// TxIndex uint `json:"transactionIndex,omitempty"`
// BlockHash common.Hash `json:"blockHash,omitempty"`
// Index uint `json:"logIndex,omitempty"`
// Removed bool `json:"removed,omitempty"`
//}
//
//func (h *logJSON) UnmarshalText(text []byte) error {
// return json.Unmarshal(text, h)
//}
//
//func (h *logJSON) MarshalText() ([]byte, error) {
// type jsonLog struct {
// Address hexutil.Bytes `json:"address" gencodec:"required"`
// Topics []hexutil.Bytes `json:"topics" gencodec:"required"`
// Data hexutil.Bytes `json:"data" gencodec:"required"`
// }
// var topics []hexutil.Bytes
// for _, t := range h.Topics {
// topics = append(topics, t.Bytes())
// }
// return json.Marshal(jsonLog{
// Address: h.Address.Bytes(),
// Topics: topics,
// Data: h.Data,
// })
//}

// storageJSON represents a 256 bit byte array, but allows less than 256 bits when
// unmarshaling from hex.
type storageJSON common.Hash
Expand Down
11 changes: 0 additions & 11 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package vm

import (
"errors"
systemcontract2 "github.com/ethereum/go-ethereum/core/vm/systemcontract"
"math/big"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -51,16 +50,6 @@ type (
)

func (evm *EVM) precompile(addr, caller common.Address) (PrecompiledContract, bool) {
evmHook := systemcontract2.CreateEvmHook(addr, systemcontract2.EvmHookContext{
CallerAddress: caller,
StateDb: evm.StateDB,
Evm: evm,
ChainConfig: evm.chainConfig,
ChainRules: evm.chainRules,
})
if evmHook != nil {
return evmHook, true
}
var precompiles map[common.Address]PrecompiledContract
switch {
case evm.chainRules.IsBerlin:
Expand Down
10 changes: 0 additions & 10 deletions core/vm/systemcontract/error.go

This file was deleted.

13 changes: 0 additions & 13 deletions core/vm/systemcontract/factory.go

This file was deleted.

31 changes: 0 additions & 31 deletions core/vm/systemcontract/types.go

This file was deleted.

95 changes: 0 additions & 95 deletions core/vm/systemcontract/upgrade.go

This file was deleted.

91 changes: 0 additions & 91 deletions core/vm/systemcontract/upgrade_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion genesis
Loading

0 comments on commit 10d2bac

Please sign in to comment.