diff --git a/contracts/wasm/testcore/go/testcoreimpl/funcs.go b/contracts/wasm/testcore/go/testcoreimpl/funcs.go index 9f81be144b..6000fa589d 100644 --- a/contracts/wasm/testcore/go/testcoreimpl/funcs.go +++ b/contracts/wasm/testcore/go/testcoreimpl/funcs.go @@ -18,10 +18,10 @@ const ( MsgDoNothing = "========== doing nothing" MsgFailOnPurpose = "failing on purpose" - MsgFullPanic = "========== panic FULL ENTRY POINT =========" + MsgFullPanic = "========== panic FULL ENTRY POINT ==========" MsgJustView = "calling empty view entry point" - MsgViewPanic = "========== panic VIEW =========" + MsgViewPanic = "========== panic VIEW ==========" ) func funcCallOnChain(ctx wasmlib.ScFuncContext, f *CallOnChainContext) { @@ -242,13 +242,10 @@ func funcWithdrawFromChain(ctx wasmlib.ScFuncContext, f *WithdrawFromChainContex transfer := wasmlib.ScTransferFromBalances(ctx.Allowance()) ctx.TransferAllowed(ctx.AccountID(), transfer) - // This is just a test contract, but normally these numbers should - // be parameters because there is no way for the contract to figure - // out the gas fees on the other chain, and it's also silly to run - // the costly calculation to determine storage deposit every time - // unless absolutely necessary. Better to just make sure that the - // storage deposit is large enough, since it will be returned anyway. - const gasFee = wasmlib.MinGasFee + var gasReserveTransferAccountToChain = wasmlib.MinGasFee + if f.Params.GasReserveTransferAccountToChain().Exists() { + gasReserveTransferAccountToChain = f.Params.GasReserveTransferAccountToChain().Value() + } var gasReserve = wasmlib.MinGasFee if f.Params.GasReserve().Exists() { gasReserve = f.Params.GasReserve().Value() @@ -261,7 +258,7 @@ func funcWithdrawFromChain(ctx wasmlib.ScFuncContext, f *WithdrawFromChainContex // NOTE: make sure you READ THE DOCS before calling this function xfer := coreaccounts.ScFuncs.TransferAccountToChain(ctx) xfer.Params.GasReserve().SetValue(gasReserve) - xfer.Func.TransferBaseTokens(storageDeposit + gasFee + gasReserve). + xfer.Func.TransferBaseTokens(storageDeposit + gasReserveTransferAccountToChain + gasReserve). AllowanceBaseTokens(withdrawal + storageDeposit + gasReserve). PostToChain(targetChain) } diff --git a/contracts/wasm/testcore/rs/testcoreimpl/src/funcs.rs b/contracts/wasm/testcore/rs/testcoreimpl/src/funcs.rs index d423b9cc51..6b97d7de56 100644 --- a/contracts/wasm/testcore/rs/testcoreimpl/src/funcs.rs +++ b/contracts/wasm/testcore/rs/testcoreimpl/src/funcs.rs @@ -8,8 +8,8 @@ use crate::*; const CONTRACT_NAME_DEPLOYED: &str = "exampleDeployTR"; const MSG_CORE_ONLY_PANIC: &str = "========== core only ========="; -const MSG_FULL_PANIC: &str = "========== panic FULL ENTRY POINT ========="; -const MSG_VIEW_PANIC: &str = "========== panic VIEW ========="; +const MSG_FULL_PANIC: &str = "========== panic FULL ENTRY POINT =========="; +const MSG_VIEW_PANIC: &str = "========== panic VIEW =========="; pub fn func_call_on_chain(ctx: &ScFuncContext, f: &CallOnChainContext) { let param_int = f.params.n().value(); @@ -255,13 +255,11 @@ pub fn func_withdraw_from_chain(ctx: &ScFuncContext, f: &WithdrawFromChainContex let transfer = ScTransfer::from_balances(&ctx.allowance()); ctx.transfer_allowed(&ctx.account_id(), &transfer); - // This is just a test contract, but normally these numbers should - // be parameters because there is no way for the contract to figure - // out the gas fees on the other chain, and it's also silly to run - // the costly calculation to determine storage deposit every time - // unless absolutely necessary. Better to just make sure that the - // storage deposit is large enough, since it will be returned anyway. - let gas_fee: u64 = MIN_GAS_FEE; + let mut gas_reserve_transfer_account_to_chain: u64 = MIN_GAS_FEE; + if f.params.gas_reserve_transfer_account_to_chain().exists() { + gas_reserve_transfer_account_to_chain = + f.params.gas_reserve_transfer_account_to_chain().value(); + } let mut gas_reserve: u64 = MIN_GAS_FEE; if f.params.gas_reserve().exists() { gas_reserve = f.params.gas_reserve().value(); @@ -275,7 +273,7 @@ pub fn func_withdraw_from_chain(ctx: &ScFuncContext, f: &WithdrawFromChainContex let xfer = coreaccounts::ScFuncs::transfer_account_to_chain(ctx); xfer.params.gas_reserve().set_value(gas_reserve); xfer.func - .transfer_base_tokens(storage_deposit + gas_fee + gas_reserve) + .transfer_base_tokens(storage_deposit + gas_reserve_transfer_account_to_chain + gas_reserve) .allowance_base_tokens(withdrawal + storage_deposit + gas_reserve) .post_to_chain(target_chain); } diff --git a/contracts/wasm/testcore/schema.yaml b/contracts/wasm/testcore/schema.yaml index 005900148b..3b773dbe96 100644 --- a/contracts/wasm/testcore/schema.yaml +++ b/contracts/wasm/testcore/schema.yaml @@ -94,6 +94,7 @@ funcs: chainID: ChainID baseTokens: Uint64 gasReserve: Uint64? + gasReserveTransferAccountToChain: Uint64? views: checkContextFromViewEP: diff --git a/contracts/wasm/testcore/test/2chains_test.go b/contracts/wasm/testcore/test/2chains_test.go index f371a40203..31e836aaa1 100644 --- a/contracts/wasm/testcore/test/2chains_test.go +++ b/contracts/wasm/testcore/test/2chains_test.go @@ -125,11 +125,16 @@ func Test2Chains(t *testing.T) { // allowance for accounts.transferAccountToChain(): SD + GAS1 + GAS2 xferDeposit := wasmlib.StorageDeposit - xferAllowance := xferDeposit + wasmlib.MinGasFee + wasmlib.MinGasFee + const gasFeeTransferAccountToChain = 10 * wasmlib.MinGasFee + const gasReserve = 10 * wasmlib.MinGasFee + const gasWithdrawFromChain = 10 * wasmlib.MinGasFee + xferAllowance := xferDeposit + gasReserve + gasFeeTransferAccountToChain f := testcore.ScFuncs.WithdrawFromChain(ctx2.Sign(user)) f.Params.ChainID().SetValue(ctx1.CurrentChainID()) f.Params.BaseTokens().SetValue(withdrawalAmount) - f.Func.TransferBaseTokens(xferAllowance + isc.Million). + f.Params.GasReserve().SetValue(gasReserve) + f.Params.GasReserveTransferAccountToChain().SetValue(gasFeeTransferAccountToChain) + f.Func.TransferBaseTokens(xferAllowance + gasWithdrawFromChain). AllowanceBaseTokens(xferAllowance).Post() require.NoError(t, ctx2.Err) @@ -153,21 +158,21 @@ func Test2Chains(t *testing.T) { // chain2.testcore account will be credited with SD+GAS1+GAS2, pay actual GAS1, // and be debited by SD+GAS2+'withdrawalAmount' bal1.UpdateFeeBalances(ctxAcc1.GasFee) - bal1.Add(testcore2, xferDeposit+wasmlib.MinGasFee+wasmlib.MinGasFee-ctxAcc1.GasFee-xferDeposit-wasmlib.MinGasFee-withdrawalAmount) + bal1.Add(testcore2, xferDeposit+gasWithdrawFromChain+gasWithdrawFromChain-ctxAcc1.GasFee-xferDeposit-gasReserve-withdrawalAmount) // verify these changes against the actual chain1 account balances bal1.VerifyBalances(t) - userL1 -= xferAllowance + isc.Million + userL1 -= xferAllowance + gasWithdrawFromChain require.Equal(t, userL1, user.Balance()) // The gas fees will be credited to chain1.Originator bal2.UpdateFeeBalances(withdrawalReceipt.GasFeeCharged) bal2.UpdateFeeBalances(transferReceipt.GasFeeCharged) // deduct coretest.WithdrawFromChain() gas fee from user's cool million - bal2.Add(user, isc.Million-withdrawalReceipt.GasFeeCharged) + bal2.Add(user, gasWithdrawFromChain-withdrawalReceipt.GasFeeCharged) // chain2.accounts1 will be credited with SD+GAS2+'withdrawalAmount', pay actual GAS2, // and be debited by SD+'withdrawalAmount', leaving zero - bal2.Add(accounts1, xferDeposit+wasmlib.MinGasFee+withdrawalAmount-transferReceipt.GasFeeCharged-xferDeposit-withdrawalAmount) + bal2.Add(accounts1, xferDeposit+gasReserve+withdrawalAmount-transferReceipt.GasFeeCharged-xferDeposit-withdrawalAmount) // chain2.testcore account receives the withdrawn tokens and storage deposit bal2.Account += withdrawalAmount + xferDeposit // verify these changes against the actual chain2 account balances diff --git a/contracts/wasm/testcore/ts/testcoreimpl/funcs.ts b/contracts/wasm/testcore/ts/testcoreimpl/funcs.ts index 756c0f04c0..6d65a9419f 100644 --- a/contracts/wasm/testcore/ts/testcoreimpl/funcs.ts +++ b/contracts/wasm/testcore/ts/testcoreimpl/funcs.ts @@ -9,8 +9,8 @@ import * as sc from "../testcore/index"; const CONTRACT_NAME_DEPLOYED = "exampleDeployTR"; const MSG_CORE_ONLY_PANIC = "========== core only ========="; -const MSG_FULL_PANIC = "========== panic FULL ENTRY POINT ========="; -const MSG_VIEW_PANIC = "========== panic VIEW ========="; +const MSG_FULL_PANIC = "========== panic FULL ENTRY POINT =========="; +const MSG_VIEW_PANIC = "========== panic VIEW =========="; export function funcCallOnChain(ctx: wasmlib.ScFuncContext, f: sc.CallOnChainContext): void { let paramInt = f.params.n().value(); @@ -228,13 +228,10 @@ export function funcWithdrawFromChain(ctx: wasmlib.ScFuncContext, f: sc.Withdraw const transfer = wasmlib.ScTransfer.fromBalances(ctx.allowance()); ctx.transferAllowed(ctx.accountID(), transfer); - // This is just a test contract, but normally these numbers should - // be parameters because there is no way for the contract to figure - // out the gas fees on the other chain, and it's also silly to run - // the costly calculation to determine storage deposit every time - // unless absolutely necessary. Better to just make sure that the - // storage deposit is large enough, since it will be returned anyway. - const gasFee: u64 = wasmlib.MinGasFee; + let gasReserveTransferAccountToChain: u64 = wasmlib.MinGasFee; + if (f.params.gasReserveTransferAccountToChain().exists()) { + gasReserveTransferAccountToChain = f.params.gasReserveTransferAccountToChain().value(); + } let gasReserve: u64 = wasmlib.MinGasFee; if (f.params.gasReserve().exists()) { gasReserve = f.params.gasReserve().value(); @@ -247,7 +244,7 @@ export function funcWithdrawFromChain(ctx: wasmlib.ScFuncContext, f: sc.Withdraw // NOTE: make sure you READ THE DOCS before calling this function const xfer = coreaccounts.ScFuncs.transferAccountToChain(ctx); xfer.params.gasReserve().setValue(gasReserve); - xfer.func.transferBaseTokens(storageDeposit + gasFee + gasReserve) + xfer.func.transferBaseTokens(storageDeposit + gasReserveTransferAccountToChain + gasReserve) .allowanceBaseTokens(withdrawal + storageDeposit + gasReserve) .postToChain(targetChain); } diff --git a/packages/chain/cons/cons_test.go b/packages/chain/cons/cons_test.go index 487ae531e3..abd67e3327 100644 --- a/packages/chain/cons/cons_test.go +++ b/packages/chain/cons/cons_test.go @@ -34,9 +34,9 @@ import ( "github.com/iotaledger/wasp/packages/vm/core/accounts" "github.com/iotaledger/wasp/packages/vm/core/coreprocessors" "github.com/iotaledger/wasp/packages/vm/core/migrations/allmigrations" + "github.com/iotaledger/wasp/packages/vm/gas" "github.com/iotaledger/wasp/packages/vm/processors" "github.com/iotaledger/wasp/packages/vm/vmimpl" - "github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib" ) // Here we run a single consensus instance, step by step with @@ -347,8 +347,7 @@ func testChained(t *testing.T, n, f, b int) { inccounter.FuncIncCounter.Hname(), dict.New(), uint64(i*reqPerBlock+ii), - // FIXME may user other MinGasFee instead of wasmlib.MinGasFee - wasmlib.MinGasFee, + gas.LimitsDefault.MinGasPerRequest, ).Sign(scClient) reqs = append(reqs, scRequest) incTotal++ diff --git a/packages/solo/ledgerl1l2.go b/packages/solo/ledgerl1l2.go index f5e2e14457..e8c994f8e8 100644 --- a/packages/solo/ledgerl1l2.go +++ b/packages/solo/ledgerl1l2.go @@ -203,7 +203,8 @@ func (fp *foundryParams) CreateFoundry() (uint32, iotago.NativeTokenID, error) { user = fp.user } req := CallParamsFromDict(accounts.Contract.Name, accounts.FuncFoundryCreateNew.Name, par). - WithAllowance(isc.NewAssetsBaseTokens(allowanceForFoundryStorageDeposit)) + WithAllowance(isc.NewAssetsBaseTokens(allowanceForFoundryStorageDeposit)). + AddBaseTokens(allowanceForFoundryStorageDeposit) gas, _, err := fp.ch.EstimateGasOnLedger(req, user, true) if err != nil { diff --git a/packages/testutil/testchain/test_chain_ledger.go b/packages/testutil/testchain/test_chain_ledger.go index 142e45a27b..70d3561c04 100644 --- a/packages/testutil/testchain/test_chain_ledger.go +++ b/packages/testutil/testchain/test_chain_ledger.go @@ -21,7 +21,6 @@ import ( "github.com/iotaledger/wasp/packages/vm/core/migrations/allmigrations" "github.com/iotaledger/wasp/packages/vm/core/root" "github.com/iotaledger/wasp/packages/vm/gas" - "github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib" ) //////////////////////////////////////////////////////////////////////////////// @@ -87,8 +86,7 @@ func (tcl *TestChainLedger) MakeTxAccountsDeposit(account *cryptolib.KeyPair) [] Metadata: &isc.SendMetadata{ TargetContract: accounts.Contract.Hname(), EntryPoint: accounts.FuncDeposit.Hname(), - // FIXME may user other MinGasFee instead of wasmlib.MinGasFee - GasBudget: wasmlib.MinGasFee, + GasBudget: 2 * gas.LimitsDefault.MinGasPerRequest, }, }, }, @@ -119,8 +117,7 @@ func (tcl *TestChainLedger) MakeTxDeployIncCounterContract() []isc.Request { root.ParamName: inccounter.Contract.Name, inccounter.VarCounter: 0, }), - // FIXME may user other MinGasFee instead of wasmlib.MinGasFee - GasBudget: wasmlib.MinGasFee, + GasBudget: 2 * gas.LimitsDefault.MinGasPerRequest, }, }, }, diff --git a/packages/vm/core/accounts/impl.go b/packages/vm/core/accounts/impl.go index 881c9a996d..a513dd8781 100644 --- a/packages/vm/core/accounts/impl.go +++ b/packages/vm/core/accounts/impl.go @@ -11,7 +11,7 @@ import ( "github.com/iotaledger/wasp/packages/util" "github.com/iotaledger/wasp/packages/vm" "github.com/iotaledger/wasp/packages/vm/core/errors/coreerrors" - "github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib" + "github.com/iotaledger/wasp/packages/vm/gas" ) func CommonAccount() isc.AgentID { @@ -176,7 +176,7 @@ func transferAccountToChain(ctx isc.Sandbox) dict.Dict { assets := allowance.Clone() // deduct the gas reserve GAS2 from the allowance, if possible - gasReserve := ctx.Params().MustGetUint64(ParamGasReserve, wasmlib.MinGasFee) + gasReserve := ctx.Params().MustGetUint64(ParamGasReserve, gas.LimitsDefault.MinGasPerRequest) if allowance.BaseTokens < gasReserve { panic(ErrNotEnoughAllowance) } diff --git a/packages/vm/core/evm/evmimpl/impl.go b/packages/vm/core/evm/evmimpl/impl.go index 4e3883b967..8b819b9537 100644 --- a/packages/vm/core/evm/evmimpl/impl.go +++ b/packages/vm/core/evm/evmimpl/impl.go @@ -29,7 +29,6 @@ import ( "github.com/iotaledger/wasp/packages/vm/core/evm/iscmagic" "github.com/iotaledger/wasp/packages/vm/core/governance" "github.com/iotaledger/wasp/packages/vm/gas" - "github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib" ) var Processor = evm.Contract.Processor(nil, @@ -254,14 +253,14 @@ func registerERC20NativeTokenOnRemoteChain(ctx isc.Sandbox) dict.Dict { evm.FieldFoundryTokenScheme: codec.EncodeTokenScheme(tokenScheme), }, // FIXME why does this gas budget is higher than the allowance below - GasBudget: 5 * wasmlib.MinGasFee, + GasBudget: 50 * gas.LimitsDefault.MinGasPerRequest, }, } sd := ctx.EstimateRequiredStorageDeposit(req) // this request is sent by contract account, // so we move enough allowance for the gas fee below in the req.Assets.AddBaseTokens() function call - ctx.TransferAllowedFunds(ctx.AccountID(), isc.NewAssetsBaseTokens(sd+wasmlib.MinGasFee)) - req.Assets.AddBaseTokens(sd + wasmlib.MinGasFee) + ctx.TransferAllowedFunds(ctx.AccountID(), isc.NewAssetsBaseTokens(sd+10*gas.LimitsDefault.MinGasPerRequest)) + req.Assets.AddBaseTokens(sd + 10*gas.LimitsDefault.MinGasPerRequest) ctx.Send(req) return nil diff --git a/packages/vm/core/evm/evmtest/utils_test.go b/packages/vm/core/evm/evmtest/utils_test.go index 465a2ce0a3..8e56456e7a 100644 --- a/packages/vm/core/evm/evmtest/utils_test.go +++ b/packages/vm/core/evm/evmtest/utils_test.go @@ -33,7 +33,6 @@ import ( "github.com/iotaledger/wasp/packages/vm/core/evm/iscmagic" "github.com/iotaledger/wasp/packages/vm/core/governance" "github.com/iotaledger/wasp/packages/vm/gas" - "github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib" ) type soloChainEnv struct { @@ -373,9 +372,8 @@ func (e *soloChainEnv) registerERC20ExternalNativeToken( evm.FieldTargetAddress: codec.EncodeAddress(e.soloChain.ChainID.AsAddress()), }). // to cover sd and gas fee for the 'FuncRegisterERC20ExternalNativeToken' func call in 'FuncRegisterERC20NativeTokenOnRemoteChain' - WithAllowance(isc.NewAssetsBaseTokens(2*wasmlib.MinGasFee)). - // FIXME why this gas budget is less than the gas budget of the indirect call FuncRegisterERC20ExternalNativeToken - WithGasBudget(wasmlib.MinGasFee), + WithAllowance(isc.NewAssetsBaseTokens(20*gas.LimitsDefault.MinGasPerRequest)). + WithGasBudget(10*gas.LimitsDefault.MinGasPerRequest), fromChain.OriginatorPrivateKey) if err != nil { return ret, err diff --git a/packages/vm/core/testcore/custom_onledger_requests_test.go b/packages/vm/core/testcore/custom_onledger_requests_test.go index be269ada30..dd2e71ecda 100644 --- a/packages/vm/core/testcore/custom_onledger_requests_test.go +++ b/packages/vm/core/testcore/custom_onledger_requests_test.go @@ -16,7 +16,7 @@ import ( "github.com/iotaledger/wasp/packages/testutil/testmisc" "github.com/iotaledger/wasp/packages/transaction" "github.com/iotaledger/wasp/packages/vm/core/accounts" - "github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib" + "github.com/iotaledger/wasp/packages/vm/gas" ) func TestNoSenderFeature(t *testing.T) { @@ -28,7 +28,9 @@ func TestNoSenderFeature(t *testing.T) { // ---------------------------------------------------------------- // mint some NTs and withdraw them - err := ch.DepositAssetsToL2(isc.NewAssetsBaseTokens(10*isc.Million), wallet) + gasFee := 10 * gas.LimitsDefault.MinGasPerRequest + withdrawAmount := 3 * gas.LimitsDefault.MinGasPerRequest + err := ch.DepositAssetsToL2(isc.NewAssetsBaseTokens(withdrawAmount+gasFee), wallet) require.NoError(t, err) nativeTokenAmount := big.NewInt(123) sn, nativeTokenID, err := ch.NewFoundryParams(1234). @@ -40,8 +42,8 @@ func TestNoSenderFeature(t *testing.T) { require.NoError(t, err) // withdraw native tokens to L1 - allowance := 5 * isc.Million - baseTokensToSend := allowance + wasmlib.MinGasFee + allowance := withdrawAmount + baseTokensToSend := allowance + gasFee _, err = ch.PostRequestOffLedger(solo.NewCallParams( accounts.Contract.Name, accounts.FuncWithdraw.Name, ). @@ -51,7 +53,7 @@ func TestNoSenderFeature(t *testing.T) { ID: nativeTokenID, Amount: nativeTokenAmount, }). - WithGasBudget(wasmlib.MinGasFee), + WithGasBudget(gasFee), wallet) require.NoError(t, err) diff --git a/packages/vm/core/testcore/sbtests/2chains_test.go b/packages/vm/core/testcore/sbtests/2chains_test.go index 1b0a0e960d..943aed5205 100644 --- a/packages/vm/core/testcore/sbtests/2chains_test.go +++ b/packages/vm/core/testcore/sbtests/2chains_test.go @@ -13,6 +13,7 @@ import ( "github.com/iotaledger/wasp/packages/vm/core/accounts" "github.com/iotaledger/wasp/packages/vm/core/corecontracts" "github.com/iotaledger/wasp/packages/vm/core/testcore/sbtests/sbtestsc" + "github.com/iotaledger/wasp/packages/vm/gas" "github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib" ) @@ -64,7 +65,7 @@ func test2Chains(t *testing.T, w bool) { // send base tokens to contractAgentID2 (that is an entity of chain2) on chain1 const baseTokensCreditedToScOnChain1 = 10 * isc.Million - const creditBaseTokensToSend = baseTokensCreditedToScOnChain1 + wasmlib.MinGasFee + creditBaseTokensToSend := baseTokensCreditedToScOnChain1 + gas.LimitsDefault.MinGasPerRequest _, err = chain1.PostRequestSync(solo.NewCallParams( accounts.Contract.Name, accounts.FuncTransferAllowanceTo.Name, accounts.ParamAgentID, contractAgentID2, @@ -97,10 +98,10 @@ func test2Chains(t *testing.T, w bool) { // make chain2 send a call to chain1 to withdraw base tokens baseTokensToWithdrawFromChain1 := baseTokensCreditedToScOnChain1 - const gasFee1 = wasmlib.MinGasFee + gasFeeTransferAccountToChain := 10 * gas.LimitsDefault.MinGasPerRequest // gas reserve for the 'TransferAllowanceTo' func call in 'TransferAccountToChain' func call - const gasReserve = wasmlib.MinGasFee - const withdrawFeeGas = wasmlib.MinGasFee + gasReserve := 10 * gas.LimitsDefault.MinGasPerRequest + withdrawFeeGas := 10 * gas.LimitsDefault.MinGasPerRequest const storageDeposit = wasmlib.StorageDeposit // NOTE: make sure you READ THE DOCS for accounts.transferAccountToChain() @@ -111,7 +112,7 @@ func test2Chains(t *testing.T, w bool) { // the gas fees for the chain2.accounts.transferAccountToChain() request and the // chain1.accounts.transferAllowanceTo() request. // note that the storage deposit will be returned in the end - withdrawReqAllowance := storageDeposit + gasFee1 + gasReserve + withdrawReqAllowance := storageDeposit + gasFeeTransferAccountToChain + gasReserve // also cover gas fee for `FuncWithdrawFromChain` on chain2 withdrawBaseTokensToSend := withdrawReqAllowance + withdrawFeeGas @@ -121,6 +122,7 @@ func test2Chains(t *testing.T, w bool) { sbtestsc.ParamChainID, chain1.ChainID, sbtestsc.ParamBaseTokens, baseTokensToWithdrawFromChain1, sbtestsc.ParamGasReserve, gasReserve, + sbtestsc.ParamGasReserveTransferAccountToChain, gasFeeTransferAccountToChain, ). AddBaseTokens(withdrawBaseTokensToSend). WithAllowance(isc.NewAssetsBaseTokens(withdrawReqAllowance)). @@ -165,9 +167,11 @@ func test2Chains(t *testing.T, w bool) { env.AssertL1BaseTokens(userAddress, utxodb.FundsFromFaucetAmount-creditBaseTokensToSend-withdrawBaseTokensToSend) // on chain1 user only made the first transaction, so it is the same as its balance before 'WithdrawFromChain' function call chain1.AssertL2BaseTokens(userAgentID, creditBaseTokensToSend-baseTokensCreditedToScOnChain1-chain1TransferAllowanceGas) + // gasFeeTransferAccountToChain is is used for paying the gas fee of the 'TransferAccountToChain' func call + // in 'WithdrawFromChain' func call // gasReserve is used for paying the gas fee of the 'TransferAllowanceTo' func call in 'TransferAccountToChain' func call // So the token left in contractAgentID2 on chain1 is the unused gas fee - chain1.AssertL2BaseTokens(contractAgentID2, gasReserve-chain1TransferAccountToChainGas) + chain1.AssertL2BaseTokens(contractAgentID2, gasFeeTransferAccountToChain-chain1TransferAccountToChainGas) // tokens in 'withdrawBaseTokensToSend' amount are moved with the request from L1 to L2 // 'withdrawReqAllowance' is is the amount moved from chain1 to chain2 with the request // 'baseTokensToWithdrawFromChain1' is the amount we assigned to withdraw in 'WithdrawFromChain' func call diff --git a/packages/vm/core/testcore/sbtests/check_ctx_test.go b/packages/vm/core/testcore/sbtests/check_ctx_test.go index ee622afb87..125c2f2718 100644 --- a/packages/vm/core/testcore/sbtests/check_ctx_test.go +++ b/packages/vm/core/testcore/sbtests/check_ctx_test.go @@ -8,6 +8,7 @@ import ( "github.com/iotaledger/wasp/packages/isc" "github.com/iotaledger/wasp/packages/solo" "github.com/iotaledger/wasp/packages/vm/core/testcore/sbtests/sbtestsc" + "github.com/iotaledger/wasp/packages/vm/gas" ) func TestMainCallsFromFullEP(t *testing.T) { run2(t, testMainCallsFromFullEP) } @@ -24,7 +25,7 @@ func testMainCallsFromFullEP(t *testing.T, w bool) { sbtestsc.ParamCaller, userAgentID, sbtestsc.ParamChainOwnerID, chain.OriginatorAgentID, ). - WithGasBudget(120_000) + WithGasBudget(10 * gas.LimitsDefault.MinGasPerRequest) _, err := chain.PostRequestSync(req, user) require.NoError(t, err) } diff --git a/packages/vm/core/testcore/sbtests/sbtestsc/impl_withdraw_from_chain.go b/packages/vm/core/testcore/sbtests/sbtestsc/impl_withdraw_from_chain.go index 35197990a4..f0410708d0 100644 --- a/packages/vm/core/testcore/sbtests/sbtestsc/impl_withdraw_from_chain.go +++ b/packages/vm/core/testcore/sbtests/sbtestsc/impl_withdraw_from_chain.go @@ -5,6 +5,7 @@ import ( "github.com/iotaledger/wasp/packages/kv/codec" "github.com/iotaledger/wasp/packages/kv/dict" "github.com/iotaledger/wasp/packages/vm/core/accounts" + "github.com/iotaledger/wasp/packages/vm/gas" "github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib" ) @@ -21,23 +22,16 @@ func withdrawFromChain(ctx isc.Sandbox) dict.Dict { // plus gas fees for the outgoing request to accounts.transferAllowanceTo() ctx.TransferAllowedFunds(ctx.AccountID()) - // This is just a test contract, but normally these numbers should - // be parameters because there is no way for the contract to figure - // out the gas fees on the other chain, and it's also silly to run - // the costly calculation to determine storage deposit every time - // unless absolutely necessary. Better to just make sure that the - // storage deposit is large enough, since it will be returned anyway. - // gasFee is for sending FuncTransferAccountToChain() request - const gasFee = wasmlib.MinGasFee - // gasReserve is the gas fee for the function all inside FuncTransferAccountToChain() - gasReserve := params.MustGetUint64(ParamGasReserve, wasmlib.MinGasFee) + // gasReserve is the gas fee for the 'TransferAllowanceTo' function call ub 'TransferAccountToChain' + gasReserve := params.MustGetUint64(ParamGasReserve, gas.LimitsDefault.MinGasPerRequest) + gasReserveTransferAccountToChain := params.MustGetUint64(ParamGasReserveTransferAccountToChain, gas.LimitsDefault.MinGasPerRequest) const storageDeposit = wasmlib.StorageDeposit // make sure to send enough to cover the storage deposit and gas fees // the storage deposit will be returned along with the withdrawal ctx.Send(isc.RequestParameters{ TargetAddress: targetChain.AsAddress(), - Assets: isc.NewAssetsBaseTokens(storageDeposit + gasFee + gasReserve), + Assets: isc.NewAssetsBaseTokens(storageDeposit + gasReserveTransferAccountToChain + gasReserve), Metadata: &isc.SendMetadata{ TargetContract: accounts.Contract.Hname(), EntryPoint: accounts.FuncTransferAccountToChain.Hname(), diff --git a/packages/vm/core/testcore/sbtests/sbtestsc/interface.go b/packages/vm/core/testcore/sbtests/sbtestsc/interface.go index 6c3746043b..7d959f0baa 100644 --- a/packages/vm/core/testcore/sbtests/sbtestsc/interface.go +++ b/packages/vm/core/testcore/sbtests/sbtestsc/interface.go @@ -116,25 +116,26 @@ const ( VarContractNameDeployed = "exampleDeployTR" // parameters - ParamAddress = "address" - ParamAgentID = "agentID" - ParamCaller = "caller" - ParamChainID = "chainID" - ParamChainOwnerID = "chainOwnerID" - ParamGasReserve = "gasReserve" - ParamContractID = "contractID" - ParamFail = "initFailParam" - ParamHnameContract = "hnameContract" - ParamHnameEP = "hnameEP" - ParamIntParamName = "intParamName" - ParamIntParamValue = "intParamValue" - ParamBaseTokens = "baseTokens" - ParamN = "n" - ParamProgHash = "progHash" - ParamSize = "size" + ParamAddress = "address" + ParamAgentID = "agentID" + ParamCaller = "caller" + ParamChainID = "chainID" + ParamChainOwnerID = "chainOwnerID" + ParamGasReserve = "gasReserve" + ParamGasReserveTransferAccountToChain = "gasReserveTransferAccountToChain" + ParamContractID = "contractID" + ParamFail = "initFailParam" + ParamHnameContract = "hnameContract" + ParamHnameEP = "hnameEP" + ParamIntParamName = "intParamName" + ParamIntParamValue = "intParamValue" + ParamBaseTokens = "baseTokens" + ParamN = "n" + ParamProgHash = "progHash" + ParamSize = "size" // error fragments for testing - MsgDoNothing = "========== doing nothing" - MsgFullPanic = "========== panic FULL ENTRY POINT =========" - MsgViewPanic = "========== panic VIEW =========" + MsgDoNothing = "========== doing nothing ==========" + MsgFullPanic = "========== panic FULL ENTRY POINT ==========" + MsgViewPanic = "========== panic VIEW ==========" ) diff --git a/packages/vm/core/testcore/sbtests/sbtestsc/testcore_bg.wasm b/packages/vm/core/testcore/sbtests/sbtestsc/testcore_bg.wasm index fc87af057b..7f7bb015ad 100644 Binary files a/packages/vm/core/testcore/sbtests/sbtestsc/testcore_bg.wasm and b/packages/vm/core/testcore/sbtests/sbtestsc/testcore_bg.wasm differ diff --git a/packages/vm/core/testcore/sbtests/setup_test.go b/packages/vm/core/testcore/sbtests/setup_test.go index afe1def52e..2fd6c146dd 100644 --- a/packages/vm/core/testcore/sbtests/setup_test.go +++ b/packages/vm/core/testcore/sbtests/setup_test.go @@ -13,8 +13,8 @@ import ( "github.com/iotaledger/wasp/packages/testutil/utxodb" "github.com/iotaledger/wasp/packages/vm/core/root" "github.com/iotaledger/wasp/packages/vm/core/testcore/sbtests/sbtestsc" + "github.com/iotaledger/wasp/packages/vm/gas" "github.com/iotaledger/wasp/packages/wasmvm/wasmhost" - "github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib" ) const ( @@ -51,8 +51,7 @@ func setupDeployer(t *testing.T, ch *solo.Chain) (*cryptolib.KeyPair, isc.AgentI user, userAddr := ch.Env.NewKeyPairWithFunds() ch.Env.AssertL1BaseTokens(userAddr, utxodb.FundsFromFaucetAmount) - // FIXME may user other MinGasFee instead of wasmlib.MinGasFee - err := ch.DepositBaseTokensToL2(wasmlib.MinGasFee, user) + err := ch.DepositBaseTokensToL2(10*gas.LimitsDefault.MinGasPerRequest, user) require.NoError(t, err) req := solo.NewCallParams(root.Contract.Name, root.FuncGrantDeployPermission.Name, diff --git a/packages/vm/gas/table.go b/packages/vm/gas/table.go index 695f54b88a..6519346a33 100644 --- a/packages/vm/gas/table.go +++ b/packages/vm/gas/table.go @@ -66,7 +66,7 @@ var burnTable = BurnTable{ BurnCodeUtilsBLSValidSignature: {"bls valid", constValue(2000)}, BurnCodeUtilsBLSAddrFromPubKey: {"bls addr", constValue(50)}, BurnCodeUtilsBLSAggregateBLS1P: {"bls aggregate", linear(CoefBLSAggregate)}, - BurnCodeMinimumGasPerRequest1P: {"minimum gas per request", minBurn(10000)}, // TODO maybe make it configurable (gov contract?) // FIXME not equal to wasmlib.MinGasFee + BurnCodeMinimumGasPerRequest1P: {"minimum gas per request", minBurn(10000)}, // TODO maybe make it configurable (gov contract?) BurnCodeEVM1P: {"evm", linear(1)}, } diff --git a/packages/wasmvm/wasmlib/go/wasmlib/sandbox.go b/packages/wasmvm/wasmlib/go/wasmlib/sandbox.go index 4a8bbd59d5..dbf8d0789a 100644 --- a/packages/wasmvm/wasmlib/go/wasmlib/sandbox.go +++ b/packages/wasmvm/wasmlib/go/wasmlib/sandbox.go @@ -9,7 +9,8 @@ import ( ) const ( - MinGasFee = uint64(100_000) + // should be aligned to gas.LimitsDefault.MinGasPerRequest + MinGasFee = uint64(10_000) StorageDeposit = uint64(20_000) FnAccountID = int32(-1) diff --git a/packages/wasmvm/wasmlib/src/coreaccounts/params.rs b/packages/wasmvm/wasmlib/src/coreaccounts/params.rs index a13b12e8d9..be4e9972c4 100644 --- a/packages/wasmvm/wasmlib/src/coreaccounts/params.rs +++ b/packages/wasmvm/wasmlib/src/coreaccounts/params.rs @@ -6,8 +6,8 @@ #![allow(dead_code)] #![allow(unused_imports)] -use crate::coreaccounts::*; use crate::*; +use crate::coreaccounts::*; #[derive(Clone)] pub struct ImmutableFoundryCreateNewParams {