Questions tagged [fallback-function]
Questions dealing with the Solidity fallback function
140
questions
0
votes
0
answers
12
views
Why fallback() function exists? [duplicate]
I am studying the fallback function, but I cannot still understand why "fallback() external payable {} " exists. It seems like it can cause security problems. why we define fallback function?...
1
vote
2
answers
186
views
Solidity low-level call and fallback function failed in hardhat-deploy
I am using examples in soliditylang.org special functions
My simple contracts are extracted from the link
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.2 <0.9.0;
contract ...
0
votes
0
answers
135
views
`EvmError: NotActivated` when modifying variables in fallback
I get the strange EvmError: NotActivated when I put the nonReentrant modifier, like the OZ one, on the fallback function. I need it there because I am working with Diamond Proxies which redirect all ...
0
votes
2
answers
100
views
Get an error calling delegate contract function with hardhat console
Here is my code
contract SimpleUpgrade {
address public implementation;
address public admin;
string public words;
constructor(address _implementation) {
admin = msg.sender;
...
3
votes
2
answers
274
views
What happens when a validator's withdrawal address is a smart contract with a fallback function?
Ethereum validators set a withdrawal address to automatically receive their staking rewards. These rewards are distributed gas free at the protocol level through a process called "validator ...
0
votes
1
answer
195
views
Disadvantages of using `call` function
Hey guys, I was reading about low-level methods of calling other contract functions and I found the following description of call method:
This is the recommended method to use when you're just ...
1
vote
1
answer
292
views
Fallback and Receive functions in Solidity [duplicate]
I have a contract that needs to be able to receive Ether. The contract includes a receive function to receive Ether but I wonder if it's good practice to also have a fallback function in case someone ...
0
votes
1
answer
29
views
questions about Re-Entrancy attack syntax
hey guys I come across this video about re-entrancy attack posted by Chainlink, but I have some questions about the syntax being covered. please help.
// SPDX-License-Identifier: MIT
pragma solidity ^...
0
votes
0
answers
57
views
Reentrancy attack (contract calling external contract to transfer funds)
So basically we have the code of some Curve pool (it's already rugged, just wonder if it was protected against reentrancy). Users deposit their curve pool tokens to this contract and it's locked for ...
0
votes
1
answer
68
views
I can't compile my contract. What's wrong with this fallback function?
function () payable external {
address impl = methodsImplementations[msg.sig];
require(impl != address(0x00), "Method not found. 404");
assembly {
let p := mload(...
0
votes
1
answer
113
views
Unable to deposit ether inside contract using receive function
Code is :
contract sendEther{
//to send ether, we need to deposit some ether first in this contract
//We can do it by declaring constructor as payable which enables us to deposit some ether ...
2
votes
1
answer
417
views
The low-level functions call, delegatecall and staticcall return true as their first return value if the account called is non-existent
According to the official Solidity documentation:
The low-level functions call, delegatecall and staticcall return true as their first return value if the account called is non-existent, as part of ...
1
vote
1
answer
85
views
Guess the number game , not working
I am trying to write a game on smart contract which is a game in which the player has to type in 5 guesses, and based on how close they were to the actual number, they would receive ether as prize.
...
1
vote
1
answer
37
views
decompiler smart contract code, how to read the result?
i scanned the smart contract in the decompiler, how will the withdrawal function be translated?
0
votes
0
answers
45
views
The old owner and the new owner of the smart contract
I encountered such a problem, when i imported the smart contract unto remix, i did this through ABI...ok
one wallet created two contracts, different times, the first contract is now worthless. i'm ...
1
vote
1
answer
48
views
How to connect our smart contract that contains the fallback function to the imported smart contract?
i'm still confused, i'm importing a smart contract address on remix ethereum via ABI, i think for the fallback function it make sense to type the contract source code or use the ABI, i hope i am right ...
1
vote
0
answers
39
views
how import in remix smart contract without source code?
I am trying to call a fallback function on a smart contract that has not verified contract source code, How can I do this?
Thanks in advance
1
vote
2
answers
51
views
How to send back the value sent to the fallback?
Is there a way to get and keep the value sent to the fallback/receive functions? Let's say, I want to send back Ethers that sent to my contract. Okay, existence of fallback function is enough to deal ...
0
votes
0
answers
188
views
Decode number of tokens and token contract address from msg.data (ERC-20)
I have a smart contract with just a fallback function and some logic.
I want users to send their tokens directly to the smart contract to do some smart contract logic on receive.
I've implemented ...
0
votes
2
answers
2k
views
address.call{}(abi.encodeWithSignature()) in solidity returns boolean and what other parameters?
I learned from this documentation https://docs.soliditylang.org/en/v0.8.15/contracts.html and this discussion How to use address.call{}() in solidity about abi.encodeWithSignature() .
I have question ...
0
votes
1
answer
466
views
delegate call from a fallback function using msg.data doesn't work
Please look into the following 3 contracts:
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;
contract implementationProxy {
uint public a;
uint public b;
address owner;
...
0
votes
1
answer
324
views
fallback not executing
I have a test project with proxy pattern (fallback/delegate call). The purpose is to have upgradeable contracts.
Here is the proxy contract:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
...
3
votes
2
answers
2k
views
Can ERC-20 token transfers have re-entrancy?
I understand that re-entrance attack can happened when you send ETH, because of fallback() function. But in ERC20 transfer there is no call for fallback, so I wonder if there's a way to make re-...
2
votes
0
answers
184
views
how to unit test fallback function using solidity by passing data
fallback() external payable {
bytes calldata data = msg.data;
bytes memory lendId =bytes(data[msg.data.length-32:]); //last parameter must be lendingId
uint256 _lendingId = uint256(abi....
0
votes
1
answer
79
views
Events in Chained Fallback Function Cause VirtualMachineError
I’m working on an upgradeable contract that uses fallback functions with inline assembly delegatecall and call calls (using calldatacopy and returndatacopy) to route internal and external function ...
1
vote
1
answer
244
views
How to check which fallback handler is set for a Gnosis Safe
I am using a 1.3 Gnosis Safe.
I want to check what fallback handler is set.
I find the function that can set it:
function internalSetFallbackHandler(address handler) internal {
bytes32 slot = ...
0
votes
1
answer
21
views
very important interface need help
the balance not change from another contract
pragma solidity ^0.8.10;
interface ICounter {
function balanceOf(address owner) external view returns (uint);
function transfer(address to, uint ...
0
votes
1
answer
101
views
How to interact with my first defi smart contract in remix?
I found this tuto online : https://cryptomarketpool.com/create-a-defi-bank-that-pays-interest-yield-farm/ and i deployed my token and my smart contract on testnet via remix.
The issue is that i am a ...
1
vote
0
answers
52
views
What the this keyword means?
im doing the ethernaut course. what does this mean ? I know what for exemple address(this)means, it s the address of the smart contract but like what does it means when the this is alone like this?
0
votes
1
answer
41
views
Contract does not accept eth sent from another contract
Hi I try to send ETH from Sender contract to Receiver contract by calling sendPayment function. But I get an error. I know that the issue is the require statement in the fallback function because ...
0
votes
1
answer
561
views
Transferring a value into a fallback function of a contract
I'm trying to figure out what happens when you send a value to a contract.
If the destination address (to) is a contract, then the EVM will execute the contract and will attempt to call the function ...
1
vote
1
answer
363
views
State variable not updated after DelegateCall
I deployed two contracts 'WalletLibrary' and 'Wallet': most of the functions in Wallet delegateCall() the functions from WalletLibrary. I want to recreate an Attack, where I call the initWallet() ...
0
votes
1
answer
36
views
Sending balance to contract fails
I'm playing ethernaut, the king of the hill level. I made a practice target contract and an attacking contract. I want to send value to the attacking contract (this works) then I want to send the ...
0
votes
0
answers
369
views
How the fallback and receive functions in version 8 differ from fallback function in version 5 of Solidity?
I found that in version 8, we explicitly use the keyword fallback for fallback function and there is a receive function also. Consider the following code:
receive() external payable {
...
}
fallback() ...
0
votes
0
answers
12
views
Struck with receive() and fallback() error. TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address" [duplicate]
I am new to solidity, learning smart contract development. I got stuck while I was learning about the fallback function. This function throws an error saying "TypeError: "send" and &...
1
vote
0
answers
132
views
Contract does not have fallback nor receive functions
In what circumstances a test can fail with the error "Contract does not have fallback nor receive functions" ?
My contract already contains both a fallback and a receive function:
event ...
2
votes
2
answers
1k
views
web3 estimateGas() from fallback function
When I sign and send raw transactions with web3 in javascipt , to call a method from Smart Contract, I always pass the transaction gas variable after getting it with estimateGas function, from Smart ...
3
votes
1
answer
802
views
Why does solidity need a fallback function? [duplicate]
I understand when the fallback function is called, but why is it needed at all?
It leaves the way open for a possible reentrancy attack.
It is called when a function of a contract is called that isn't ...
0
votes
1
answer
264
views
Sending ether to a contract without data throws an error
I'm trying to deploy a smart contract that allows users to buy tokens that can be used to pay fees on its platform.
In case someone is going to send ETH directly to the contract address without ...
1
vote
2
answers
411
views
Receive keyword in solidity
I was making a smart contract in which I wanted to send and receive ether.
My code:
contract coin_transfer_to {
function() public payable {
}
function get_balance() public returns (uint)
...
0
votes
2
answers
1k
views
Truffle Console: Sending Ether to a contract using fallback function
I have the following contract:
pragma solidity ^0.5.8;
contract Victim {
address owner;
constructor() public{
owner = msg.sender;
}
function deposit() payable public {}
}
If ...
0
votes
1
answer
101
views
Reflect Base contract's update in another contract
I have wanted to know what concept is it called when we want two contracts which are deployed on the Network, reflect the transaction and updates in another contract.
for example:
contract Base{
...
2
votes
2
answers
2k
views
What happens if there is no fallback function in solidity?
Here is the short definition about fallback function in solidity:
Solidity fallback function does not have any arguments, has external visibility and does not return anything.
What happens if there ...
0
votes
1
answer
418
views
Way to fetch function name in fallback function with Solidity
I am writing a fallback function this way:
fallback() external {
(param1, param2) = abi.decode(msg.data[4:], (uint256, uint256));
}
I know this is not a good practice but let's suppose i ...
4
votes
1
answer
681
views
Using selfdestruct in constructor
What's the purpose of such a call to this stub?
contract Sacrifice {
constructor(address payable _recipient) payable {
selfdestruct(_recipient);
}
}
Usage:
if (_token == address(0)) {
...
0
votes
1
answer
427
views
Why isn't my initial sendEther function not recognized as a receive ether function, am getting the error shown below [closed]
Error: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
Here is my code:
// SPDX-License-Identifier: MIT
pragma solidity >=0....
0
votes
0
answers
92
views
amount of gas used in receive and fallback functions in truffle tests
I have a contract that is written in solidity ^0.6.4 and has a simple implementation of reverting funds when someone directly transfers some eth or calls an unhandled function. Now it appears to be ...
2
votes
1
answer
504
views
What is the gas limit for a fallback function called when the method does not exist?
According to the docs a non matching function identifier will trigger the fallback function. So what happens if someone calls my contract with "thisMethodDoesntExist()", would the fallback ...
1
vote
1
answer
61
views
Do gas refunds apply in a fallback function? What is the limit for non matching function identifiers?
I know that a fallback function called with a .transfer only has gas limit of 2300. What happens if the fallback function deletes some storage variables in the fallback function? Would the fallback ...
0
votes
1
answer
3k
views
How should 'fallback' function be defined if we transact using 'call' method? [duplicate]
i came to know that 'call' method is better for transacting, since all gas is transferred and could withstand reentrancy attack.. but how should we define fallback function for 'call' method?
using ...