Provide a modifier to prevent calling from another contract.
See original GitHub issueš§ Motivation
A lots of contract security issues need to be exploited by calling from another contract, so we often protect our contract by preventing contract calling some critical functions.
š Details
We can provide a modifier to do this check, although address.code.length == 0
do the same effect, that cost more gas.
modifier callerIsUser() {
require(tx.origin == msg.sender, 'The caller is another contract.');
_;
}
function mint() public callerIsUser {
...
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How can you call a function with a modifier in another contract?
I am getting an error Error: Undeclared identifier: getModified for getModified in Remix. I tried reading the docs but they also dont mentionĀ ......
Read more >Solidity Tutorial: all about Modifiers | by Jean Cvllr | Coinmonks
In Solidity, Modifiers express what actions are occurring in a declarative ... As a result, this prevent other smart contracts to call theĀ ......
Read more >Access Restriction | solidity-patterns - GitHub Pages
This is a good example for the various possibilities modifiers can provide. Combined with the previous modifier the contract can only be bought...
Read more >Solidity: call modifiers from other smart contracts
My current workaround is the following: - In my token smart contract, I added an "intermediate" function. That function is directly calledĀ ...
Read more >Contracts ā Solidity 0.8.17 documentation
Calling a function on a different contract (instance) will perform an EVM function call and ... but the latter provides an external view...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Some users donāt use EOA. They use Argent, Gnosis, or any other smart-contract-based wallets. By forcing
tx.origin == msg.sender
you are preventing these users for interacting with you. I would not call that fair.I am yet to see a case where using such a modifier was really needed. All usages Iāve seen so far were trying to mitigate ābadā design decisions.
I got your points now, thanks @Amxx @frangio I might use
tx.origin == msg.sender
to exclude contract user or even real smart wallet users sometimes, for example in some case Iāll just use block.timestamp as random seed instead of VRF which is expensive. But I understand your concern for including such a modifier in library.