Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Issue sending address data to ABI packer as a byte array #1326

Closed
3 of 4 tasks
maxwellfoley3 opened this issue Jan 28, 2020 · 1 comment · Fixed by #1330
Closed
3 of 4 tasks

Issue sending address data to ABI packer as a byte array #1326

maxwellfoley3 opened this issue Jan 28, 2020 · 1 comment · Fixed by #1330

Comments

@maxwellfoley3
Copy link

maxwellfoley3 commented Jan 28, 2020

Describe the Bug
I cannot successfully send address data in the form of a byte array to the ABI packing function Burrow provides. It seems to me like it might be a bug.

To Reproduce

import (
	"github.com/hyperledger/burrow/crypto"
	"github.com/hyperledger/burrow/execution/evm/abi"
	"github.com/hyperledger/burrow/logging"
)

	AbiJsonString := `
	[
		{
			"constant": false,
			"inputs": [
				{
					"internalType": "address payable",
					"name": "friend",
					"type": "address"
				}
			],
			"name": "sendToAFriend",
			"outputs": [],
			"payable": true,
			"stateMutability": "payable",
			"type": "function"
		}
	]`
	

	bytesData := []byte{
		0, 0, 0, 0,
		0, 0, 0, 0,
		0, 0, 3, 4,
		1, 2, 3, 4,
		1, 2, 3, 4,
		1, 2, 3, 4,
		1, 2, 3, 4,
		1, 2, 3, 4}

	var toArr [20]byte
	copy(toArr[:], padOrTrim(bytesData, 32)[10:32])
	var toAddr crypto.Address = toArr

	sendToAFriendCall, _, err := abi.EncodeFunctionCall(
		AbiJsonString,
		"sendToAFriend",
		logging.NewNoopLogger(),
		toArr,
	)

	fmt.Println("err", err) // <nil>
	fmt.Println("sendToAFriendCall", sendToAFriendCall) 
	//[72 151 224 99 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

	sendToAFriendCall2, _, err := abi.EncodeFunctionCall(
		AbiJsonString,
		"sendToAFriend",
		logging.NewNoopLogger(),
		toAddr,
	)

	fmt.Println("err", err) // cannot map to array to EVM address
	fmt.Println("sendToAFriendCall2", sendToAFriendCall2) // []

Expected Behavior

The address should be properly packed and added onto the ABI array

In the above example, the packed ABI should be

[72 151 224 99 0 0 0 0 0 0 0 0 0 0 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4]

Technical Details

  • Burrow Version (docker image tag or branch if built from source) 0.29.7
  • Go Version (if applicable) 1.13.6
  • Docker Version (if applicable)
  • Operating System (osx/windows/linux) 10.14.6

Additional Context

The issue seems to me to be in the pack function in execution/evm/abi/primitives.go. The code first tries to cast interface v to a crypto.Address. If I pass the function a crypto.Address, the cast will be successful and it will take the else path after the check on line 519. At that point, it will try to cast v to a []byte. This will fail and an error will be returned on line 530.

Forgive me if I am misunderstanding things since I am somewhat new to Golang, but it seems to me like it is impossible to get to line 533 because the code is expecting v to be two different types at the same time (crypto.Address and []byte). While crypto.Address is an alias for binary.Word160 which is an alias for [20]byte, this does not make it compatible with []byte, due to the incompatibility between fixed-length and dynamic-length arrays.

silasdavis pushed a commit that referenced this issue Feb 11, 2020
Signed-off-by: Silas Davis <silas@monax.io>
@silasdavis
Copy link
Contributor

Thanks @maxwellfoley3 this is a bug as you describe, I've just PR'd a fix in #1330

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

Successfully merging a pull request may close this issue.

2 participants