From 53041a03e7d5e96b109174a13b9e195fc04b2bb7 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Tue, 12 Dec 2023 01:40:32 -0800 Subject: [PATCH 1/4] whitelistaddr var and less params --- core/vm/contracts_with_ctx.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/core/vm/contracts_with_ctx.go b/core/vm/contracts_with_ctx.go index 8b36f91b33b3..cefac1edc670 100644 --- a/core/vm/contracts_with_ctx.go +++ b/core/vm/contracts_with_ctx.go @@ -77,21 +77,25 @@ func (c *mint) RequiredGas(input []byte) uint64 { return 100 } +// TODO +const whitelistCreate2Addr = "0x000000" + func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) { - // TODO: filter out non-allowed callers - _ = common.BytesToAddress(input[0:32]) // From + if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { + 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 - value, parsed := math.ParseBig256(hexutil.Encode(input[64:96])) + 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])) } - // Mint case: Create native token out of thin air - ctx.evm.StateDB.AddBalance(to, value) + // Create native token out of thin air + ctx.evm.StateDB.AddBalance(mintTo, value) return input, nil } @@ -106,22 +110,22 @@ func (c *burn) RequiredGas(input []byte) uint64 { func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) { - // TODO: filter out non-allowed callers - _ = common.BytesToAddress(input[0:32]) // From + if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { + return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted") + } - // Address to get their tokens burned - addrReqTokenBurn := common.BytesToAddress(input[32:64]) + burnFrom := common.BytesToAddress(input[0:32]) var parsed bool - value, parsed := math.ParseBig256(hexutil.Encode(input[64:96])) + 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])) } - if !ctx.CanTransfer(ctx.evm.StateDB, addrReqTokenBurn, value) { + if !ctx.CanTransfer(ctx.evm.StateDB, burnFrom, value) { return nil, ErrInsufficientBalance } - ctx.evm.StateDB.SubBalance(addrReqTokenBurn, value) + ctx.evm.StateDB.SubBalance(burnFrom, value) return input, nil } From 782bb41681d2799f99de11491585fe11a337af01 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Tue, 12 Dec 2023 02:03:36 -0800 Subject: [PATCH 2/4] todos --- core/vm/contracts_with_ctx.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/vm/contracts_with_ctx.go b/core/vm/contracts_with_ctx.go index cefac1edc670..9708f2d0560b 100644 --- a/core/vm/contracts_with_ctx.go +++ b/core/vm/contracts_with_ctx.go @@ -80,6 +80,7 @@ func (c *mint) RequiredGas(input []byte) uint64 { // TODO const whitelistCreate2Addr = "0x000000" +// TODO: confirm new abi schema works with contract func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) { if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { @@ -108,6 +109,7 @@ func (c *burn) RequiredGas(input []byte) uint64 { return 100 } +// TODO: confirm new abi schema works with contract func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) { if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { From a73391dc4229af1eb3f24ffce11557f9560260d2 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Tue, 12 Dec 2023 23:20:31 -0800 Subject: [PATCH 3/4] Update contracts_with_ctx.go --- core/vm/contracts_with_ctx.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/core/vm/contracts_with_ctx.go b/core/vm/contracts_with_ctx.go index 9708f2d0560b..76493661a172 100644 --- a/core/vm/contracts_with_ctx.go +++ b/core/vm/contracts_with_ctx.go @@ -77,15 +77,14 @@ func (c *mint) RequiredGas(input []byte) uint64 { return 100 } -// TODO +// Predetermined create2 address of whitelist contract with exclusive mint/burn privileges. const whitelistCreate2Addr = "0x000000" -// TODO: confirm new abi schema works with contract func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) { - if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { - return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted") - } + // if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { + // return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted") + // } mintTo := common.BytesToAddress(input[0:32]) @@ -109,12 +108,11 @@ func (c *burn) RequiredGas(input []byte) uint64 { return 100 } -// TODO: confirm new abi schema works with contract func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) { - if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { - return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted") - } + // if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { + // return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted") + // } burnFrom := common.BytesToAddress(input[0:32]) From 80679748c92292cd52f82f7ae9b24079f26c8b8f Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Wed, 13 Dec 2023 03:31:44 -0800 Subject: [PATCH 4/4] whitelist filtering --- core/vm/contracts_with_ctx.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/vm/contracts_with_ctx.go b/core/vm/contracts_with_ctx.go index 76493661a172..2bae3c133b7c 100644 --- a/core/vm/contracts_with_ctx.go +++ b/core/vm/contracts_with_ctx.go @@ -78,13 +78,14 @@ func (c *mint) RequiredGas(input []byte) uint64 { } // Predetermined create2 address of whitelist contract with exclusive mint/burn privileges. -const whitelistCreate2Addr = "0x000000" +// 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) { - // if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { - // return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted") - // } + if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { + return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted") + } mintTo := common.BytesToAddress(input[0:32]) @@ -110,9 +111,9 @@ func (c *burn) RequiredGas(input []byte) uint64 { func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) { - // if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { - // return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted") - // } + if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { + return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted") + } burnFrom := common.BytesToAddress(input[0:32])