You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The generated log topic for events with dynamic size tuple inputs is incorrect. I noticed this issue while testing a contract using the eth-brownie package. Below is a demonstration of the issue.
contracts/Foobar.sol
// SPDX-License-Identifier: MITpragma solidity0.7.6;
pragma abicoder v2;
/// @title A placeholder demo contract/// @dev Used for demonstrating bug in eth-eventcontractFoobar {
struct Foo {
address x;
uint8 y;
bytes4[] z;
}
/// @notice This event gets emitted everytime function main is called/// @dev An example of an event with a dynamic tuple/struct for an argument/// @dev Topic = keccak("Bar((address,uint8,bytes4[])[],address,string)")/// 0x0ec34a86243bfab8deb0e5685fb8ecacabf10ede0975ba4c8c61bbfdaad70a3c/// @dev Incorrectly gets encoded as 0x820a1d2c7df65cbffdfe074485ce39f5e4722d7c99abef3883bcc2c68a32b612/// @param _foo a Foo type argument/// @param _x a address type argument/// @param _y a string type argumentevent Bar(Foo[] _foo, address_x, string_y);
/// @notice The primary entrypoint for this demofunction main() external {
// a dynamic bytes4 array of size 1bytes4[] memory _z =newbytes4[](1);
_z[0] =bytes4(0x00c0ffee);
// a dynamic Foo type array of size 1
Foo[] memory _foo =newFoo[](1);
_foo[0] =Foo({x: address(this), y: 0, z: _z});
address _x =address(this);
stringmemory _y ="Hello World!";
// emit the eventemitBar(_foo, _x, _y);
}
}
build/contracts/Foobar.json
Note: The following is only the ABI of the Foobar contract, and not the full build output.
The first test (test_emitted_event_is_correctly_hashed) passes, verifying that the correct log topic for the Bar event is actually 0x0ec34a86243bfab8deb0e5685fb8ecacabf10ede0975ba4c8c61bbfdaad70a3c. The second test however fails, as the generated log topic via eth-event.get_log_topic is 0x820a1d2c7df65cbffdfe074485ce39f5e4722d7c99abef3883bcc2c68a32b612.
This issue is due to a minor bug in the eth_event/main.py::_params function.
When given the Bar event's inputs from build/contracts/Foobar.json, the _params function incorrectly enters the if i["type"] != "tuple" branch and simply appends tuple[] to the types list.
How can it be fixed?
A simple fix would change the branching logic of the _params function, to also evaluate whether the input type is a tuple array (whether it be fixed size or dynamic would also matter). Similar to the already written code, some recursion would be necessary to get the types of the components of the tuple array and care needs to be taken to include the array notation at the end of the returned tuple type (i.e. (address,uint8,bytes)[])
Additional Contextual Material
Some stuff I found while researching why this error was occurring for me:
Types can be combined to a tuple by enclosing them inside parentheses, separated by commas: (T1,T2,...,Tn): tuple consisting of the types T1, …, Tn, n >= 0 It is possible to form tuples of tuples, arrays of tuples and so on. It is also possible to form zero-tuples (where n == 0).
Environment information
eth-event
Version: 1.2.0What was wrong?
The generated log topic for events with dynamic size tuple inputs is incorrect. I noticed this issue while testing a contract using the
eth-brownie
package. Below is a demonstration of the issue.contracts/Foobar.sol
build/contracts/Foobar.json
tests/log_topic_tests.py
The first test (
test_emitted_event_is_correctly_hashed
) passes, verifying that the correct log topic for theBar
event is actually0x0ec34a86243bfab8deb0e5685fb8ecacabf10ede0975ba4c8c61bbfdaad70a3c
. The second test however fails, as the generated log topic viaeth-event.get_log_topic
is0x820a1d2c7df65cbffdfe074485ce39f5e4722d7c99abef3883bcc2c68a32b612
.This issue is due to a minor bug in the
eth_event/main.py::_params
function.eth_event/main.py::_params
When given the
Bar
event's inputs from build/contracts/Foobar.json, the_params
function incorrectly enters theif i["type"] != "tuple"
branch and simply appendstuple[]
to thetypes
list.How can it be fixed?
A simple fix would change the branching logic of the
_params
function, to also evaluate whether the input type is a tuple array (whether it be fixed size or dynamic would also matter). Similar to the already written code, some recursion would be necessary to get the types of the components of the tuple array and care needs to be taken to include the array notation at the end of the returned tuple type (i.e.(address,uint8,bytes)[]
)Additional Contextual Material
Some stuff I found while researching why this error was occurring for me:
Contract ABI Specification - Types
Most interesting to note is:
Contract ABI Specification - Handling Tuple Types
The text was updated successfully, but these errors were encountered: