Skip to content

Commit

Permalink
Merge branch 'develop' into renovate/serde-1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemmsilva authored May 11, 2023
2 parents de1bbd5 + e76e7a6 commit 1ccbd41
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 250 deletions.
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/iotaledger/wasp
go 1.20

replace (
github.com/ethereum/go-ethereum => github.com/iotaledger/go-ethereum v1.10.26-wasp
github.com/ethereum/go-ethereum => github.com/iotaledger/go-ethereum v1.11.6-wasp
go.dedis.ch/kyber/v3 => github.com/kape1395/kyber/v3 v3.0.14-0.20230124095845-ec682ff08c93 // branch: dkg-2suites
)

Expand Down Expand Up @@ -45,7 +45,7 @@ require (
go.uber.org/dig v1.17.0
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.9.0
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea
golang.org/x/net v0.10.0
gopkg.in/yaml.v3 v3.0.1
nhooyr.io/websocket v1.8.7
Expand All @@ -54,24 +54,26 @@ require (

require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
github.com/benbjohnson/clock v1.3.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20230412222916-60cfeb46143b // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/eclipse/paho.mqtt.golang v1.4.2 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/edsrzf/mmap-go v1.0.0 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/flynn/noise v1.0.0 // indirect
Expand All @@ -83,10 +85,11 @@ require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-github v17.0.0+incompatible // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gopacket v1.1.19 // indirect
Expand All @@ -96,7 +99,6 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v0.6.0 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.2 // indirect
github.com/huin/goupnp v1.1.0 // indirect
Expand Down Expand Up @@ -158,15 +160,13 @@ require (
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/tsdb v0.10.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
github.com/quic-go/quic-go v0.34.0 // indirect
github.com/quic-go/webtransport-go v0.5.2 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rjeczalik/notify v0.9.3 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
Expand Down
47 changes: 20 additions & 27 deletions go.sum

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions packages/evm/jsonrpc/tracer_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strconv"
"strings"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -41,6 +40,8 @@ type callTracer struct {
reason error // Textual reason for the interruption
}

var _ tracers.Tracer = &callTracer{}

type callTracerConfig struct {
OnlyTopCall bool `json:"onlyTopCall"` // If true, call tracer won't collect any subcalls
}
Expand Down Expand Up @@ -76,7 +77,7 @@ func (t *callTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Ad
}

// CaptureEnd is called after the call finishes to finalize the tracing.
func (t *callTracer) CaptureEnd(output []byte, gasUsed uint64, _ time.Duration, err error) {
func (t *callTracer) CaptureEnd(output []byte, gasUsed uint64, err error) {
t.callstack[0].GasUsed = uintToHex(gasUsed)
if err != nil {
t.callstack[0].Error = err.Error()
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/jsonrpc/waspevmbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (b *WaspEVMBackend) EVMGasRatio() (util.Ratio32, error) {

func (b *WaspEVMBackend) EVMSendTransaction(tx *types.Transaction) error {
// Ensure the transaction has more gas than the basic Ethereum tx fee.
intrinsicGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, true)
intrinsicGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, true, true)
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion packages/vm/core/evm/emulator/blockchaindb.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,13 @@ func filterAndAppendToLogs(query *ethereum.FilterQuery, receipts []*types.Receip

type fakeHasher struct{}

var _ types.TrieHasher = &fakeHasher{}

func (d *fakeHasher) Reset() {
}

func (d *fakeHasher) Update(i1, i2 []byte) {
func (d *fakeHasher) Update(i1, i2 []byte) error {
return nil
}

func (d *fakeHasher) Hash() common.Hash {
Expand Down
74 changes: 31 additions & 43 deletions packages/vm/core/evm/emulator/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/iotaledger/wasp/packages/kv"
"github.com/iotaledger/wasp/packages/kv/subrealm"
"github.com/iotaledger/wasp/packages/util/panicutil"
"github.com/iotaledger/wasp/packages/vm/core/evm"
"github.com/iotaledger/wasp/packages/vm/vmcontext/vmexceptions"
)

Expand Down Expand Up @@ -59,7 +58,6 @@ func getConfig(chainID int) *params.ChainConfig {
ChainID: big.NewInt(int64(chainID)),
HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
EIP150Hash: common.Hash{},
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
Expand All @@ -69,6 +67,7 @@ func getConfig(chainID int) *params.ChainConfig {
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
Ethash: &params.EthashConfig{},
ShanghaiTime: new(uint64),
}
configCache.Add(chainID, c)
return c
Expand Down Expand Up @@ -162,6 +161,22 @@ func (e *EVMEmulator) ChainContext() core.ChainContext {
}
}

func coreMsgFromCallMsg(call ethereum.CallMsg, statedb *StateDB) *core.Message {
return &core.Message{
To: call.To,
From: call.From,
Nonce: statedb.GetNonce(call.From),
Value: call.Value,
GasLimit: call.Gas,
GasPrice: call.GasPrice,
GasFeeCap: call.GasFeeCap,
GasTipCap: call.GasTipCap,
Data: call.Data,
AccessList: call.AccessList,
SkipAccountChecks: false,
}
}

// CallContract executes a contract call, without committing changes to the state
func (e *EVMEmulator) CallContract(call ethereum.CallMsg, gasBurnEnable func(bool)) (*core.ExecutionResult, error) {
// Ensure message is initialized properly.
Expand All @@ -177,30 +192,34 @@ func (e *EVMEmulator) CallContract(call ethereum.CallMsg, gasBurnEnable func(boo
// run the EVM code on a buffered state (so that writes are not committed)
statedb := e.StateDB().Buffered().StateDB()

return e.applyMessage(callMsg{call}, statedb, pendingHeader, gasBurnEnable, nil)
return e.applyMessage(coreMsgFromCallMsg(call, statedb), statedb, pendingHeader, gasBurnEnable, nil)
}

func (e *EVMEmulator) applyMessage(
msg callMsg,
msg *core.Message,
statedb vm.StateDB,
header *types.Header,
gasBurnEnable func(bool),
tracer tracers.Tracer,
) (res *core.ExecutionResult, err error) {
// Set msg gas price to 0
msg.GasPrice = big.NewInt(0)
msg.GasFeeCap = big.NewInt(0)
msg.GasTipCap = big.NewInt(0)

blockContext := core.NewEVMBlockContext(header, e.ChainContext(), nil)
txContext := core.NewEVMTxContext(msg)

vmConfig := e.vmConfig
vmConfig.Tracer = tracer
vmConfig.Debug = vmConfig.Tracer != nil

vmEnv := vm.NewEVM(blockContext, txContext, statedb, e.chainConfig, vmConfig)

if msg.CallMsg.Gas > e.gasLimits.Call {
msg.CallMsg.Gas = e.gasLimits.Call
if msg.GasLimit > e.gasLimits.Call {
msg.GasLimit = e.gasLimits.Call
}

gasPool := core.GasPool(msg.Gas())
gasPool := core.GasPool(msg.GasLimit)
vmEnv.Reset(txContext, statedb)
if gasBurnEnable != nil {
gasBurnEnable(true)
Expand Down Expand Up @@ -238,27 +257,13 @@ func (e *EVMEmulator) SendTransaction(
return nil, nil, fmt.Errorf("invalid transaction nonce: got %d, want %d", tx.Nonce(), nonce)
}

msg, err := tx.AsMessage(types.MakeSigner(e.chainConfig, pendingHeader.Number), pendingHeader.BaseFee)
msg, err := core.TransactionToMessage(tx, types.MakeSigner(e.chainConfig, pendingHeader.Number), pendingHeader.BaseFee)
if err != nil {
return nil, nil, err
}

msgWithZeroGasPrice := callMsg{
CallMsg: ethereum.CallMsg{
From: msg.From(),
To: msg.To(),
Gas: msg.Gas(),
GasPrice: big.NewInt(0),
GasFeeCap: big.NewInt(0),
GasTipCap: big.NewInt(0),
Value: msg.Value(),
Data: msg.Data(),
AccessList: msg.AccessList(),
},
}

result, err := e.applyMessage(
msgWithZeroGasPrice,
msg,
statedb,
pendingHeader,
gasBurnEnable,
Expand Down Expand Up @@ -295,8 +300,8 @@ func (e *EVMEmulator) SendTransaction(
receipt.Status = types.ReceiptStatusSuccessful
}

if msg.To() == nil {
receipt.ContractAddress = crypto.CreateAddress(msg.From(), tx.Nonce())
if msg.To == nil {
receipt.ContractAddress = crypto.CreateAddress(msg.From, tx.Nonce())
}

buf.Commit()
Expand All @@ -313,23 +318,6 @@ func (e *EVMEmulator) Signer() types.Signer {
return evmutil.Signer(e.chainConfig.ChainID)
}

// callMsg implements core.Message to allow passing it as a transaction simulator.
type callMsg struct {
ethereum.CallMsg
}

func (m callMsg) From() common.Address { return m.CallMsg.From }
func (m callMsg) Nonce() uint64 { return 0 }
func (m callMsg) IsFake() bool { return true }
func (m callMsg) To() *common.Address { return m.CallMsg.To }
func (m callMsg) GasPrice() *big.Int { return evm.GasPrice } // we ignore the gas price set by the sender
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap }
func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
func (m callMsg) Data() []byte { return m.CallMsg.Data }
func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }

type chainContext struct {
engine consensus.Engine
}
Expand Down
16 changes: 16 additions & 0 deletions packages/vm/core/evm/emulator/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"

"github.com/iotaledger/wasp/packages/kv"
"github.com/iotaledger/wasp/packages/kv/buffered"
Expand Down Expand Up @@ -252,6 +253,21 @@ func (s *StateDB) Buffered() *BufferedStateDB {
return NewBufferedStateDB(s)
}

// GetTransientState implements vm.StateDB
func (*StateDB) GetTransientState(addr common.Address, key common.Hash) common.Hash {
panic("unimplemented")
}

// Prepare implements vm.StateDB
func (s *StateDB) Prepare(rules params.Rules, sender common.Address, coinbase common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList) {
// do nothing
}

// SetTransientState implements vm.StateDB
func (*StateDB) SetTransientState(addr common.Address, key common.Hash, value common.Hash) {
panic("unimplemented")
}

// BufferedStateDB is a wrapper for StateDB that writes all mutations into an in-memory buffer,
// leaving the original state unmodified until the mutations are applied manually with Commit().
type BufferedStateDB struct {
Expand Down
8 changes: 4 additions & 4 deletions packages/vm/core/testcore/sbtests/gas_limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func testBlockGasOverflow(t *testing.T, w bool) {
setupTestSandboxSC(t, ch, nil, w)
initialBlockInfo := ch.GetLatestBlockInfo()

// produce n requests over the block gas limit (each request uses the maximum amount of gas a call can use)
// produce 1 request over the block gas limit (each request uses the maximum amount of gas a call can use)
limits := ch.GetGasLimits()
nRequests := int(limits.MaxGasPerBlock / limits.MaxGasPerRequest)
nRequests := int(limits.MaxGasPerBlock/limits.MaxGasPerRequest) + 1
reqs := make([]isc.Request, nRequests)

for i := 0; i < nRequests; i++ {
Expand All @@ -75,14 +75,14 @@ func testBlockGasOverflow(t *testing.T, w bool) {
fullGasBlockInfo, err := ch.GetBlockInfo(initialBlockInfo.BlockIndex() + 1)
require.NoError(t, err)
// the request number #{nRequests} should overflow the block and be moved to the next one
require.Equal(t, int(fullGasBlockInfo.TotalRequests), nRequests-1)
require.Equal(t, nRequests-1, int(fullGasBlockInfo.TotalRequests))
// gas burned will be sightly below the limit
require.LessOrEqual(t, fullGasBlockInfo.GasBurned, limits.MaxGasPerBlock)

// 1 requests should be moved to the next block
followingBlockInfo, err := ch.GetBlockInfo(initialBlockInfo.BlockIndex() + 2)
require.NoError(t, err)
require.Equal(t, followingBlockInfo.TotalRequests, uint16(1))
require.Equal(t, uint16(1), followingBlockInfo.TotalRequests)

// no further blocks should have been produced
_, err = ch.GetBlockInfo(initialBlockInfo.BlockIndex() + 3)
Expand Down
10 changes: 5 additions & 5 deletions packages/vm/vmcontext/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ func (vmctx *VMContext) GasBurn(burnCode gas.BurnCode, par ...uint64) {
g := burnCode.Cost(par...)
vmctx.gasBurnLog.Record(burnCode, g)
vmctx.gasBurned += g
vmctx.gasBurnedTotal += g

if vmctx.gasBurnedTotal+g > vmctx.chainInfo.GasLimits.MaxGasPerBlock {
panic(vmexceptions.ErrBlockGasLimitExceeded)
}

if vmctx.gasBurned > vmctx.gasBudgetAdjusted {
vmctx.gasBurned = vmctx.gasBudgetAdjusted // do not charge more than the limit set by the request
panic(vm.ErrGasBudgetExceeded)
}

if vmctx.gasBurnedTotal+vmctx.gasBurned > vmctx.chainInfo.GasLimits.MaxGasPerBlock {
panic(vmexceptions.ErrBlockGasLimitExceeded) // panic if the current request gas overshoots the block limit
}
}

func (vmctx *VMContext) GasBudgetLeft() uint64 {
Expand Down
9 changes: 5 additions & 4 deletions packages/vm/vmcontext/runreq.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ func (vmctx *VMContext) callTheContract() (receipt *blocklog.RequestReceipt, cal
callRet = vmctx.callFromRequest()
// ensure at least the minimum amount of gas is charged
if vmctx.GasBurned() < gas.BurnCodeMinimumGasPerRequest1P.Cost() {
vmctx.gasBurnedTotal -= vmctx.gasBurned
vmctx.gasBurned = 0
vmctx.GasBurn(gas.BurnCodeMinimumGasPerRequest1P, vmctx.GasBurned())
}
Expand All @@ -204,6 +203,7 @@ func (vmctx *VMContext) callTheContract() (receipt *blocklog.RequestReceipt, cal
}
// charge gas fee no matter what
vmctx.chargeGasFee()

// write receipt no matter what
receipt = vmctx.writeReceiptToBlockLog(callErr)
return receipt, callRet
Expand Down Expand Up @@ -316,12 +316,13 @@ func (vmctx *VMContext) calcGuaranteedFeeTokens() uint64 {
// chargeGasFee takes burned tokens from the sender's account
// It should always be enough because gas budget is set affordable
func (vmctx *VMContext) chargeGasFee() {
defer func() {
vmctx.gasBurnedTotal += vmctx.gasBurned // add current request gas burn to the total of the block
}()
// ensure at least the minimum amount of gas is charged
minGas := gas.BurnCodeMinimumGasPerRequest1P.Cost()
if vmctx.GasBurned() < minGas {
currentGas := vmctx.gasBurned
if vmctx.gasBurned < minGas {
vmctx.gasBurned = minGas
vmctx.gasBurnedTotal += minGas - currentGas
}

vmctx.GasBurnEnable(false)
Expand Down
Loading

0 comments on commit 1ccbd41

Please sign in to comment.