mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-12 06:53:46 +00:00
Merge pull request #7 from primevprotocol/precompile-updates
precompile updates
This commit is contained in:
commit
0d63eca03f
1 changed files with 18 additions and 13 deletions
|
|
@ -77,21 +77,26 @@ func (c *mint) RequiredGas(input []byte) uint64 {
|
||||||
return 100
|
return 100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Predetermined create2 address of whitelist contract with exclusive mint/burn privileges.
|
||||||
|
// See: https://github.com/primevprotocol/contracts/blob/ecfd53d43770201da9c7a697be1fb03e5e554e4e/scripts/DeployScripts.s.sol
|
||||||
|
const whitelistCreate2Addr = "0xe57ee51bcb0914EC666703F923e0433d8c4d70b1"
|
||||||
|
|
||||||
func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) {
|
func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) {
|
||||||
|
|
||||||
// TODO: filter out non-allowed callers
|
if ctx.caller != common.HexToAddress(whitelistCreate2Addr) {
|
||||||
_ = common.BytesToAddress(input[0:32]) // From
|
return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted")
|
||||||
|
}
|
||||||
|
|
||||||
to := common.BytesToAddress(input[32:64])
|
mintTo := common.BytesToAddress(input[0:32])
|
||||||
|
|
||||||
var parsed bool
|
var parsed bool
|
||||||
value, parsed := math.ParseBig256(hexutil.Encode(input[64:96]))
|
value, parsed := math.ParseBig256(hexutil.Encode(input[32:64]))
|
||||||
if !parsed {
|
if !parsed {
|
||||||
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96]))
|
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mint case: Create native token out of thin air
|
// Create native token out of thin air
|
||||||
ctx.evm.StateDB.AddBalance(to, value)
|
ctx.evm.StateDB.AddBalance(mintTo, value)
|
||||||
|
|
||||||
return input, nil
|
return input, nil
|
||||||
}
|
}
|
||||||
|
|
@ -106,22 +111,22 @@ func (c *burn) RequiredGas(input []byte) uint64 {
|
||||||
|
|
||||||
func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) {
|
func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) {
|
||||||
|
|
||||||
// TODO: filter out non-allowed callers
|
if ctx.caller != common.HexToAddress(whitelistCreate2Addr) {
|
||||||
_ = common.BytesToAddress(input[0:32]) // From
|
return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted")
|
||||||
|
}
|
||||||
|
|
||||||
// Address to get their tokens burned
|
burnFrom := common.BytesToAddress(input[0:32])
|
||||||
addrReqTokenBurn := common.BytesToAddress(input[32:64])
|
|
||||||
|
|
||||||
var parsed bool
|
var parsed bool
|
||||||
value, parsed := math.ParseBig256(hexutil.Encode(input[64:96]))
|
value, parsed := math.ParseBig256(hexutil.Encode(input[32:64]))
|
||||||
if !parsed {
|
if !parsed {
|
||||||
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96]))
|
return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96]))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.CanTransfer(ctx.evm.StateDB, addrReqTokenBurn, value) {
|
if !ctx.CanTransfer(ctx.evm.StateDB, burnFrom, value) {
|
||||||
return nil, ErrInsufficientBalance
|
return nil, ErrInsufficientBalance
|
||||||
}
|
}
|
||||||
ctx.evm.StateDB.SubBalance(addrReqTokenBurn, value)
|
ctx.evm.StateDB.SubBalance(burnFrom, value)
|
||||||
|
|
||||||
return input, nil
|
return input, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue