osmosis-labs / osmosis

The AMM Laboratory
https://app.osmosis.zone
Apache License 2.0
887 stars 581 forks source link

BeforeSend Hook impact analysis on the Incentives module #2572

Open ljah8 opened 2 years ago

ljah8 commented 2 years ago

The main task during the Informal Audit of Before Send hook design and implementation was to detect the possible area of impact and to see if there are places that could lead to panicking in modules affected the most.

Artifacts:

BeforeSend hook Facts:

Expectations:

Analysis Summary:

If the smart contract would be written so that some accounts can't send coins but can receive them, distribution of native tokens in the incentives module would cause a panic in AfterEpochEnd.

AfterEpochEnd: https://github.com/osmosis-labs/osmosis/blob/f09305e60b5b23fec761ea14446ee33556313e69/x/incentives/keeper/hooks.go#L42-L45

doDistributionSends - send coins from the module account to various recipients: https://github.com/osmosis-labs/osmosis/blob/f09305e60b5b23fec761ea14446ee33556313e69/x/incentives/keeper/distribute.go#L200-L207

Concerns:

Conclusion: It seems that exists a potential risk in this module for a new feature. Smart contract could be written to cause a panic in the module, so it is necessary to consider how to protect it.

dalmirel commented 2 years ago

Comments from our 09/02 sync meeting with @ValarDragon and @sunnya97:

The needed semantic for this problematic place would be to only log the error received upon the triggering of the hook. Sending should be done in case there are no errors of type != BeforeSend hook error type, for the denominations that could be sent.

There are two ways of approaching the problematic places - not sure if any approach is nice enough

  1. to suppress and ignore errors for the denominations that can not be sent
  2. to change the API of the sending to many accounts function to return the list of the errors received for each to be able to analyze the result...