Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove StarknetTransaction and friends #6745

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions cmd/rpcdaemon/cli/httpcfg/http_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ type HttpCfg struct {
TCPListenAddress string
TCPPort int

StarknetGRPCAddress string
JWTSecretPath string // Engine API Authentication
TraceRequests bool // Always trace requests in INFO level
HTTPTimeouts rpccfg.HTTPTimeouts
AuthRpcTimeouts rpccfg.HTTPTimeouts
EvmCallTimeout time.Duration
InternalCL bool
LogDirVerbosity string
LogDirPath string
JWTSecretPath string // Engine API Authentication
TraceRequests bool // Always trace requests in INFO level
HTTPTimeouts rpccfg.HTTPTimeouts
AuthRpcTimeouts rpccfg.HTTPTimeouts
EvmCallTimeout time.Duration
InternalCL bool
LogDirVerbosity string
LogDirPath string

BatchLimit int // Maximum number of requests in a batch
ReturnDataLimit int // Maximum number of bytes retutned from calls (like eth_call)
Expand Down
26 changes: 9 additions & 17 deletions cmd/state/exec3/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ type Worker struct {
isPoSA bool
posa consensus.PoSA

starkNetEvm *vm.CVMAdapter
evm *vm.EVM

evm *vm.EVM
ibs *state.IntraBlockState
}

Expand All @@ -68,8 +66,7 @@ func NewWorker(lock sync.Locker, ctx context.Context, background bool, chainDb k
resultCh: resultCh,
engine: engine,

starkNetEvm: &vm.CVMAdapter{Cvm: vm.NewCVM(nil)},
evm: vm.NewEVM(evmtypes.BlockContext{}, evmtypes.TxContext{}, nil, chainConfig, vm.Config{}),
evm: vm.NewEVM(evmtypes.BlockContext{}, evmtypes.TxContext{}, nil, chainConfig, vm.Config{}),
}
w.getHeader = func(hash libcommon.Hash, number uint64) *types.Header {
h, err := blockReader.Header(ctx, w.chainTx, hash, number)
Expand Down Expand Up @@ -189,19 +186,14 @@ func (rw *Worker) RunTxTask(txTask *exec22.TxTask) {
ibs.Prepare(txHash, txTask.BlockHash, txTask.TxIndex)
msg := txTask.TxAsMessage

var vmenv vm.VMInterface
if txTask.Tx.IsStarkNet() {
rw.starkNetEvm.Reset(evmtypes.TxContext{}, ibs)
vmenv = rw.starkNetEvm
} else {
blockContext := txTask.EvmBlockContext
if !rw.background {
getHashFn := core.GetHashFn(header, rw.getHeader)
blockContext = core.NewEVMBlockContext(header, getHashFn, rw.engine, nil /* author */)
}
rw.evm.ResetBetweenBlocks(blockContext, core.NewEVMTxContext(msg), ibs, vmConfig, rules)
vmenv = rw.evm
blockContext := txTask.EvmBlockContext
if !rw.background {
getHashFn := core.GetHashFn(header, rw.getHeader)
blockContext = core.NewEVMBlockContext(header, getHashFn, rw.engine, nil /* author */)
}
rw.evm.ResetBetweenBlocks(blockContext, core.NewEVMTxContext(msg), ibs, vmConfig, rules)
vmenv := rw.evm

applyRes, err := core.ApplyMessage(vmenv, msg, gp, true /* refunds */, false /* gasBailout */)
if err != nil {
txTask.Error = err
Expand Down
16 changes: 4 additions & 12 deletions cmd/state/exec3/state_recon.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,8 @@ type ReconWorker struct {
isPoSA bool
posa consensus.PoSA

starkNetEvm *vm.CVMAdapter
evm *vm.EVM
ibs *state.IntraBlockState
evm *vm.EVM
ibs *state.IntraBlockState
}

func NewReconWorker(lock sync.Locker, wg *sync.WaitGroup, rs *state.ReconState,
Expand All @@ -256,7 +255,6 @@ func NewReconWorker(lock sync.Locker, wg *sync.WaitGroup, rs *state.ReconState,
logger: logger,
genesis: genesis,
engine: engine,
starkNetEvm: &vm.CVMAdapter{Cvm: vm.NewCVM(nil)},
evm: vm.NewEVM(evmtypes.BlockContext{}, evmtypes.TxContext{}, nil, chainConfig, vm.Config{}),
}
rw.epoch = NewEpochReader(chainTx)
Expand Down Expand Up @@ -347,14 +345,8 @@ func (rw *ReconWorker) runTxTask(txTask *exec22.TxTask) {
ibs.Prepare(txTask.Tx.Hash(), txTask.BlockHash, txTask.TxIndex)
msg := txTask.TxAsMessage

var vmenv vm.VMInterface
if txTask.Tx.IsStarkNet() {
rw.starkNetEvm.Reset(evmtypes.TxContext{}, ibs)
vmenv = rw.starkNetEvm
} else {
rw.evm.ResetBetweenBlocks(txTask.EvmBlockContext, core.NewEVMTxContext(msg), ibs, vmConfig, txTask.Rules)
vmenv = rw.evm
}
rw.evm.ResetBetweenBlocks(txTask.EvmBlockContext, core.NewEVMTxContext(msg), ibs, vmConfig, txTask.Rules)
vmenv := rw.evm
//fmt.Printf("txNum=%d, blockNum=%d, txIndex=%d\n", txTask.TxNum, txTask.BlockNum, txTask.TxIndex)
_, err = core.ApplyMessage(vmenv, msg, gp, true /* refunds */, false /* gasBailout */)
if err != nil {
Expand Down
138 changes: 0 additions & 138 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/common/length"
"github.com/ledgerwatch/erigon-lib/crypto/cryptopool"

"github.com/ledgerwatch/erigon/common/hexutil"
)
Expand All @@ -39,12 +38,6 @@ const (
BlockNumberLength = 8
// IncarnationLength length of uint64 for contract incarnations
IncarnationLength = 8
// Address32Length is the expected length of the Starknet address (in bytes)
Address32Length = 32
)

var (
addressSt = reflect.TypeOf(Address32{})
)

// UnprefixedHash allows marshaling a Hash without 0x prefix.
Expand Down Expand Up @@ -183,134 +176,3 @@ func (keys StorageKeys) Less(i, j int) bool {
func (keys StorageKeys) Swap(i, j int) {
keys[i], keys[j] = keys[j], keys[i]
}

/////////// Address32

// Address32 represents the 32 byte address.
type Address32 [Address32Length]byte

// BytesToAddress32 returns Address32 with value b.
// If b is larger than len(h), b will be cropped from the left.
func BytesToAddress32(b []byte) Address32 {
var a Address32
a.SetBytes(b)
return a
}

// HexToAddress32 returns Address32 with byte values of s.
// If s is larger than len(h), s will be cropped from the left.
func HexToAddress32(s string) Address32 { return BytesToAddress32(FromHex(s)) }

// IsHexAddress32 verifies whether a string can represent a valid hex-encoded
// Starknet address or not.
func IsHexAddress32(s string) bool {
if has0xPrefix(s) {
s = s[2:]
}
return len(s) == 2*Address32Length && isHex(s)
}

// Bytes gets the string representation of the underlying address.
func (a Address32) Bytes() []byte { return a[:] }

// Hash converts an address to a hash by left-padding it with zeros.
func (a Address32) Hash() libcommon.Hash { return libcommon.BytesToHash(a[:]) }

// Hex returns an EIP55-compliant hex string representation of the address.
func (a Address32) Hex() string {
return string(a.checksumHex())
}

// String implements fmt.Stringer.
func (a Address32) String() string {
return a.Hex()
}

func (a *Address32) checksumHex() []byte {
buf := a.hex()

// compute checksum
sha := cryptopool.GetLegacyKeccak256()
//nolint:errcheck
sha.Write(buf[2:])
hash := sha.Sum(nil)
cryptopool.ReturnLegacyKeccak256(sha)
for i := 2; i < len(buf); i++ {
hashByte := hash[(i-2)/2]
if i%2 == 0 {
hashByte = hashByte >> 4
} else {
hashByte &= 0xf
}
if buf[i] > '9' && hashByte > 7 {
buf[i] -= 32
}
}
return buf
}

func (a Address32) hex() []byte {
var buf [len(a)*2 + 2]byte
copy(buf[:2], "0x")
hex.Encode(buf[2:], a[:])
return buf[:]
}

// SetBytes sets the address to the value of b.
// If b is larger than len(a), b will be cropped from the left.
func (a *Address32) SetBytes(b []byte) {
if len(b) > len(a) {
b = b[len(b)-Address32Length:]
}
copy(a[Address32Length-len(b):], b)
}

// MarshalText returns the hex representation of a.
func (a Address32) MarshalText() ([]byte, error) {
return hexutil.Bytes(a[:]).MarshalText()
}

// UnmarshalText parses a hash in hex syntax.
func (a *Address32) UnmarshalText(input []byte) error {
return hexutility.UnmarshalFixedText("Address", input, a[:])
}

// UnmarshalJSON parses a hash in hex syntax.
func (a *Address32) UnmarshalJSON(input []byte) error {
return hexutility.UnmarshalFixedJSON(addressSt, input, a[:])
}

// ToCommonAddress converts Address32 to Address
func (a *Address32) ToCommonAddress() libcommon.Address {
ad := libcommon.Address{}
ad.SetBytes(a.Bytes())
return ad
}

// Format implements fmt.Formatter.
// Address32 supports the %v, %s, %v, %x, %X and %d format verbs.
func (a Address32) Format(s fmt.State, c rune) {
switch c {
case 'v', 's':
s.Write(a.checksumHex())
case 'q':
q := []byte{'"'}
s.Write(q)
s.Write(a.checksumHex())
s.Write(q)
case 'x', 'X':
// %x disables the checksum.
hex := a.hex()
if !s.Flag('#') {
hex = hex[2:]
}
if c == 'X' {
hex = bytes.ToUpper(hex)
}
s.Write(hex)
case 'd':
fmt.Fprint(s, ([len(a)]byte)(a))
default:
fmt.Fprintf(s, "%%!%c(address=%x)", c, a)
}
}
Loading