I'm using OpenZeppelin library for my project and I need to override some functions for business logic. But my concern is with given example,

// contract from library
contract A {
    function something_1() public { ... }
    function something_2() public { ... }

// contract made my me
contract B is A {
    function something_1() public  { ... }
    function something_2() private { ... }

outside contract A and B, is it possible for client,

  1. to call function something_1 from contract A?
  2. to call function somethong_2 from contract A?

What I'm trying to achieve is

  1. to restrict clients to call something_1 from contract A so clients can only call something_1 from contract B
  2. to permanently restrict clients calling function something_2 from contract A and B,
  • In the code you shared, there's no inheritance. And how can the client call the function from contract B if you've made it private? – user19510 May 2 '19 at 3:03
  • @smarx sorry, I fixed my question – xvnm May 2 '19 at 3:09
  • You can't override a public function with a private one. This is a compile-time error. (Your code won't compile.) – user19510 May 2 '19 at 3:15
  • @smarx yeah I just checked and it gives error you referred... that asides, then is it possible Q1? – xvnm May 2 '19 at 3:20

You can't change the visibility of an overridden function like that. The Solidity language doesn't allow it, so you'll have a compile-time error.

In my opinion, the best thing to do is just mark something_2 in contract A as internal or private. But if you insist on not touching contract A, you can override in B and just revert the transaction:

contract B {
    function something_2() public {
        revert("Not allowed.");

For your other question, if you deploy contract B and someone calls something_1(), they'll get the implementation from contract B. Of course, that implementation may call into the super implementation from contract A, but that's entirely up to you.

| improve this answer | |
  • thanks, I just wanted to know if an abuser can jump into overriden function that will critically break business logic. In this case, the abusing cannot happen right? – xvnm May 2 '19 at 3:25
  • Not if the Solidity compiler is doing what it's supposed to. – user19510 May 2 '19 at 3:33

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.