zksync-sdk / zksync2-go

zksync2-go is a geth library adapted to work with the zkSync Era.
Apache License 2.0
87 stars 36 forks source link

Encoding paymaster params for a general paymaster does not work #30

Closed ETeissonniere closed 7 months ago

ETeissonniere commented 7 months ago

πŸ› Bug Report for zksync2-go Go SDK

πŸ“ Description

GetGeneralPaymasterInput will fail due to the underlying behavior of the github.com/ethereum/go-ethereum/accounts/abi library which expects an input as bytes instead of types.GeneralPaymasterInput.

πŸ”„ Reproduction Steps

GetGeneralPaymasterInput(types.GeneralPaymasterInput{}) should return an error.

πŸ€” Expected Behavior

It shouldn't return an error :)

😯 Current Behavior

It returns an error :)

Fix

The underlying ABI library expects the arguments to come in as []byte{}, since it uses reflect to check the type of the parameters passed. We were able to hack this around by passing []byte{} manually:

func hack_createPaymasterParams(paymasterAddress common.Address) (*types.PaymasterParams, error) {
    paymasterFlowAbi, err := abi.JSON(strings.NewReader(paymasterflow.IPaymasterFlowMetaData.ABI))
    if err != nil {
        return &types.PaymasterParams{}, fmt.Errorf("failed to load paymasterFlowAbi: %w", err)
    }

    input, err := paymasterFlowAbi.Pack("general", []byte{})
    if err != nil {
        return &types.PaymasterParams{}, fmt.Errorf("failed to pack general paymaster input: %w", err)
    }

    return &types.PaymasterParams{
        Paymaster:      paymasterAddress,
        PaymasterInput: input,
    }, nil
}

Of course this fix should be adapted to supporting the current code.

github-actions[bot] commented 7 months ago

:tada: This issue has been resolved in version 0.4.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: