-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And & Not decider implementation (#375)
* And & Not decider implementation * Added directory for quantifiers to group them together
- Loading branch information
1 parent
4ae5caa
commit 6966be7
Showing
15 changed files
with
613 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
Decider, | ||
Decision, | ||
ImplicationProofItem, | ||
Property, | ||
} from '../../../types/ovm' | ||
|
||
export interface AndDeciderInput { | ||
left: Property | ||
leftWitness: any | ||
right: Property | ||
rightWitness: any | ||
} | ||
|
||
/** | ||
* Decider that decides true iff both of the provided properties evaluate to true. | ||
*/ | ||
export class AndDecider implements Decider { | ||
public async decide( | ||
input: AndDeciderInput, | ||
witness: undefined | ||
): Promise<Decision> { | ||
const [leftDecision, rightDecision] = await Promise.all([ | ||
input.left.decider.decide(input.left.input, input.leftWitness), | ||
input.right.decider.decide(input.right.input, input.rightWitness), | ||
]) | ||
|
||
if (!leftDecision.outcome) { | ||
return this.getDecision(input, leftDecision) | ||
} | ||
if (!rightDecision.outcome) { | ||
return this.getDecision(input, rightDecision) | ||
} | ||
|
||
const justification: ImplicationProofItem[] = [] | ||
if (!!leftDecision.justification.length) { | ||
justification.push(...leftDecision.justification) | ||
} | ||
if (!!rightDecision.justification.length) { | ||
justification.push(...rightDecision.justification) | ||
} | ||
|
||
return this.getDecision(input, { outcome: true, justification }) | ||
} | ||
|
||
public async checkDecision(input: AndDeciderInput): Promise<Decision> { | ||
return this.decide(input, undefined) | ||
} | ||
|
||
/** | ||
* Gets the Decision that results from invocation of the And decider, which simply | ||
* returns true if both sub-Decisions returned true. | ||
* | ||
* @param input The input that led to the Decision | ||
* @param subDecision The decision of the wrapped Property, provided the witness | ||
* @returns The Decision | ||
*/ | ||
private getDecision(input: AndDeciderInput, subDecision: Decision): Decision { | ||
const justification: ImplicationProofItem[] = [ | ||
{ | ||
implication: { | ||
decider: this, | ||
input, | ||
}, | ||
implicationWitness: undefined, | ||
}, | ||
...subDecision.justification, | ||
] | ||
|
||
return { | ||
outcome: subDecision.outcome, | ||
justification, | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/core/src/app/ovm/deciders/hash-preimage-existence-decider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './and-decider' | ||
export * from './hash-preimage-existence-decider' | ||
export * from './key-value-store-decider' | ||
export * from './not-decider' | ||
export * from './utils' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
Decider, | ||
Decision, | ||
ImplicationProofItem, | ||
Property, | ||
} from '../../../types/ovm' | ||
|
||
export interface NotDeciderInput { | ||
property: Property | ||
witness: any | ||
} | ||
|
||
/** | ||
* Decider that decides true iff the provided property evaluates to false. | ||
*/ | ||
export class NotDecider implements Decider { | ||
public async decide( | ||
input: NotDeciderInput, | ||
witness: undefined | ||
): Promise<Decision> { | ||
const decision: Decision = await input.property.decider.decide( | ||
input.property.input, | ||
input.witness | ||
) | ||
|
||
return this.getDecision(input, decision) | ||
} | ||
|
||
public async checkDecision(input: NotDeciderInput): Promise<Decision> { | ||
return this.decide(input, undefined) | ||
} | ||
|
||
/** | ||
* Gets the Decision that results from invocation of the Not decider, which simply | ||
* returns the opposite outcome than the provided Decision. | ||
* | ||
* @param input The input that led to the Decision | ||
* @param subDecision The decision of the wrapped Property, provided the witness | ||
* @returns The Decision. | ||
*/ | ||
private getDecision(input: NotDeciderInput, subDecision: Decision): Decision { | ||
const justification: ImplicationProofItem[] = [ | ||
{ | ||
implication: { | ||
decider: this, | ||
input, | ||
}, | ||
implicationWitness: undefined, | ||
}, | ||
...subDecision.justification, | ||
] | ||
|
||
return { | ||
outcome: !subDecision.outcome, | ||
justification, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './deciders' | ||
export * from './quantifiers' | ||
export * from './state-db' | ||
export * from './state-manager' | ||
export * from './integer-quantifiers' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './integer-quantifiers' |
2 changes: 1 addition & 1 deletion
2
...s/core/src/app/ovm/integer-quantifiers.ts → ...pp/ovm/quantifiers/integer-quantifiers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from './state-manager.interface' | ||
export * from './state-db.interface' | ||
export * from './decider.interface' | ||
export * from './predicate-plugin.interface' | ||
export * from './plugin-manager.interface' | ||
export * from './sync-manager' | ||
export * from './quantifier.interface' | ||
export * from './state-db.interface' | ||
export * from './state-manager.interface' | ||
export * from './sync-manager' |
Oops, something went wrong.