zeta-chain / node

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

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

Open fbac opened 4 days ago

fbac commented 4 days 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.