[gnovm/bug] deploying same contract to longer pkg_path spends more gas
deploying same contract to longer pkg_path spends more gas
Description
Originally, this issue was founded here
Somehow, deploying same contract to longer pkg_path spends more gas
- deploy to gno.land/p/demo/gnoswap/u1 => 9.5M
- deploy to gno.land/p/demo/gnoswap/u2 => 9.5M
- deploy to gno.land/p/demo/gnoswap/what_an_long_pkg_path => out of gas
- deploy to gno.land/p/demo/gnoswap/longer_path => 9.9M
@r3v4s Just curious, to narrow down the problem - did you do these simulations on a fresh chain every time (the deployment is the single transaction), or on the same chain (you've tested out all deployments on a single chain together)?
@r3v4s Just curious, to narrow down the problem - did you do these simulations on a fresh chain every time (the deployment is the single transaction), or on the same chain (you've tested out all deployments on a single chain together)?
It's gnodev node and simulations are on same chain (not fresh). Should I test it also on fresh chain?
just a share of my test result(every time on fresh node). curious what's happening, more dig needed.
the difference between the two is: 815,040
gnokey maketx addpkg -pkgdir ./gnoswap/uint256 -pkgpath gno.land/p/demo/u2 -broadcast=true -gas-fee 1ugnot -gas-wanted 20000000 1216 -remote localhost:26657 Enter password.
OK! GAS WANTED: 20000000 GAS USED: 10627011 HEIGHT: 2 EVENTS: []
gnokey maketx addpkg -pkgdir ./gnoswap/uint256 -pkgpath gno.land/p/demo/what_a_long_pkg_path -broadcast=true -gas-fee 1ugnot -gas-wanted 20000000 1216 -remote localhost:26657 Enter password.
OK! GAS WANTED: 20000000 GAS USED: 11442051 HEIGHT: 6 EVENTS: []
if run on non-fresh node, the gas of the second addpkg will be different:
$ gnokey maketx addpkg -pkgdir ./gnoswap/uint256 -pkgpath gno.land/p/demo/u2 -broadcast=true -gas-fee 1ugnot -gas-wanted 20000000 1216 -remote localhost:26657
Enter password.
OK! GAS WANTED: 20000000 GAS USED: 10627011 HEIGHT: 2 EVENTS: [] (base)
$ gnokey maketx addpkg -pkgdir ./gnoswap/uint256 -pkgpath gno.land/p/demo/what_a_long_pkg_path -broadcast=true -gas-fee 1ugnot -gas-wanted 20000000 1216 -remote localhost:26657 Enter password.
OK! GAS WANTED: 20000000 GAS USED: 11444646 HEIGHT: 4 EVENTS: []
In a simplified scenario to replicate the issue, found that the long package path is referenced multiple times when setting objects for storage. The resulting increase in gas consumption just corresponds to the length of the extended path multiplied by the number of repetitions, which aligns with expectations. (This behavior has been consistently observed on a fresh node.)
However, when executing on a non-fresh node, an additional 2595 gas is consistently incurred compared to running on a fresh node. This discrepancy persists across various packages, whether simple or complex. While this discrepancy is peculiar, it may not be the primary cause of the issue at hand.
Before delving deeper into investigation, it would be helpful to understand the exact amount of gas increases due to the extended package path. This information will provide a clearer baseline for further analysis. @r3v4s , can you provide an exact number? 🙏
store set, write byte, writeCostPerByte: 30, len(value) 201, value: 482047 /gno.DeclaredType� 482048 gno.land/p/demo/helloAnimal� 482049 /gno.StructType~ 482050 gno.land/p/demo/hello 482051 name 482052 /gno.PrimitiveTyp 482053 age 482054 /gno.PrimitiveTyp@" 482055 gender 482056 /gno.PrimitiveTy e
store set, write byte, writeCostPerByte: 30, len(value) 236, value: 482053 /gno.DeclaredType� 482054 &gno.land/p/demo/what_a_very_long_helloAnimal� 482055 /gno.StructType� 482056 &gno.land/p/demo/what_a_very_long_hello 482057 name 482058 /gno.PrimitiveTyp 482059 age 482060 /gno.PrimitiveTyp@" 482061 gender 482062 /gno.PrimitiveTy e
Update: A simple solution could be to use a fixed-length pkgpath, such as gno.land/p/.....foo.Bar. However, I'm questioning whether this is worthwhile, as this issue isn't technically a bug.
@ltzmaxwell I'm not really sure that deploying to a longer path should take more gas. This would mean that over time, deployment cost would go up simply because the shorter paths are taken. Also, a user with a shorter username would not have to pay as much for as a user with a longer username for uploading the same code, which is unfair.
Is there any way we can not spend more gas only if a package path is longer?
I don't have a good solution for now, please pick it if you want, sorry for the delay. @leohhhn @r3v4s
It's likely a bug that we can fix. However, it may also be beneficial for security to encourage shorter names, as this improves readability when using or auditing the dApps.