Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abigen v1.9.25 bytes32 interface conversion bug #22219

Closed
albertchon opened this issue Jan 23, 2021 · 1 comment · Fixed by #22230
Closed

Abigen v1.9.25 bytes32 interface conversion bug #22219

albertchon opened this issue Jan 23, 2021 · 1 comment · Fixed by #22230
Assignees
Labels

Comments

@albertchon
Copy link

albertchon commented Jan 23, 2021

System information

Geth version: geth version 1.9.25, abigen version 1.9.25-stable
OS & Version: OSX
Commit hash : e7872729012a4871397307b12cc3f4772ffcbec6

Expected behaviour

After generating contract bindings using abigen version 1.9.25-stable, I tried calling a view function getOrderRelevantStates (see below)

// GetOrderRelevantStates is a free data retrieval call binding the contract method 0xe25cabf7.
//
// Solidity: function getOrderRelevantStates((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[] orders, bytes[] signatures) view returns((uint8,bytes32,uint256,bytes32,uint8,bytes32,uint256)[] ordersInfo, uint256[] fillableTakerAssetAmounts, bool[] isValidSignature)
func (f *FuturesCaller) GetOrderRelevantStates(opts *bind.CallOpts, orders []Order, signatures [][]byte) (struct {
	OrdersInfo                []DerivativeOrderInfo
	FillableTakerAssetAmounts []*big.Int
	IsValidSignature          []bool
}, error) {
	var out []interface{}
	err := f.contract.Call(opts, &out, "getOrderRelevantStates", orders, signatures)

	outstruct := new(struct {
		OrdersInfo                []DerivativeOrderInfo
		FillableTakerAssetAmounts []*big.Int
		IsValidSignature          []bool
	})

	outstruct.OrdersInfo = out[0].([]DerivativeOrderInfo)
	outstruct.FillableTakerAssetAmounts = out[1].([]*big.Int)
	outstruct.IsValidSignature = out[2].([]bool)

	return *outstruct, err

}

where the DerivativeOrderInfo struct is defined as

// DerivativeOrderInfo is an auto generated low-level Go binding around an user-defined struct.
type DerivativeOrderInfo struct {
	OrderStatus                 uint8
	OrderHash                   [32]byte
	OrderTakerAssetFilledAmount *big.Int
	SubAccountID                [32]byte
	Direction                   uint8
	MarketID                    [32]byte
	EntryPrice                  *big.Int
}

It's expected this call should work successfully without any panics.

Actual behaviour

However, this results in the following panic

panic: interface conversion: interface {} is []struct { OrderStatus uint8 "json:\"orderStatus\""; OrderHash [32]uint8 "json:\"orderHash\""; OrderTakerAssetFilledAmount *big.Int "json:\"orderTakerAssetFilledAmount\""; SubAccountID [32]uint8 "json:\"subAccountID\""; Direction uint8 "json:\"direction\""; MarketID [32]uint8 "json:\"marketID\""; EntryPrice *big.Int "json:\"entryPrice\"" }, not []wrappers.DerivativeOrderInfo

The OrderHash, SubAccountID, and MarketID fields are attempting to be converted as [32]uint8 instead of [32]byte as expected.

We manually fixed this in our contract binding wrapper here but this should be fixed on the abigen level obviously.

@albertchon albertchon changed the title Abigen v1.9.25 fails Abigen v1.9.25 bytes32 interface conversion bug Jan 23, 2021
@MariusVanDerWijden MariusVanDerWijden self-assigned this Jan 25, 2021
@MariusVanDerWijden
Copy link
Member

MariusVanDerWijden commented Jan 25, 2021

@albertchon Could you maybe share your solidity contract so that I can reproduce the issue better?

Edit: nevermind, I built a contract that can repro this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants