8000 Add possibility for flexible did method type id for state contract and onchain issuer by Kolezhniuk · Pull Request #251 · iden3/contracts · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add possibility for flexible did method type id for state contract and onchain issuer #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Aug 16, 2024

Conversation

Kolezhniuk
Copy link
Contributor

No description provided.

Copy link

Pull Request Test Coverage Report for Build 10162198597

Details

  • 10 of 11 (90.91%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 86.405%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contracts/state/State.sol 5 6 83.33%
Totals Coverage Status
Change from base Build 9821943718: -0.2%
Covered Lines: 746
Relevant Lines: 803

💛 - Coveralls

* @dev getIdType
*/
function getIdType(uint256 id) internal pure returns (bytes2) {
return bytes2(PrimitiveTypeUtils.uint256ToBytes(PrimitiveTypeUtils.reverseUint256(id)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will test with some assembly function, maybe it can be done more gas efficient

vmidyllic
vmidyllic previously approved these changes Aug 5, 2024
vmidyllic
vmidyllic previously approved these changes Aug 5, 2024
) external {
require(depth <= IDENTITY_MAX_SMT_DEPTH, "SMT depth is greater than max allowed depth");
self.stateContract = IState(_stateContractAddr);
require(self.stateContract.isIdTypeSupported(idType), "id type doesn't exist");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be id type is not supported, because State contract doesn't know if it exists on other blockchains.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -145,7 +145,9 @@ contract State is Ownable2StepUpgradeable, IState {
bytes calldata methodParams
) public {
if (methodId == 1) {
uint256 calcId = GenesisUtils.calcIdFromEthAddress(getDefaultIdType(), msg.sender);
bytes2 idType = GenesisUtils.getIdType(id);
require(_stateData.isIdTypeSupported[idType], "id type is not supported");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to check if idType is supported in transitState function too.

Also you can put this check here before if (methodId == 1) {, because we may add more methods, but the check would be universal for all of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After moving this check before if (methodId == 1) - 59 tests is failing
Just double check should I fix this test or leave idTypeCheck inside if (methodId == 1)...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kolezhniuk that shouldn't happen. Probably tests use identities created with different idType, so you just need to add this idType to supported after the deployment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed tests

* @dev Set IdType setter
* @param idType id type
*/
function setIdType(bytes2 idType) public onlyOwner {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be renamed to let's say setIdTypeSupported with additional boolean param supported, so that we could disable support for some idType.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

Comment on lines 121 to 122
bytes2 idType = GenesisUtils.getIdType(id);
require(_stateData.isIdTypeSupported[idType], "id type is not supported");
Copy link
Contributor
@AndriianChestnykh AndriianChestnykh Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeatable code. Better to put it into some modifier or public method.
It's interesting BTW whether the isIdTypeSupported method will be used by clients with bytes2 idType parameter in reality. Maybe clients in most cases would extract type id from identifier before making the contract call. If that is the case uint256 id can be used instead. What do you think @vmidyllic, @OBrezhniev ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default type is fine, because onchain issuer during creation can't pass identifier but should check that id type is supported

Copy link
Member
@OBrezhniev OBrezhniev Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Vlad. Agree on modifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idType is used further in code, but I've added modifier also

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upd: moved this code to separate function

Comment on lines 157 to 158
bytes2 idType = GenesisUtils.getIdType(id);
require(_stateData.isIdTypeSupported[idType], "id type is not supported");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the modifier instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndriianChestnykh not sure that use modifier is reasonable here. In any case I need to calculate idType to use it below in the code. Why do I need calculate idType it twice?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, sorry I missed that

Comment on lines 157 to 158
bytes2 idType = GenesisUtils.getIdType(id);
require(_stateData.isIdTypeSupported[idType], "id type is not supported");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, sorry I missed that

vmidyllic
vmidyllic previously approved these changes Aug 8, 2024
}

/**
* @dev Set supported IdType setter
* @param idType id type
*/
function setIdTypeSupported(bytes2 idType) public onlyOwner {
_stateData.isIdTypeSupported[idType] = true;
function setSupportedIdType(bytes2 idType) public onlyOwner {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked for possibility to disable it too with a second param to the function.

@@ -170,7 +170,10 @@ contract CredentialAtomicQueryV3Validator is CredentialAtomicQueryValidatorBase
function _checkAuth(uint256 userID, address ethIdentityOwner) internal view {
require(
userID ==
GenesisUtils.calcIdFromEthAddress(getState().getDefaultIdType(), ethIdentityOwner),
GenesisUtils.calcIdFromEthAddress(
getState().checkSupportedIdTypeForId(userID),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better move getting of idType outside of the calcIdFromEthAddress.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

* @dev Check if the id type is supported and return the id type
* @param id Identity
*/
function checkSupportedIdTypeForId(uint256 id) public view returns (bytes2) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk, this function looks confusing to me. It's not modifier, but it does some checks, but also returns idType...
@AndriianChestnykh what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it's confusing. I would suggest use combination of getIdType and then isIdTypeSupported instead in any place (both from off-chain clients and inside smart contracts)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Folks, now we returning back to the code duplication issue that was mentioned in previous comments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, getIdTypeIfSupported(uint256 id) (which throws if not) is the best I can figure out now then.

vmidyllic
vmidyllic previously approved these changes Aug 9, 2024
*/
function setDefaultIdType(bytes2 defaultIdType) external onlyOwner {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need this function (setDefaultIdType) and we'll call it on polygon mainnet & amoy.

@vmidyllic vmidyllic merged commit b528b55 into master Aug 16, 2024
5 checks passed
@vmidyllic vmidyllic deleted the feature/flex-type-id branch August 16, 2024 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0