11package vmimpl
22
33import (
4+ "fmt"
45 "math"
56 "math/big"
67 "os"
78 "runtime/debug"
89 "time"
910
11+ "github.com/iotaledger/wasp/clients/iota-go/iotago"
12+ "github.com/iotaledger/wasp/clients/iota-go/iotago/iotatest"
1013 "github.com/iotaledger/wasp/packages/coin"
1114 "github.com/iotaledger/wasp/packages/hashing"
1215 "github.com/iotaledger/wasp/packages/isc"
@@ -16,6 +19,7 @@ import (
1619 "github.com/iotaledger/wasp/packages/kv/codec"
1720 "github.com/iotaledger/wasp/packages/parameters"
1821 "github.com/iotaledger/wasp/packages/util"
22+ "github.com/iotaledger/wasp/packages/util/bcs"
1923 "github.com/iotaledger/wasp/packages/util/panicutil"
2024 "github.com/iotaledger/wasp/packages/vm"
2125 "github.com/iotaledger/wasp/packages/vm/core/accounts"
@@ -57,7 +61,7 @@ func (vmctx *vmContext) runRequest(req isc.Request, requestIndex uint16, mainten
5761
5862 result , err := reqctx .callTheContract ()
5963 if err == nil {
60- err = vmctx .checkTransactionSize () // TODO is this a concern now?
64+ err = vmctx .checkTransactionSize ()
6165 }
6266 if err != nil {
6367 // skip the request / rollback tx builder (no need to rollback the state, because the mutations will never be applied)
@@ -476,11 +480,23 @@ func (vmctx *vmContext) loadChainConfig() {
476480
477481// checkTransactionSize panics with ErrMaxTransactionSizeExceeded if the estimated transaction size exceeds the limit
478482func (vmctx * vmContext ) checkTransactionSize () error {
479- // TODO the following requirements we need to check
480- // * The encoded bytes of ptb should be smaller than `max_tx_size_bytes`
481- // * max_size_written_objects
482- // * max_serialized_tx_effects_size_bytes
483- // * max_pure_argument_size
484- vmctx .task .Log .Info ("TODO: checkTransactionSize" )
483+ const maxTxSizeBytes = 128 * 1024
484+ const maxInputObjects = 2048
485+ const maxProgrammableTxCommands = 1024
486+ ptb := vmctx .txbuilder .ViewPTB ()
487+ if ptb .Inputs .Len () > maxInputObjects {
488+ return fmt .Errorf ("ptb input len: %d, exceed max_input_objects" , ptb .Inputs .Len ())
489+ }
490+ if len (ptb .Commands ) > maxProgrammableTxCommands {
491+ return fmt .Errorf ("ptb input len: %d, exceed max_programmable_tx_commands" , len (ptb .Commands ))
492+ }
493+ pt := ptb .Finish ()
494+ tx := iotago .NewProgrammable (
495+ iotatest .RandomAddress (), pt , []* iotago.ObjectRef {iotatest .RandomObjectRef ()}, 0 , 0 ,
496+ )
497+ b , _ := bcs .Marshal (& tx )
498+ if len (b ) > maxTxSizeBytes {
499+ return fmt .Errorf ("ptb serialized size: %d, exceed max_tx_size_bytes" , maxTxSizeBytes )
500+ }
485501 return nil
486502}
0 commit comments