0

can I add a modifier (for ex: onlyOwner) to a mapping? only I must see the value of mapping's key by myself(onlyowner).

For example: mapping (address => bool) onlyOwner getAddress;

Thank you.

  • No, you cant. Everybody can (and should be able to) see the data on the blockchain, that's actually part of the whole idea (would you ever sign a contract without seeing the details?). – goodvibration Mar 27 at 16:04
0

It's actually part of a broader concern.

You can put access control on a read-only function, but an adversary will:

  1. Have all of your code
  2. Have all of the data

Therefore, an adversary will get around any notion of confidentiality you construct. private doesn't change that. The most you can do is inconvenience a determined adversary.

Since it is transparent in any case, I generally advise against any restrictions on read-only functions and, in fact, incline to completely discoverable states.

Confidential information just won't exist in a contract state because it shouldn't be there.

Hope it helps.

| improve this answer | |
  • thank you Rob, I see. you're right :) – sollover Mar 28 at 10:13

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.