PatrickAlphaC / hardhat-nft-fcc

100 stars 139 forks source link

remove obsolete from call #10

Closed n00b21337 closed 2 years ago

n00b21337 commented 2 years ago

Function callFunctionDirectly in CallAnything.sol has obsolete part as if we pass in calldata suggested above that function in code commment that is abi of transfer function and parameters then abi.encodeWithSignature("getSelectorThree(bytes)" part is obsolete and produces wrong result. Function needs to be as made in commit to output result properly. Tested it with remix and works as it should. Current code outputs wrong result

PatrickAlphaC commented 2 years ago

What are you inputting to callFunctionDirectly ?

n00b21337 commented 2 years ago

0xa9059cbb000000000000000000000000d7acd2a9fd159e69bb102a1ca21c9a3e3a5f771b000000000000000000000000000000000000000000000000000000000000007b

as suggested in comment above the function, which is hash of func selector and arguments.

PatrickAlphaC commented 2 years ago

My testing gets the opposite result. I'm not sure how the current code is obsolete. I'm not sure how you're getting the a different result.

n00b21337 commented 2 years ago

My testing gets the opposite result. I'm not sure how the current code is obsolete. I'm not sure how you're getting the a different result.

How I see it. Function selector is this bytes 0xa9059cbb We are passing into calldata 0xa9059cbb000000000000000000000000d7acd2a9fd159e69bb102a1ca21c9a3e3a5f771b000000000000000000000000000000000000000000000000000000000000007b

which already has function selector in it. So basically what we are doing with abi.encodeWithSignature("getSelectorThree(bytes)", callData) is concat of bytes of selector plus bytes of selector again with parametars.

PatrickAlphaC commented 2 years ago

Ahh, I see.

Ok so this is a little confusing, I should have clarified. The function callFunctionDirectly is calling getSelectorThree(bytes) which takes in a bytes object with a function selector and returns the function selector from the object.

So we aren't calling 0xa9059cbb, we are getting 0xa9059cbb as a return value. The function selector of the function we are calling is 0xce6eb7ff <- This is the function selector of getSelectorThree(bytes).

Hopefully that makes sense

n00b21337 commented 2 years ago

Patrick, thnx for effort and great tutorial