Skip to content

Commit

Permalink
fix: avoid error
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiagarms committed Sep 13, 2024
1 parent 5d07a64 commit baf0ab5
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/traverse/MappingKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ export default class MappingKey {
this.isNullified = false;
this.nullificationCount = 0;
this.nullifyingPaths = []; // array of paths of `Identifier` nodes which nullify this binding
;
if (this.keyPath.node.typeDescriptions?.typeString === 'address') {
this.updateOwnership(this.keyPath);
}
}

addStructProperty(referencingPath: NodePath): MappingKey {
Expand Down Expand Up @@ -173,15 +169,18 @@ export default class MappingKey {
}

updateOwnership(ownerNode: any) {
// if the mapping key is an address the owner is always the address itself, even if the owner is set elsewhere.
if (this.keyPath.node.typeDescriptions?.typeString === 'address') {
//We need to check if the owner node is msg.sender - if it is then we need to set the owner to the mapping key
if (this.container.owner.mappingOwnershipType === 'key'){
if (this.isOwned){
return;
} else{
} else {
this.isOwned =true;
this.owner = this.keyPath;
this.owner = this.keyPath.node;
this.owner.mappingOwnershipType = 'key';
return;
}
};
}
if (this.isOwned && this.owner.mappingOwnershipType === 'key') return;
if (this.isOwned && this.owner.name !== ownerNode.name) {
throw new ZKPError(
`We found two distinct owners (${this.owner.name} and ${ownerNode.name}) of a secret state, which we can't allow because only one public key needs to be able to open/nullify the secret.`,
Expand Down Expand Up @@ -367,9 +366,17 @@ export default class MappingKey {
this.isPartitionedReason = this.isPartitioned
? container.isPartitionedReason
: this.isPartitionedReason;
const mappingKeys: [string, MappingKey][] = Object.entries(container.mappingKeys);
for (const [, mappingKey] of mappingKeys) {
if (mappingKey.name === this.name){
this.isOwned = mappingKey.isOwned;
this.owner = mappingKey.owner;
this.mappingOwnershipType = mappingKey.mappingOwnershipType;
}
}
this.isOwned ??= container.isOwned;
this.owner ??= container.owner;
this.mappingOwnershipType = this.owner?.mappingOwnershipType;
this.mappingOwnershipType ??= this.owner?.mappingOwnershipType;
this.onChainKeyRegistry ??= container.onChainKeyRegistry;
}
}

0 comments on commit baf0ab5

Please sign in to comment.