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

Function::decode_input should assume that first 4 bytes are function signature hash #222

Open
midnightexigent opened this issue May 11, 2021 · 2 comments

Comments

@midnightexigent
Copy link

to solve the problem mentionned here #180

possible new implementation for Function::decode_input

	pub fn decode_input(&self, data: &[u8]) -> Result<Vec<Token>> {
	    let signed = short_signature(&self.name, &self.input_params()).to_vec();
            if signed[..4] != data[..4] { return Err(".."); }
	    decode(&self.input_param_types(), &data[4..])
	}
@alex88
Copy link

alex88 commented Dec 10, 2021

Would also be nice to have a method that finds the function based on the input data by itself.

@r2d2-rmbl
Copy link

r2d2-rmbl commented Dec 18, 2021

I had a struct layout like this: ((address,bytes),string,bytes32) for my encoded function call, so just trimming those 4 bytes didn't work for me. This is because we need to add a tuple offset for tuples with dynamic data.

I ended up having to

  1. trim the first 4 function bytes
  2. prepend '0000000000000000000000000000000000000000000000000000000000000020' to the encoded bytes' hexstring.

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

No branches or pull requests

3 participants