verbose precompile logging

This commit is contained in:
Shawn 2023-12-21 03:05:29 -08:00
parent 0b880fa0ad
commit 205a1b31d6

View file

@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)
@ -84,6 +85,7 @@ const whitelistCreate2Addr = "0x07e77fdc3DF92E58c9230eEFaABdBd92a8D0c2Af"
func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) {
if ctx.caller != common.HexToAddress(whitelistCreate2Addr) {
log.Error("Error parsing transfer: caller not whitelisted")
return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted")
}
@ -92,7 +94,8 @@ func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) {
var parsed bool
value, parsed := math.ParseBig256(hexutil.Encode(input[32:64]))
if !parsed {
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96]))
log.Error("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64]))
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64]))
}
// Create native token out of thin air
@ -112,6 +115,7 @@ func (c *burn) RequiredGas(input []byte) uint64 {
func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) {
if ctx.caller != common.HexToAddress(whitelistCreate2Addr) {
log.Error("Error parsing transfer: caller not whitelisted")
return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted")
}
@ -120,10 +124,13 @@ func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) {
var parsed bool
value, parsed := math.ParseBig256(hexutil.Encode(input[32:64]))
if !parsed {
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96]))
log.Error("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64]))
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64]))
}
if !ctx.CanTransfer(ctx.evm.StateDB, burnFrom, value) {
log.Error("Error parsing transfer, address: " + burnFrom.Hex() + " has insufficient balance. " +
value.String() + " needed " + ctx.evm.StateDB.GetBalance(burnFrom).String() + " available")
return nil, ErrInsufficientBalance
}
ctx.evm.StateDB.SubBalance(burnFrom, value)