-
Notifications
You must be signed in to change notification settings - Fork 162
Description
Hi, we recently have conducted a systematic study about Solidity event usage, evolution, and impact, and we are attempting to build a tool to improve the practice of Solidity event use based on our findings. We have tried our prototype tool on some of the most popular GitHub Solidity repositories, and for your repository, we find a potential optimization of gas consumption arisen from event use.
The point is that when we use emit operation to store the value of a certain variable, local memory type variable would be preferable to global storage type (state) variable if they hold the same value. The reason is that an extra SLOAD operation would be needed to access the variable if it is storage type, and the SLOAD operation costs 800 gas.
For your repository, we find that the following event use can be improved:
- KrakenPriceTicker.sol
function name: __callback
event name: LogNewKrakenPriceTicker
variable: priceETHXBT->_result
function __callback(
bytes32 _myid,
string memory _result,
bytes memory _proof
)
public
{
require(msg.sender == provable_cbAddress());
update(); // Recursively update the price stored in the contract...
priceETHXBT = _result;
emit LogNewKrakenPriceTicker(priceETHXBT);
}- WolframAlpha.sol
function name: __callback
event name: LogNewTemperatureMeasure
variable: temperature->_result
function __callback(
bytes32 _myid,
string memory _result
)
public
{
require(msg.sender == provable_cbAddress());
temperature = _result;
emit LogNewTemperatureMeasure(temperature);
// Do something with the temperature measure...
}- YoutubeViews.sol
function name: __callback
event name: LogYoutubeViewCount
variable: viewsCount->_result
function __callback(
bytes32 _myid,
string memory _result
)
public
{
require(msg.sender == provable_cbAddress());
viewsCount = _result;
emit LogYoutubeViewCount(viewsCount);
// Do something with viewsCount, like tipping the author if viewsCount > X?
}-
WolframAlpha.sol
function name: __callback
event name: LogNewTemperatureMeasure
variable: temperature->_result -
CallerPaysForQuery.sol
function name: __callback
event name: LogNewEthPrice
variable: ethPriceInUSD->_result -
KrakenPriceTicker.sol
function name: __callback
event name: LogNewKrakenPriceTicker
variable: priceETHXBT->_result -
YoutubeViews.sol
function name: __callback
event name: LogYoutubeViewCount
variable: viewsCount->_result -
EncryptedQuery.sol
function name: __callback
event name: LogNewRequestStatus
variable: requestStatus->_result
Do you find our results useful? Your reply and invaluable suggestions would be greatly appreciated, and are vital for improving our tool. Thanks a lot for your time!