Replies: 3 comments 2 replies
-
Thanks for starting this discussion @mshakeg, I really like this idea and feel it could benefit our users a great deal. I have a few questions about this so we can flesh out this proposal a bit more. Can you give a scenario of a simulation and how it gets implemented in the in the Here's another train of thought here: will the simulation methods be available for all types of smart contracts including those developed outside the Hedera ecosystem? What I mean by that is, could we simulate bridging transactions? We aren't integrated with Axelar, but thinking forward to when it will be common to see cross-chain swaps and that sort of thing, how would we simulate those types of transactions? I would imagine this will increase the usage of our community service rpc relay Hashio, and we may need to think about how this would affect our current throttle. Thank you again for bringing up this discussion. We have a hip template in the root of this repository. If you fork this repo and use that template to fill out the details of this discussion and make a PR, we can start moving this discussion formally as a hip if you like. @Nana-EC what are your thoughts as to how we can flesh this out with a specification? |
Beta Was this translation helpful? Give feedback.
-
Radix's Transaction Manifests appear to offer a simpler(as it doesn't require any tx simulation at the time of signing) and more secure method(as it's enforced at the network level) for achieving the same objectives as this concept, at least for the most common DeFi interactions. It seems feasible to adapt this concept for the HSCS(involving HTS interactions). As I understand it, the transaction manifest outlines conditions for asset checks, which are validated after the execution of the smart contract. If these conditions are met, the transaction is not reverted; otherwise, it is. For instance, if you wish to exchange X amount of tokenA for at least Y amount of tokenB, the transaction manifest would stipulate that your tokenA balance should decrease by no more than X and your tokenB balance should increase by at least Y following EVM execution. |
Beta Was this translation helpful? Give feedback.
-
Hey @mshakeg Assuming so, I totally agree with the need and would like to see wallets and DApps highlight this to users for security reasons. One consideration is does https://hips.hedera.com/hip/hip-801 using debug_traceTransaction assist you? Will review the additional links you shared and circle back. |
Beta Was this translation helpful? Give feedback.
-
Background
It would be helpful for users to gain visibility into a contract transaction before signing it to validate its correctness and potential effects, particularly when working with complex smart contracts that may execute HTS actions such as transfers and approvals. AFAIK there's no standard way of doing this on Ethereum, however, a few 3rd party node providers have developed services for simulating/previewing a transaction such as Alchemy and Blocknative[1] [2]. Aptos is a non-EVM chain that supports transaction simulation with detailed insights into effects[3].
HIP-584 adds an EVM module to the mirror node which allows for the transient execution of EVM transactions to facilitate gas estimates and static EVM calls exposed by the
eth_estimateGas
andeth_call
json rpc methods respectively. However, whileeth_estimateGas
andeth_call
return some information about transactions, such as thegas_used
andcall_result
(orerror_message
in the case of a revert), neither method returns the eventlogs
which if set up correctly can be used to gain greater insight into a transaction.Proposal
The mirror node should expose a
/api/v1/contracts/simulate
endpoint that accepts the same request body as the/api/v1/contracts/call
endpoint proposed in HIP-584, however, adds an additionalsimulationType
field that could be either of the following 4 values:simulateAssetChanges
- Simulates a transaction and returns a list of HTS asset changes. The return data is in a standard predefined format and unlike the followingsimulateExecution
type does NOT require the contract ABI to decode.simulateExecution
- Simulates a transaction and returns the same data as/api/v1/contracts/results/{transactionIdOrHash}
; most importantly thecall_result
,error_message
(in the case of a revert),logs
and theresult
.simulateAssetChangesBundle
- Similar tosimulateAssetChanges
however simulates multiple transactions sequentially and returns a list of HTS asset changes.simulateExecutionBundle
- Similar tosimulateExecution
however simulates multiple transactions sequentially.The Hedera JSON RPC Relay can expose the following 4 corresponding methods(with identical request schema to
eth_call
):hedera_simulateAssetChanges
hedera_simulateExecution
hedera_simulateAssetChangesBundle
hedera_simulateExecutionBundle
Methods 3 and 4 will probably be more useful to developers and researchers than the typical user who'll likely only be executing a single transaction at a time at the "latest" blockTag. If a user wishes to gain insight into a transaction pre-signing wallets should allow a user to globally turn on contract transaction previews or whitelist contracts and toggle on the transaction preview functionality on a per contract basis since request simulations will take some time to fetch. Additionally, when whitelisting a contract wallets should request an ABI that is a union of all ABIs for contracts that could be called by the contract that is being whitelisted, since in order for the results of
simulateExecution
calls to be decoded and displayed to the user not only will the function inputs for the whitelisted contract have to be decoded but also events and errors that could occur at any call depth beyond the whitelisted contract.Conclusion
The addition of these four simulation methods would greatly improve the ability of developers and users to test and validate the correctness and potential effects of transactions before submitting them to the Hedera network. This would help reduce issues arising from signing transactions that result in the loss of funds due to users unknowingly signing malicious transactions or potentially due to a bug in the contract.
In order for end users to benefit from this wallets will have to integrate this functionality and display the simulation results in a user-friendly format and highlight any potential issues or errors. Additionally, allowing users to adjust transaction details(i.e. the inputs to the function) and to re-simulate transactions until they are satisfied with the potential outcome can improve the overall user experience of the wallet.
References
Beta Was this translation helpful? Give feedback.
All reactions