1

Working on some smart contract security cases to become more comfortable with it but am running into an issue.

In order to solve this particular puzzle, I need to initiate a fallback function from a contract that is non-payable and send some data along with it. In the case of a payable fallback function I'd just send over some wei together with the msg.data and that should work. But what if a fallback function is nonpayable? I can't select it as a function to send to in web3's sendTransaction right, because I do not have a method name for it.

How would you go about initiating that function while sending data along?

Cheers

  • So have you tried sendTransaction (with msg.value = 0 of course) or not? – goodvibration Jan 4 at 13:12
  • @goodvibration Managed to do it. Initially I was trying to call the fallback function (without sending value) by calling a non-existing method using the instance I had created in the console (e.g. contract.buyFruit() would work but contract.FFFnonexistingmethod() might call the fallback). This didn't work, what did work was using the web3.eth.sendTransaction and filling the data field with a nonexisting function (which I needed to pass as msg.data to go into the fallback function anyway). In other words, I called a non-existing method, which initiated the fallback using the msg.data passed. – Valentijn van den Hout Jan 4 at 14:41
1

Managed to do it. Initially

I was trying to call the fallback function (without sending value) by calling a non-existing method using the instance I had created in the console (e.g. contract.buyFruit() would work but contract.FFFnonexistingmethod() might call the fallback). This didn't work.

What did work was using the web3.eth.sendTransaction and filling the data field with a nonexisting function (which I needed to pass as msg.data to go into the fallback function anyway in this specific case). In other words, I called a non-existing method, which initiated the fallback, and passed the msg.data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.