rust-ethereum / ethabi

Encode and decode smart contract invocations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decode work but Parser not

kamikazebr opened this issue · comments

The issue

When i'm trying decode ((uint256,uint256,address,address,(address,uint256,bytes)[],bytes32,bytes),(uint256,(address,uint256),(address,uint256),address,bytes,uint256)) using the ethabi decode command i get error.

That below its the same abi getting decoded correctly

image
image

here the test code used

image

So the code work how expected when we defined in the code the structure to be decoded.

But when we use the command below:

image

I put some logs to understand what happening, but the error its that.

Error: Invalid name: (address,uint256,bytes)[],bytes32,bytes) nested

Looks like the parser can't understand the array of tuples inside the tuples correctly, so miss the count of parenteses and brackets.

To reproduce

cargo run -- decode params -t '((uint256,uint256,address,address,(address,uint256,bytes)[],bytes32,bytes),(uint256,(address,uint256),(address,uint256),address,bytes,uint256))' 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000062bc94dd000000000000000000000000809c9f8dd8ca93a41c3adca4972fa234c28f7714000000000000000000000000f7ca580b38d60b00eac495d6f932c5affa55a41800000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000ac979eacb1738f77d107c66f45b0e0cf6122de6a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e4b434151c0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000809c9f8dd8ca93a41c3adca4972fa234c28f77140000000000000000000000000000000000000000000000000214e8348c4f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e516d56685172656e3472394261776266767346654d6937344b794b58414d527a77564d6b62747075564a7778356500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e516d56685172656e3472394261776266767346654d6937344b794b58414d527a77564d6b62747075564a777835650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000093a8000000000000000000000000071850b7e9ee3f13ab46d67167341e4bdc905eef9000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000071850b7e9ee3f13ab46d67167341e4bdc905eef9000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000044e4fcfed14e1285c9e0f6eae77d5fdd0f196f85000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000000000000000000000000000000000000000000

test code

Put that in decoder.rs

#[test]
	fn decode_our_test() {
		let encoded = hex!(
			"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000062bc94dd000000000000000000000000809c9f8dd8ca93a41c3adca4972fa234c28f7714000000000000000000000000f7ca580b38d60b00eac495d6f932c5affa55a41800000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000ac979eacb1738f77d107c66f45b0e0cf6122de6a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e4b434151c0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000809c9f8dd8ca93a41c3adca4972fa234c28f77140000000000000000000000000000000000000000000000000214e8348c4f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e516d56685172656e3472394261776266767346654d6937344b794b58414d527a77564d6b62747075564a7778356500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e516d56685172656e3472394261776266767346654d6937344b794b58414d527a77564d6b62747075564a777835650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000093a8000000000000000000000000071850b7e9ee3f13ab46d67167341e4bdc905eef9000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000071850b7e9ee3f13ab46d67167341e4bdc905eef9000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000044e4fcfed14e1285c9e0f6eae77d5fdd0f196f85000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000000000000000000000000000000000000000000"
		);

		let param = 
			// ParamType::Tuple(vec![
			ParamType::Tuple(vec![
			ParamType::Tuple(vec![
				ParamType::Uint(256),
				ParamType::Uint(256),
				ParamType::Address,
				ParamType::Address,
				ParamType::Array(Box::new(ParamType::Tuple(vec![
					ParamType::Address,
					ParamType::Uint(256),
					ParamType::Bytes,
				]))),
				ParamType::FixedBytes(32),
				ParamType::Bytes,
			]),
			ParamType::Tuple(vec![
				ParamType::Uint(256),
				ParamType::Tuple(vec![ParamType::Address, ParamType::Uint(256)]),
				ParamType::Tuple(vec![ParamType::Address, ParamType::Uint(256)]),
				ParamType::Address,
				ParamType::Bytes,
				ParamType::Uint(256),
			]),
		// ])
		]);
		
		let abi = Writer::write(&param);

		println!("abi: {}",abi);
		let decoded = decode(
			&[param],
			&encoded,
		)
		.unwrap();

		println!("decoded: {:#?}", decoded);
		let tu = decoded[0].to_owned();

		match tu {
			Token::Tuple(tuple)=> println!("{:?}",tuple),
			_ => ()
		}
	} ```