Skip to content

Commit

Permalink
fix: simpler fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiagarms committed Sep 13, 2024
1 parent 6f33332 commit e308e92
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,7 @@ export const preimageBoilerPlate = (node: any) => {
default:
// TODO - this is the case where the owner is an admin (state var)
// we have to let the user submit the key and check it in the contract
if (stateNode.mappingOwnershipType === 'key') {
newOwnerStatment = `generalise(await instance.methods.zkpPublicKeys(${newOwner}.hex(20)).call()); // address should be registered`;
}
else if (!stateNode.ownerIsSecret && !stateNode.ownerIsParam) {
if (!stateNode.ownerIsSecret && !stateNode.ownerIsParam) {
newOwnerStatment = `_${privateStateName}_newOwnerPublicKey === 0 ? generalise(await instance.methods.zkpPublicKeys(await instance.methods.${newOwner}().call()).call()) : ${privateStateName}_newOwnerPublicKey;`;
} else if (stateNode.ownerIsParam && newOwner) {
newOwnerStatment = `_${privateStateName}_newOwnerPublicKey === 0 ? ${newOwner} : ${privateStateName}_newOwnerPublicKey;`;
Expand Down
25 changes: 14 additions & 11 deletions src/traverse/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export class VariableBinding extends Binding {
}

updateOwnership(ownerNode: any, msgIsMappingKeyorMappingValue?: string | null) {
if (this.isOwned && this.owner.mappingOwnershipType === 'key') return;
if (
ownerNode.expression?.name === 'msg' &&
msgIsMappingKeyorMappingValue === 'value'
Expand Down Expand Up @@ -524,16 +525,6 @@ export class VariableBinding extends Binding {
let msgSenderEverywhereMappingKey: boolean;
let msgSenderEverywhereMappingValue: boolean;
this.nullifyingPaths.forEach(path => {
const functionDefScope = path.scope.getAncestorOfScopeType(
'FunctionDefinition',
);
if (functionDefScope.callerRestriction === 'match') {
this.updateOwnership(functionDefScope.callerRestrictionNode);
return;
}
if (functionDefScope.callerRestriction === 'exclude') {
this.updateBlacklist(functionDefScope.callerRestrictionNode);
}
if (this.isMapping && path.getAncestorOfType('IndexAccess') && this.addMappingKey(path).isMsgSender ) {
// if its unassigned, we assign true
// if its true, it remains true
Expand Down Expand Up @@ -562,7 +553,19 @@ export class VariableBinding extends Binding {
this.nullifyingPaths[0].parent.rightHandSide ||
this.nullifyingPaths[0].parentPath.parent.rightHandSide;
this.updateOwnership(owner, 'value');
}
}
this.nullifyingPaths.forEach(path => {
const functionDefScope = path.scope.getAncestorOfScopeType(
'FunctionDefinition',
);
if (functionDefScope.callerRestriction === 'match') {
this.updateOwnership(functionDefScope.callerRestrictionNode);
return;
}
if (functionDefScope.callerRestriction === 'exclude') {
this.updateBlacklist(functionDefScope.callerRestrictionNode);
}
});
}

ownerSetToZeroCheck() {
Expand Down
19 changes: 1 addition & 18 deletions src/traverse/MappingKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,6 @@ export default class MappingKey {
}

updateOwnership(ownerNode: any) {
//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'){
this.isOwned =true;
this.owner = this.keyPath.node;
this.owner.mappingOwnershipType = 'key';
this.owner.isParam = this.keyPath.isFunctionParameter();
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 @@ -363,17 +354,9 @@ 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 e308e92

Please sign in to comment.