Skip to content

Conversation

@zhiqiangxu
Copy link
Contributor

This PR fixes this testcase :

type fixedBytes struct {
	Chunk [4 * 1024]byte
	A     *big.Int
}

func TestMinimal(t *testing.T) {
	IntTy, _ := abi.NewType("uint256", "", nil)
	Bytes4096Ty, _ := abi.NewType("bytes4096", "", nil)
	Abi := abi.Arguments{
		{Type: Bytes4096Ty, Name: "Chunk"},
		{Type: IntTy, Name: "A"},
	}
	a := big.NewInt(10)
	chunk := [4 * 1024]byte{0x03, 0x4}
	packed, err := Abi.Pack(chunk, a)
	if err != nil {
		t.Fatal(err)
	}

	values, err := Abi.Unpack(packed)
	if err != nil {
		t.Fatal(err)
	}

	var decoded fixedBytes
	err = Abi.Copy(&decoded, values)
	if err != nil {
		t.Fatal(err)
	}
	if decoded.Chunk != chunk {
		t.Fatal("Chunk mismatch")
	}
	if decoded.A.Cmp(a) != 0 {
		t.Fatal("A mismatch")
	}
}

@karalabe
Copy link
Member

Thanks for the PR, however these types of changes will not be accepted without extensive tests. You are introducing new functionality, we need to ensure it works as intended.

@zhiqiangxu
Copy link
Contributor Author

Thanks for the PR, however these types of changes will not be accepted without extensive tests. You are introducing new functionality, we need to ensure it works as intended.

I see, that's understandable.

@ligi ligi added the need:test label Oct 27, 2022
@rjl493456442
Copy link
Member

According to ABI spec the maximum length supported for fixed size is 32, https://docs.soliditylang.org/en/v0.8.17/abi-spec.html.

bytes<M>: binary type of M bytes, 0 < M <= 32.

Can you share the link if the type is newly introduced?

@zhiqiangxu
Copy link
Contributor Author

zhiqiangxu commented Oct 31, 2022

According to ABI spec the maximum length supported for fixed size is 32, https://docs.soliditylang.org/en/v0.8.17/abi-spec.html.

bytes<M>: binary type of M bytes, 0 < M <= 32.

Can you share the link if the type is newly introduced?

Oops, didn't know the spec. If fixed bytes size is specified to be <= 32, maybe abi.NewType("bytes4096", "", nil) should return a non nil error?

@rjl493456442
Copy link
Member

@zhiqiangxu yeah, technically we can build bytes4096, but in practice there is no such type. But maybe we can add a check for rejecting non-spec'd type.

Feel free to open PR for the additional check. But I will close this PR if you are fine for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants