diff --git a/contracts/wasm/testcore/go/testcoreimpl/funcs.go b/contracts/wasm/testcore/go/testcoreimpl/funcs.go index 2c02a35b09..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,14 +242,14 @@ 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 - const gasReserve = 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() + } const storageDeposit = wasmlib.StorageDeposit // note: gasReserve is the gas necessary to run accounts.transferAllowanceTo @@ -258,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 addc5fbf71..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,14 +255,15 @@ 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 gas_reserve: 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(); + } let storage_deposit: u64 = STORAGE_DEPOSIT; // note: gasReserve is the gas necessary to run accounts.transferAllowanceTo @@ -272,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 1c8cc9b986..3b773dbe96 100644 --- a/contracts/wasm/testcore/schema.yaml +++ b/contracts/wasm/testcore/schema.yaml @@ -93,6 +93,8 @@ funcs: params: 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 bc6ede268c..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,14 +228,14 @@ 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; - const gasReserve: 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(); + } const storageDeposit: u64 = wasmlib.StorageDeposit; // note: gasReserve is the gas necessary to run accounts.transferAllowanceTo @@ -244,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 22f64322bc..abd67e3327 100644 --- a/packages/chain/cons/cons_test.go +++ b/packages/chain/cons/cons_test.go @@ -34,6 +34,7 @@ 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" ) @@ -346,7 +347,7 @@ func testChained(t *testing.T, n, f, b int) { inccounter.FuncIncCounter.Hname(), dict.New(), uint64(i*reqPerBlock+ii), - 20000, + gas.LimitsDefault.MinGasPerRequest, ).Sign(scClient) reqs = append(reqs, scRequest) incTotal++ diff --git a/packages/solo/ledgerl1l2.go b/packages/solo/ledgerl1l2.go index ce75ecc12a..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 { @@ -297,7 +298,7 @@ func (ch *Chain) DestroyTokensOnL1(nativeTokenID iotago.NativeTokenID, amount in return err } -// DepositAssetsToL2 deposits ftokens on user's on-chain account +// DepositAssetsToL2 deposits ftokens on user's on-chain account, if user is nil, then chain owner is assigned func (ch *Chain) DepositAssetsToL2(assets *isc.Assets, user *cryptolib.KeyPair) error { _, err := ch.PostRequestSync( NewCallParams(accounts.Contract.Name, accounts.FuncDeposit.Name). diff --git a/packages/testutil/testchain/test_chain_ledger.go b/packages/testutil/testchain/test_chain_ledger.go index 983ff15d68..70d3561c04 100644 --- a/packages/testutil/testchain/test_chain_ledger.go +++ b/packages/testutil/testchain/test_chain_ledger.go @@ -86,7 +86,7 @@ func (tcl *TestChainLedger) MakeTxAccountsDeposit(account *cryptolib.KeyPair) [] Metadata: &isc.SendMetadata{ TargetContract: accounts.Contract.Hname(), EntryPoint: accounts.FuncDeposit.Hname(), - GasBudget: 10_000, + GasBudget: 2 * gas.LimitsDefault.MinGasPerRequest, }, }, }, @@ -117,7 +117,7 @@ func (tcl *TestChainLedger) MakeTxDeployIncCounterContract() []isc.Request { root.ParamName: inccounter.Contract.Name, inccounter.VarCounter: 0, }), - GasBudget: 10_000, + GasBudget: 2 * gas.LimitsDefault.MinGasPerRequest, }, }, }, diff --git a/packages/vm/core/accounts/impl.go b/packages/vm/core/accounts/impl.go index 377634e946..a513dd8781 100644 --- a/packages/vm/core/accounts/impl.go +++ b/packages/vm/core/accounts/impl.go @@ -11,6 +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/vm/gas" ) func CommonAccount() isc.AgentID { @@ -175,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, 100) + gasReserve := ctx.Params().MustGetUint64(ParamGasReserve, gas.LimitsDefault.MinGasPerRequest) if allowance.BaseTokens < gasReserve { panic(ErrNotEnoughAllowance) } @@ -183,7 +184,7 @@ func transferAccountToChain(ctx isc.Sandbox) dict.Dict { // Warning: this will transfer all assets into the accounts core contract's L2 account. // Be sure everything transfers out again, or assets will be stuck forever. - _ = ctx.TransferAllowedFunds(ctx.AccountID()) + ctx.TransferAllowedFunds(ctx.AccountID()) // Send the specified assets, which should include GAS2 and SD, as part of the // accounts.TransferAllowanceTo() request on the origin chain. diff --git a/packages/vm/core/evm/evmimpl/impl.go b/packages/vm/core/evm/evmimpl/impl.go index 3bac58326d..8b819b9537 100644 --- a/packages/vm/core/evm/evmimpl/impl.go +++ b/packages/vm/core/evm/evmimpl/impl.go @@ -252,11 +252,15 @@ func registerERC20NativeTokenOnRemoteChain(ctx isc.Sandbox) dict.Dict { evm.FieldTokenDecimals: codec.EncodeUint8(decimals), evm.FieldFoundryTokenScheme: codec.EncodeTokenScheme(tokenScheme), }, + // FIXME why does this gas budget is higher than the allowance below + GasBudget: 50 * gas.LimitsDefault.MinGasPerRequest, }, } sd := ctx.EstimateRequiredStorageDeposit(req) - ctx.TransferAllowedFunds(ctx.AccountID(), isc.NewAssetsBaseTokens(sd)) - req.Assets.AddBaseTokens(sd) + // 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+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 b52c1c735a..8e56456e7a 100644 --- a/packages/vm/core/evm/evmtest/utils_test.go +++ b/packages/vm/core/evm/evmtest/utils_test.go @@ -370,7 +370,11 @@ func (e *soloChainEnv) registerERC20ExternalNativeToken( evm.FieldTokenTickerSymbol: codec.EncodeString(tokenTickerSymbol), evm.FieldTokenDecimals: codec.EncodeUint8(tokenDecimals), evm.FieldTargetAddress: codec.EncodeAddress(e.soloChain.ChainID.AsAddress()), - }).WithMaxAffordableGasBudget().WithAllowance(isc.NewAssetsBaseTokens(1*isc.Million)), fromChain.OriginatorPrivateKey) + }). + // to cover sd and gas fee for the 'FuncRegisterERC20ExternalNativeToken' func call in 'FuncRegisterERC20NativeTokenOnRemoteChain' + 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 7eec9e2e02..dd2e71ecda 100644 --- a/packages/vm/core/testcore/custom_onledger_requests_test.go +++ b/packages/vm/core/testcore/custom_onledger_requests_test.go @@ -15,6 +15,8 @@ import ( "github.com/iotaledger/wasp/packages/solo" "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/vm/gas" ) func TestNoSenderFeature(t *testing.T) { @@ -26,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). @@ -37,14 +41,20 @@ func TestNoSenderFeature(t *testing.T) { err = ch.MintTokens(sn, nativeTokenAmount, wallet) require.NoError(t, err) - // withdraw NTs to L1 - req := solo.NewCallParams("accounts", "withdraw"). - AddAllowanceBaseTokens(5 * isc.Million). + // withdraw native tokens to L1 + allowance := withdrawAmount + baseTokensToSend := allowance + gasFee + _, err = ch.PostRequestOffLedger(solo.NewCallParams( + accounts.Contract.Name, accounts.FuncWithdraw.Name, + ). + AddBaseTokens(baseTokensToSend). + AddAllowanceBaseTokens(allowance). AddAllowanceNativeTokensVect(&iotago.NativeToken{ ID: nativeTokenID, Amount: nativeTokenAmount, - }) - _, err = ch.PostRequestOffLedger(req, wallet) + }). + WithGasBudget(gasFee), + wallet) require.NoError(t, err) nft, _, err := ch.Env.MintNFTL1(wallet, addr, []byte("foobar")) diff --git a/packages/vm/core/testcore/sbtests/2chains_test.go b/packages/vm/core/testcore/sbtests/2chains_test.go index c9196e49db..943aed5205 100644 --- a/packages/vm/core/testcore/sbtests/2chains_test.go +++ b/packages/vm/core/testcore/sbtests/2chains_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/common/math" "github.com/stretchr/testify/require" "github.com/iotaledger/wasp/packages/isc" @@ -14,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" ) @@ -37,7 +37,9 @@ func test2Chains(t *testing.T, w bool) { WithNativeContract(sbtestsc.Processor) chain1 := env.NewChain() chain2, _ := env.NewChainExt(nil, 0, "chain2") - err := chain2.DepositAssetsToL2(isc.NewAssetsBaseTokens(5*isc.Million), nil) + // chain owner deposit base tokens on chain2 + chain2BaseTokenOwnerDeposit := 5 * isc.Million + err := chain2.DepositAssetsToL2(isc.NewAssetsBaseTokens(chain2BaseTokenOwnerDeposit), nil) require.NoError(t, err) chain1.CheckAccountLedger() chain2.CheckAccountLedger() @@ -49,6 +51,12 @@ func test2Chains(t *testing.T, w bool) { userAgentID := isc.NewAgentID(userAddress) env.AssertL1BaseTokens(userAddress, utxodb.FundsFromFaucetAmount) + fmt.Println("---------------chain1---------------") + fmt.Println(chain1.DumpAccounts()) + fmt.Println("---------------chain2---------------") + fmt.Println(chain2.DumpAccounts()) + fmt.Println("------------------------------------") + chain1TotalBaseTokens := chain1.L2TotalBaseTokens() chain2TotalBaseTokens := chain2.L2TotalBaseTokens() @@ -56,26 +64,26 @@ func test2Chains(t *testing.T, w bool) { chain2.WaitForRequestsMark() // send base tokens to contractAgentID2 (that is an entity of chain2) on chain1 - const baseTokensToSend = 11 * isc.Million const baseTokensCreditedToScOnChain1 = 10 * isc.Million + creditBaseTokensToSend := baseTokensCreditedToScOnChain1 + gas.LimitsDefault.MinGasPerRequest _, err = chain1.PostRequestSync(solo.NewCallParams( accounts.Contract.Name, accounts.FuncTransferAllowanceTo.Name, accounts.ParamAgentID, contractAgentID2, ). - AddBaseTokens(baseTokensToSend). + AddBaseTokens(creditBaseTokensToSend). AddAllowanceBaseTokens(baseTokensCreditedToScOnChain1). - WithGasBudget(math.MaxUint64), + WithMaxAffordableGasBudget(), userWallet) require.NoError(t, err) chain1TransferAllowanceReceipt := chain1.LastReceipt() chain1TransferAllowanceGas := chain1TransferAllowanceReceipt.GasFeeCharged - env.AssertL1BaseTokens(userAddress, utxodb.FundsFromFaucetAmount-baseTokensToSend) - chain1.AssertL2BaseTokens(userAgentID, baseTokensToSend-baseTokensCreditedToScOnChain1-chain1TransferAllowanceGas) + env.AssertL1BaseTokens(userAddress, utxodb.FundsFromFaucetAmount-creditBaseTokensToSend) + chain1.AssertL2BaseTokens(userAgentID, creditBaseTokensToSend-baseTokensCreditedToScOnChain1-chain1TransferAllowanceGas) chain1.AssertL2BaseTokens(contractAgentID2, baseTokensCreditedToScOnChain1) - chain1.AssertL2TotalBaseTokens(chain1TotalBaseTokens + baseTokensToSend) - chain1TotalBaseTokens += baseTokensToSend + chain1.AssertL2TotalBaseTokens(chain1TotalBaseTokens + creditBaseTokensToSend) + chain1TotalBaseTokens += creditBaseTokensToSend chain2.AssertL2BaseTokens(userAgentID, 0) chain2.AssertL2BaseTokens(contractAgentID2, 0) @@ -90,49 +98,63 @@ func test2Chains(t *testing.T, w bool) { // make chain2 send a call to chain1 to withdraw base tokens baseTokensToWithdrawFromChain1 := baseTokensCreditedToScOnChain1 - // actual gas fee is less, but always rounded up to this minimum amount - const gasFee = wasmlib.MinGasFee + gasFeeTransferAccountToChain := 10 * gas.LimitsDefault.MinGasPerRequest + // gas reserve for the 'TransferAllowanceTo' func call in 'TransferAccountToChain' func call + gasReserve := 10 * gas.LimitsDefault.MinGasPerRequest + withdrawFeeGas := 10 * gas.LimitsDefault.MinGasPerRequest const storageDeposit = wasmlib.StorageDeposit // NOTE: make sure you READ THE DOCS for accounts.transferAccountToChain() // to understand fully how to call it and why. - // reqAllowance is the allowance provided to chain2.testcore.withdrawFromChain(), + // withdrawReqAllowance is the allowance provided to chain2.testcore.withdrawFromChain(), // which needs to be enough to cover any storage deposit along the way and to pay // 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 - reqAllowance := storageDeposit + gasFee + gasFee + withdrawReqAllowance := storageDeposit + gasFeeTransferAccountToChain + gasReserve // also cover gas fee for `FuncWithdrawFromChain` on chain2 - assetsBaseTokens := reqAllowance + isc.Million + withdrawBaseTokensToSend := withdrawReqAllowance + withdrawFeeGas - _, err = chain2.PostRequestSync(solo.NewCallParams(ScName, sbtestsc.FuncWithdrawFromChain.Name, + _, err = chain2.PostRequestSync(solo.NewCallParams( + ScName, sbtestsc.FuncWithdrawFromChain.Name, sbtestsc.ParamChainID, chain1.ChainID, - sbtestsc.ParamBaseTokens, baseTokensToWithdrawFromChain1). - AddBaseTokens(assetsBaseTokens). - WithAllowance(isc.NewAssetsBaseTokens(reqAllowance)). - WithGasBudget(isc.Million), + sbtestsc.ParamBaseTokens, baseTokensToWithdrawFromChain1, + sbtestsc.ParamGasReserve, gasReserve, + sbtestsc.ParamGasReserveTransferAccountToChain, gasFeeTransferAccountToChain, + ). + AddBaseTokens(withdrawBaseTokensToSend). + WithAllowance(isc.NewAssetsBaseTokens(withdrawReqAllowance)). + WithMaxAffordableGasBudget(), userWallet) require.NoError(t, err) chain2WithdrawFromChainReceipt := chain2.LastReceipt() chain2WithdrawFromChainGas := chain2WithdrawFromChainReceipt.GasFeeCharged + chain2WithdrawFromChainTarget := chain2WithdrawFromChainReceipt.DeserializedRequest().CallTarget() + require.Equal(t, sbtestsc.Contract.Hname(), chain2WithdrawFromChainTarget.Contract) + require.Equal(t, sbtestsc.FuncWithdrawFromChain.Hname(), chain2WithdrawFromChainTarget.EntryPoint) + require.Nil(t, chain2WithdrawFromChainReceipt.Error) + // accounts.FuncTransferAllowanceTo() + // accounts.FuncTransferAccountToChain() require.True(t, chain1.WaitForRequestsThrough(2, 10*time.Second)) + // testcore.FuncWithdrawFromChain() + // accounts.FuncTransferAllowanceTo() require.True(t, chain2.WaitForRequestsThrough(2, 10*time.Second)) chain2TransferAllowanceReceipt := chain2.LastReceipt() - chain2TransferAllowanceGas := chain2TransferAllowanceReceipt.GasFeeCharged + // chain2TransferAllowanceGas := chain2TransferAllowanceReceipt.GasFeeCharged chain2TransferAllowanceTarget := chain2TransferAllowanceReceipt.DeserializedRequest().CallTarget() - require.Equal(t, chain2TransferAllowanceTarget.Contract, accounts.Contract.Hname()) - require.Equal(t, chain2TransferAllowanceTarget.EntryPoint, accounts.FuncTransferAllowanceTo.Hname()) + require.Equal(t, accounts.Contract.Hname(), chain2TransferAllowanceTarget.Contract) + require.Equal(t, accounts.FuncTransferAllowanceTo.Hname(), chain2TransferAllowanceTarget.EntryPoint) require.Nil(t, chain2TransferAllowanceReceipt.Error) chain1TransferAccountToChainReceipt := chain1.LastReceipt() chain1TransferAccountToChainGas := chain1TransferAccountToChainReceipt.GasFeeCharged chain1TransferAccountToChainTarget := chain1TransferAccountToChainReceipt.DeserializedRequest().CallTarget() - require.Equal(t, chain1TransferAccountToChainTarget.Contract, accounts.Contract.Hname()) - require.Equal(t, chain1TransferAccountToChainTarget.EntryPoint, accounts.FuncTransferAccountToChain.Hname()) + require.Equal(t, accounts.Contract.Hname(), chain1TransferAccountToChainTarget.Contract) + require.Equal(t, accounts.FuncTransferAccountToChain.Hname(), chain1TransferAccountToChainTarget.EntryPoint) require.Nil(t, chain1TransferAccountToChainReceipt.Error) fmt.Println("---------------chain1---------------") @@ -141,13 +163,24 @@ func test2Chains(t *testing.T, w bool) { fmt.Println(chain2.DumpAccounts()) fmt.Println("------------------------------------") - env.AssertL1BaseTokens(userAddress, utxodb.FundsFromFaucetAmount-baseTokensToSend-assetsBaseTokens) - - chain1.AssertL2BaseTokens(userAgentID, baseTokensToSend-baseTokensCreditedToScOnChain1-chain1TransferAllowanceGas) - chain1.AssertL2BaseTokens(contractAgentID2, 0) // emptied the account - chain1.AssertL2TotalBaseTokens(chain1TotalBaseTokens + chain1TransferAllowanceGas + chain1TransferAccountToChainGas - chain2TransferAllowanceGas - baseTokensToWithdrawFromChain1) - - chain2.AssertL2BaseTokens(userAgentID, assetsBaseTokens-reqAllowance-chain2WithdrawFromChainGas) + // the 2 function call we did above are requests from L1 + 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, 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 + chain1.AssertL2TotalBaseTokens(chain1TotalBaseTokens + (withdrawBaseTokensToSend - withdrawReqAllowance - baseTokensToWithdrawFromChain1)) + + // tokens in 'withdrawBaseTokensToSend' amount are moved from L1 to L2 with the 'WithdrawFromChain' func call + // token in 'withdrawReqAllowance' amount are withdrawn by contractAgentID2 + // and 'WithdrawFromChain' func call was sent by user on chain2, so its balance should deduct 'chain2WithdrawFromChainGas' + chain2.AssertL2BaseTokens(userAgentID, withdrawBaseTokensToSend-withdrawReqAllowance-chain2WithdrawFromChainGas) chain2.AssertL2BaseTokens(contractAgentID2, baseTokensToWithdrawFromChain1+storageDeposit) - chain2.AssertL2TotalBaseTokens(chain2TotalBaseTokens + assetsBaseTokens + baseTokensCreditedToScOnChain1 + chain2TransferAllowanceGas - chain1TransferAllowanceGas - chain1TransferAccountToChainGas) + chain2.AssertL2TotalBaseTokens(chain2TotalBaseTokens + baseTokensToWithdrawFromChain1 + withdrawReqAllowance) } 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 2231448a78..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 @@ -2,8 +2,10 @@ package sbtestsc import ( "github.com/iotaledger/wasp/packages/isc" + "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" ) @@ -15,30 +17,29 @@ func withdrawFromChain(ctx isc.Sandbox) dict.Dict { withdrawal := params.MustGetUint64(ParamBaseTokens) // if it is not already present in the SC's account the caller should have - // provided enough base tokens to cover the gas fees for the current call, - // and for the storage deposit plus gas fees for the outgoing request to - // accounts.transferAllowanceTo() + // provided enough base tokens to cover the gas fees for the current call + // (should be wasmlib.MinGasFee in default), and for the storage deposit + // 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. - const gasFee = 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 + gasFee), + Assets: isc.NewAssetsBaseTokens(storageDeposit + gasReserveTransferAccountToChain + gasReserve), Metadata: &isc.SendMetadata{ TargetContract: accounts.Contract.Hname(), EntryPoint: accounts.FuncTransferAccountToChain.Hname(), - GasBudget: gasFee, - Allowance: isc.NewAssetsBaseTokens(withdrawal + storageDeposit + gasFee), + Params: dict.Dict{ + accounts.ParamGasReserve: codec.EncodeUint64(gasReserve), + }, + GasBudget: gasReserve, + Allowance: isc.NewAssetsBaseTokens(withdrawal + storageDeposit + gasReserve), }, }) diff --git a/packages/vm/core/testcore/sbtests/sbtestsc/interface.go b/packages/vm/core/testcore/sbtests/sbtestsc/interface.go index 9ca950b270..7d959f0baa 100644 --- a/packages/vm/core/testcore/sbtests/sbtestsc/interface.go +++ b/packages/vm/core/testcore/sbtests/sbtestsc/interface.go @@ -116,24 +116,26 @@ const ( VarContractNameDeployed = "exampleDeployTR" // parameters - ParamAddress = "address" - ParamAgentID = "agentID" - ParamCaller = "caller" - ParamChainID = "chainID" - ParamChainOwnerID = "chainOwnerID" - 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 78e5876681..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 99e5ba76c0..2fd6c146dd 100644 --- a/packages/vm/core/testcore/sbtests/setup_test.go +++ b/packages/vm/core/testcore/sbtests/setup_test.go @@ -13,6 +13,7 @@ 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" ) @@ -50,7 +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) - err := ch.DepositBaseTokensToL2(10_000, 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/gas.md b/packages/vm/gas/gas.md index 36bf5c8d8c..c02538227d 100644 --- a/packages/vm/gas/gas.md +++ b/packages/vm/gas/gas.md @@ -11,13 +11,13 @@ Current gas costs are still experimental and will change. | GetBalance | 20 | get balance of account on the chain | | BurnCodeGetNFTData | 10 | get data about the NFT (issuer/metadata) | | CallContract | 10 | call a target (another SC in the same chain) | -| EmitEventFixed | 10 | emit event | +| EmitEvent | 1*B | emit event (B = number of bytes) | | GetAllowance | 10 | get allowance | | TransferAllowance | 10 | transfer allowance | | BurnCodeEstimateStorageDepositCost | 5 | estimate the storage deposit cost of a L1 request to be sent | | SendL1Request | 200*N | send a L1 transaction (N = number of issued txs in the current call) | | DeployContract | 10 | deploy a contract | -| Storage | 1*B | storage (B = number of bytes) | +| Storage | 55*B | storage (B = number of bytes) | | ReadFromState | 1*(B/100) | read from state (B = number of bytes, adjusted in the call) | | Wasm | X | wasm code execution (X = gas returnted by WASM VM) | | UtilsHashingBlake2b | 5*B | blake2b hash function (B = number of bytes) | diff --git a/packages/vm/gas/table.go b/packages/vm/gas/table.go index 9499e0be75..6519346a33 100644 --- a/packages/vm/gas/table.go +++ b/packages/vm/gas/table.go @@ -14,7 +14,7 @@ const ( BurnCodeGetNFTData BurnCodeCallContract BurnCodeDeployContract - BurnCodeEmitEventFixed + BurnCodeEmitEvent1P BurnCodeTransferAllowance BurnCodeEstimateStorageDepositCost BurnCodeSendL1Request @@ -47,13 +47,13 @@ var burnTable = BurnTable{ BurnCodeGetBalance: {"balance", constValue(20)}, BurnCodeGetNFTData: {"nft data", constValue(10)}, BurnCodeCallContract: {"call", constValue(100)}, - BurnCodeEmitEventFixed: {"event", constValue(10)}, + BurnCodeEmitEvent1P: {"event", linear(1)}, // 1 gas per byte BurnCodeGetAllowance: {"allowance", constValue(10)}, BurnCodeTransferAllowance: {"transfer", constValue(10)}, BurnCodeEstimateStorageDepositCost: {"storage deposit estimate", constValue(5)}, BurnCodeSendL1Request: {"send", linear(Coef1Send)}, BurnCodeDeployContract: {"deploy", constValue(10)}, - BurnCodeStorage1P: {"storage", linear(1)}, // 1 gas per byte + BurnCodeStorage1P: {"storage", linear(55)}, // 55 gas per byte BurnCodeReadFromState1P: {"state read", linear(1)}, BurnCodeWasm1P: {"wasm", linear(1)}, BurnCodeUtilsHashingBlake2b: {"blake2b", constValue(50)}, diff --git a/packages/vm/vmimpl/sandbox.go b/packages/vm/vmimpl/sandbox.go index 5d81cdea45..db3c7dcff3 100644 --- a/packages/vm/vmimpl/sandbox.go +++ b/packages/vm/vmimpl/sandbox.go @@ -42,7 +42,7 @@ func (s *contractSandbox) DeployContract(programHash hashing.HashValue, name str } func (s *contractSandbox) Event(topic string, payload []byte) { - s.Ctx.GasBurn(gas.BurnCodeEmitEventFixed) + s.Ctx.GasBurn(gas.BurnCodeEmitEvent1P, uint64(len(topic)+len(payload))) hContract := s.reqctx.CurrentContractHname() hex := iotago.EncodeHex(payload) if len(hex) > 80 { diff --git a/packages/wasmvm/wasmlib/as/wasmlib/coreaccounts/params.ts b/packages/wasmvm/wasmlib/as/wasmlib/coreaccounts/params.ts index 79b189ab03..374ca3414b 100644 --- a/packages/wasmvm/wasmlib/as/wasmlib/coreaccounts/params.ts +++ b/packages/wasmvm/wasmlib/as/wasmlib/coreaccounts/params.ts @@ -70,7 +70,7 @@ export class MutableFoundryModifySupplyParams extends wasmtypes.ScProxy { export class ImmutableTransferAccountToChainParams extends wasmtypes.ScProxy { // Optional gas amount to reserve in the allowance for the internal - // call to transferAllowanceTo(). Default 100 (MinGasFee). + // call to transferAllowanceTo(). Default 10_000 (MinGasFee). gasReserve(): wasmtypes.ScImmutableUint64 { return new wasmtypes.ScImmutableUint64(this.proxy.root(sc.ParamGasReserve)); } @@ -78,7 +78,7 @@ export class ImmutableTransferAccountToChainParams extends wasmtypes.ScProxy { export class MutableTransferAccountToChainParams extends wasmtypes.ScProxy { // Optional gas amount to reserve in the allowance for the internal - // call to transferAllowanceTo(). Default 100 (MinGasFee). + // call to transferAllowanceTo(). Default 10_000 (MinGasFee). gasReserve(): wasmtypes.ScMutableUint64 { return new wasmtypes.ScMutableUint64(this.proxy.root(sc.ParamGasReserve)); } diff --git a/packages/wasmvm/wasmlib/as/wasmlib/sandbox.ts b/packages/wasmvm/wasmlib/as/wasmlib/sandbox.ts index 41f4003e42..69dd006e77 100644 --- a/packages/wasmvm/wasmlib/as/wasmlib/sandbox.ts +++ b/packages/wasmvm/wasmlib/as/wasmlib/sandbox.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // @formatter:off -export const MinGasFee : u64 = 100; +export const MinGasFee : u64 = 10_000; export const StorageDeposit : u64 = 20_000; export const FnAccountID : i32 = -1; diff --git a/packages/wasmvm/wasmlib/go/wasmlib/coreaccounts/params.go b/packages/wasmvm/wasmlib/go/wasmlib/coreaccounts/params.go index 71ca1ee49e..6cf3d80ad6 100644 --- a/packages/wasmvm/wasmlib/go/wasmlib/coreaccounts/params.go +++ b/packages/wasmvm/wasmlib/go/wasmlib/coreaccounts/params.go @@ -105,7 +105,7 @@ func NewImmutableTransferAccountToChainParams() ImmutableTransferAccountToChainP } // Optional gas amount to reserve in the allowance for the internal -// call to transferAllowanceTo(). Default 100 (MinGasFee). +// call to transferAllowanceTo(). Default 10_000 (MinGasFee). func (s ImmutableTransferAccountToChainParams) GasReserve() wasmtypes.ScImmutableUint64 { return wasmtypes.NewScImmutableUint64(s.Proxy.Root(ParamGasReserve)) } @@ -115,7 +115,7 @@ type MutableTransferAccountToChainParams struct { } // Optional gas amount to reserve in the allowance for the internal -// call to transferAllowanceTo(). Default 100 (MinGasFee). +// call to transferAllowanceTo(). Default 10_000 (MinGasFee). func (s MutableTransferAccountToChainParams) GasReserve() wasmtypes.ScMutableUint64 { return wasmtypes.NewScMutableUint64(s.Proxy.Root(ParamGasReserve)) } diff --git a/packages/wasmvm/wasmlib/go/wasmlib/sandbox.go b/packages/wasmvm/wasmlib/go/wasmlib/sandbox.go index 8bb30f2edc..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) + // should be aligned to gas.LimitsDefault.MinGasPerRequest + MinGasFee = uint64(10_000) StorageDeposit = uint64(20_000) FnAccountID = int32(-1) diff --git a/packages/wasmvm/wasmlib/interfaces/coreaccounts.yaml b/packages/wasmvm/wasmlib/interfaces/coreaccounts.yaml index 1eb0cdc360..fa64da5808 100644 --- a/packages/wasmvm/wasmlib/interfaces/coreaccounts.yaml +++ b/packages/wasmvm/wasmlib/interfaces/coreaccounts.yaml @@ -50,7 +50,7 @@ funcs: transferAccountToChain: params: # Optional gas amount to reserve in the allowance for the internal - # call to transferAllowanceTo(). Default 100 (MinGasFee). + # call to transferAllowanceTo(). Default 10_000 (MinGasFee). gasReserve=g: Uint64? # Transfers the specified allowance from the sender's L2 account diff --git a/packages/wasmvm/wasmlib/src/coreaccounts/params.rs b/packages/wasmvm/wasmlib/src/coreaccounts/params.rs index a8793140b6..0512d304b9 100644 --- a/packages/wasmvm/wasmlib/src/coreaccounts/params.rs +++ b/packages/wasmvm/wasmlib/src/coreaccounts/params.rs @@ -132,7 +132,7 @@ impl ImmutableTransferAccountToChainParams { } // Optional gas amount to reserve in the allowance for the internal - // call to transferAllowanceTo(). Default 100 (MinGasFee). + // call to transferAllowanceTo(). Default 10_000 (MinGasFee). pub fn gas_reserve(&self) -> ScImmutableUint64 { ScImmutableUint64::new(self.proxy.root(PARAM_GAS_RESERVE)) } @@ -145,7 +145,7 @@ pub struct MutableTransferAccountToChainParams { impl MutableTransferAccountToChainParams { // Optional gas amount to reserve in the allowance for the internal - // call to transferAllowanceTo(). Default 100 (MinGasFee). + // call to transferAllowanceTo(). Default 10_000 (MinGasFee). pub fn gas_reserve(&self) -> ScMutableUint64 { ScMutableUint64::new(self.proxy.root(PARAM_GAS_RESERVE)) } diff --git a/packages/wasmvm/wasmlib/src/sandbox.rs b/packages/wasmvm/wasmlib/src/sandbox.rs index c76e995001..1f278b32d0 100644 --- a/packages/wasmvm/wasmlib/src/sandbox.rs +++ b/packages/wasmvm/wasmlib/src/sandbox.rs @@ -8,7 +8,7 @@ use crate::host::*; use crate::wasmrequests::*; // @formatter:off -pub const MIN_GAS_FEE : u64 = 100; +pub const MIN_GAS_FEE : u64 = 10_000; pub const STORAGE_DEPOSIT : u64 = 20_000; pub const FN_ACCOUNT_ID : i32 = -1; diff --git a/packages/wasmvm/wasmlib/ts/wasmlib/coreaccounts/params.ts b/packages/wasmvm/wasmlib/ts/wasmlib/coreaccounts/params.ts index 79b189ab03..374ca3414b 100644 --- a/packages/wasmvm/wasmlib/ts/wasmlib/coreaccounts/params.ts +++ b/packages/wasmvm/wasmlib/ts/wasmlib/coreaccounts/params.ts @@ -70,7 +70,7 @@ export class MutableFoundryModifySupplyParams extends wasmtypes.ScProxy { export class ImmutableTransferAccountToChainParams extends wasmtypes.ScProxy { // Optional gas amount to reserve in the allowance for the internal - // call to transferAllowanceTo(). Default 100 (MinGasFee). + // call to transferAllowanceTo(). Default 10_000 (MinGasFee). gasReserve(): wasmtypes.ScImmutableUint64 { return new wasmtypes.ScImmutableUint64(this.proxy.root(sc.ParamGasReserve)); } @@ -78,7 +78,7 @@ export class ImmutableTransferAccountToChainParams extends wasmtypes.ScProxy { export class MutableTransferAccountToChainParams extends wasmtypes.ScProxy { // Optional gas amount to reserve in the allowance for the internal - // call to transferAllowanceTo(). Default 100 (MinGasFee). + // call to transferAllowanceTo(). Default 10_000 (MinGasFee). gasReserve(): wasmtypes.ScMutableUint64 { return new wasmtypes.ScMutableUint64(this.proxy.root(sc.ParamGasReserve)); } diff --git a/packages/wasmvm/wasmlib/ts/wasmlib/sandbox.ts b/packages/wasmvm/wasmlib/ts/wasmlib/sandbox.ts index 036cf03c3a..f4c315be72 100644 --- a/packages/wasmvm/wasmlib/ts/wasmlib/sandbox.ts +++ b/packages/wasmvm/wasmlib/ts/wasmlib/sandbox.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // @formatter:off -export const MinGasFee : u64 = 100n; +export const MinGasFee : u64 = 10_000n; export const StorageDeposit : u64 = 20_000n; export const FnAccountID : i32 = -1; diff --git a/packages/wasmvm/wasmsolo/solocontext.go b/packages/wasmvm/wasmsolo/solocontext.go index 313c7b5a85..d07b688152 100644 --- a/packages/wasmvm/wasmsolo/solocontext.go +++ b/packages/wasmvm/wasmsolo/solocontext.go @@ -51,7 +51,6 @@ var ( ) const ( - MinGasFee = 100 L2FundsAgent = 10 * isc.Million L2FundsContract = 10 * isc.Million L2FundsCreator = 20 * isc.Million @@ -406,7 +405,7 @@ func (ctx *SoloContext) MintNFT(agent *SoloAgent, metadata []byte) wasmtypes.ScN // tokens in its address and pre-deposits 10Mi into the corresponding chain account func (ctx *SoloContext) NewSoloAgent(name string) *SoloAgent { agent := NewSoloAgent(ctx.Chain.Env, name) - ctx.Chain.MustDepositBaseTokensToL2(L2FundsAgent+MinGasFee, agent.Pair) + ctx.Chain.MustDepositBaseTokensToL2(L2FundsAgent+wasmlib.MinGasFee, agent.Pair) return agent } diff --git a/tools/wasp-cli/authentication/login.go b/tools/wasp-cli/authentication/login.go index 236c9cba37..18293ce61b 100644 --- a/tools/wasp-cli/authentication/login.go +++ b/tools/wasp-cli/authentication/login.go @@ -37,7 +37,8 @@ func initLoginCmd() *cobra.Command { username = scanner.Text() log.Printf("Password: ") - passwordBytes, err := term.ReadPassword(int(syscall.Stdin)) //nolint:nolintlint,unconvert // int cast is needed for windows + // int cast is needed for windows + passwordBytes, err := term.ReadPassword(int(syscall.Stdin)) //nolint:unconvert if err != nil { panic(err) }