zeta-chain / node

ZetaChain’s blockchain node and an observer validator client
https://zetachain.com
MIT License
167 stars 109 forks source link

Return proper ABI types in precompiles (prototype and staking) #2908

Open fbac opened 2 months ago

fbac commented 2 months ago

Describe the Bug Currently the prototype and staking precompiles doesn't return the expected values from a smart contract perspective in case of failure.

Example in the following snippet, look at the if execErr != nil statement:

    case GetAllValidatorsMethodName:
        var res []byte
        execErr := stateDB.ExecuteNativeAction(contract.Address(), nil, func(ctx sdk.Context) error {
            res, err = c.GetAllValidators(ctx, method)
            return err
        })
        if execErr != nil {
            return nil, err
        }
        return res, nil

Returning nil, err looks like an unexpected revert from another smart contract calling the precompile.

Instead of this, we should do return method.Outputs.Pack(SANE_ERROR_VALUE), where a sane error value is false, 0 or any values that applies.

Affected precompiles: prototype, staking.

lumtis commented 6 days ago

I'm removing bug label as it seems like just a design flaw to improve