Giter VIP home page Giter VIP logo

accordproject / ergo Goto Github PK

View Code? Open in Web Editor NEW
156.0 156.0 55.0 88.79 MB

Programming Language for Smart Legal Contracts

Home Page: https://accordproject.org/projects/ergo

License: Apache License 2.0

Makefile 1.16% JavaScript 26.53% Coq 47.52% OCaml 10.57% Shell 0.12% HTML 0.36% Java 3.03% Gherkin 3.35% Emacs Lisp 4.70% Handlebars 0.01% Standard ML 2.50% Vim Script 0.16%
accord-project blockchain corda digital-asset ergo ergo-compiler ethereum hacktoberfest hyperledger javascript language legal legal-engineering legaltech smart-contracts tezos verification

ergo's People

Contributors

algomaster99 avatar alvesgabriel avatar aniruddha-shriwant avatar arshadkazmi42 avatar daniloff200 avatar dependabot[bot] avatar dselman avatar gargarchit avatar harsh1206 avatar irmerk avatar jbesq777 avatar jeromesimeon avatar kach avatar kewbish avatar martinhalford avatar michizhou avatar mttrbrts avatar parikshit-hooda avatar peterhunn avatar petrgazarov avatar sidhyatikku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ergo's Issues

Client-side Ergo

We should have a way to embed Ergo in the browser. This would be a better way to implement #5 as well.

Remove scaffolding for calculus/sexp

Initial work using sexpressions to show case the intermediate calculus aren't tested or used anymore. They should probably be removed now that there is a full parser for Ergo.

Separate statements from expressions

It might be cleaner/better to introduce a distinction between statements and expressions to more clearly isolate the part of the Ergo logic that can affect state (e.g., change contract state, return an error, emit a transaction).

This could also facilitate code generation by more clearly isolating the purely functional part from the state change part of the logic.

Here is a possible beginning for a statement grammar:

statement ::=
| statement ; statement   // sequence
| define variable Var (: Type)? := expression; statement
| if expression then statement (else statement)?
| enforce expression (else statement)?; statement
| return expression
| reject expression
| emit expression
| set state expression
...

Support for instanceof

It would be great to be able to match values against types. This could be a new operator in the language e.g., e instanceof T or e is of type T.

This could also be used for the underlying semantics of define variable x : T := e.

I believe instanceof can be supported as an operator and compiled to an underlying combination of data-type inference and sub typing (See querycert/qcert#95).

Additionally, this might allow us to consolidate the pattern matching expression, which currently only works for either class names or values, and from there to generalize the type dispatch implemented for #15

Align syntax for match and conditionals

We are currently using:
if e1 { e2 } else { e3 } and match e1 with e2 : e3 ... otherwise en

We might want to consolidate and remove the curly braces in the conditional as follows:
if e1 then e2 else e3 and match e1 with e2 then ... else en

This also removes one overloading for the : character (see #28).

Support for records

It would be useful to allow record values and types (similar to JSON objects). Those could also be interpreted as anonymous CTO concept. Those would most naturally be written in a way similar to JSON as:

{ name : "John", age : 32 }

Note that in contract concepts are created with their concept names as follows:

new Person{ name : "John", age : 32 }

Prose examples to illustrate Ergo Syntax

The documentation should include some example legal text to help illustrate the Ergo Syntax.
Particularly for:

  • Conditional expressions
  • Enforce expressions
  • Match expressions

CTO Import

Currently, the Jura compiler does not import CTO model files. Those are needed for: syntactic sugar (e.g., new Asset{ value1, value2 } instead of new Asset{ field1: value1, field2: value2 }, type checking, optimization, etc.

Limit overloading of semantics for ':'

The character : is used in multiple places at the moment (for indicating a type in a function signature or variable declaration, for object/record construction, and in the match expression. We could use then .. else in the match expression to limit the amount of overloading for the : character.

Add missing datatypes

The Jura documentation lists all CTO datatypes should be available. Those include:

Boolean
String
Double
Long
Integer
DateTime

Namespace handling

Some review/consolidation of the namespace handling in Ergo should happen. The top-level package declaration indicates a namespace for the given Ergo file. The namespace needs to be properly taken into account in type declarations, function/clause calls, etc.

Reimplement all the Cicero templates

The Ergo language should be validated against the existing Cicero templates (https://github.com/accordproject/cicero-template-library):

  • acceptance-of-delivery
  • car-rental-tr
  • copyright-license
  • demandforecast
  • eat-apples
  • fragile-goods
  • helloworld
  • helloworldstate
  • installment-sale
  • ip-payment
  • latedeliveryandpenalty
  • one-time-payment
  • one-time-payment-tr
  • payment-upon-delivery
  • perishable-goods
  • promissory-note
  • saft
  • safte
  • sales-contract-ru
  • servicelevelaggreement
  • supplyagreement
  • supplyagreement-perishable-goods
  • volumediscount

Refactor backend module instantiation

It might be necessary/cleaner to instantiate the Q*cert modules for code generation before they are used in Ergo. This would freeze foreign types (e.g., for date/time) which means constructing type models is more natural. This concretely means:

  • Split the Compiler directory into pre-Jura Backend and post-Ergo ErgoCompiler parts
  • Import the Backend instead of Qcert in the Ergo part of the code
  • Re-factor the built-in operators, CTO to model translation, etc to rely on the instantiated backend compiler
  • Fix up of backend module types and definitions so it results in cleaner extracted code

Syntax for guard expressions

The world seems united in its dislike of guard as a keyword. Also now that conditional and match statements do not use curly braces, the guard expression should avoid those as well. A possible alternative to:
guard e1 else { e2 }; and guard e1;
might be:
ensure e1 else e2; and ensure e1;

Ergo Language Documentation

We should have documentation for the language, this should include: compiler documentation, programming model, syntax/grammar documentation, expression language, semantics, typing constraints.

Document reserved words

The list of reserved words (language used by the language such as contract, function, etc that can't be identifiers) should be documented.

Add support for relationships

Ergo needs to be able to access/create relationships between concepts (relationships in the sense of the CTO). The acceptance of delivery template provides a simple example of that.

Integration with Cicero

The jura CLI uses it's own execution code. We need to test the generated JavaScript and possibly adjust the code-generation so it can run from within Cicero.

Full handling for type name hierarchy

Type name hierarchy is not yet handled properly. This is relevant for code generation, the reference interpreter, and of course for type checking.

Requires some of the following steps:

  • Import of CTO files (See #9)
  • Namespace resolution (See #18)
  • Uniform handling of CTOs and type declaration in module (done in PR #234)
  • Extract type hierarchy from ergo modules after namespace resolution (See #330)
  • Pass type hierarchy to backend compiler calls
  • Add code-generation for type hierarchy

Incorrect signature types in compiled JsDoc annotations

Comparing original JS latedeliveryandpenalty sample with compiled JS from Ergo I see the following difference.

JS sample

/**
 * Execute the smart clause
 * @param {Context} context - the Accord Project context
 * @param {io.clause.latedeliveryandpenalty.LateDeliveryAndPenaltyRequest} context.request - the incoming request
 * @param {io.clause.latedeliveryandpenalty.LateDeliveryAndPenaltyResponse} context.response - the response
 * @AccordClauseLogic
 */

Compiled Jura

/**
 * Execute the smart clause
 * @param {Context} context - the Accord Project context
 * @param {Request} context.request - the incoming request
 * @param {Response} context.response - the response
 * @AccordClauseLogic
 */

I suspect that the missing namespaces are related to #18 , but the type names also seem to be wrong.

Ergo reference interpreter

There should be a way to execute Ergo contracts without full compilation to get the "official" semantics.

Avoid duplication in tests

Currently each package has sets of Jura tests in ./test/data. There is a lot of duplication, which should be avoided, maybe by each package linking to a single top-level directory.

Add CI for the build-from-source process

Currently CI with Travis only tests Jura after extraction to JavaScript. We should have a separate build for testing compilation of the Jura compiler from its Coq/OCaml source code.

Distinguish Ergo compiler from CLI

It would be better to provide independent executables for the compiler and the CLI. The CLI might be possibly replaced by a REPL or that might be yet another executable. (See also #25).

One of the benefit of having the compiler separate is that it could include more compilation options, distinct compilation targets down the road, etc.

This might also serve to address #13

Improve error messages

Notably:

  • Parsing errors should be reported with a reference to the file rather than a "code dump"
  • Compilation errors should be reported with a more useful message.
  • Compilation errors should not be lost when calling execute.

Generalize production of Ergo runtime

The Ergo runtime is a patched-up version of the Q*cert one. It is composed of vanilla JavaScript functions without module layout for node consumption. We should improve upon this in several ways:

  • Automate the production of the runtime from Q*cert itself so changes/fixes there are propagated to Ergo automatically
  • Allow the runtime generation to be parameterized by foreign type libraries (e.g., various support for dateTime)
  • Generalize the runtime generation so it works for both browser and node

Type Checking for Ergo

We need a type checker for Ergo and/or the Ergo Calculus. It should be based on the CTOs being imported in the Ergo contracts, it should provide correctness guarantees, it should provide useful information to the editor, it should return useful errors to the Ergo developer.

REPL for Ergo

We should provide a read-eval-print-loop for Ergo. This is useful for learning the language.

Support execution with transaction type-based dispatch

Currently, execution for clauses requires the user to specify the contract and clause. It would be useful to allow execution to be driven by the type of the incoming transaction (typically the clause request). The execution could match the incoming transaction type against the type signature of clauses.

This is also a useful item for integration with Cicero (#8), since Cicero already uses a form of dispatch.

Automated testing

We should have automated testing for Jura contract compilation and execution.

Perform inline expansion on Ergo as a separate phase

Inline expansion is the main source of compiler error (e.g., calling a function that isn't in scope or hasn't been declared). It would make the compiler code simpler and easier to debug if it was performed as a first step before translation to calculus.

Ergo Playground

There should be a way to try/learn/experiment with Ergo online (using a kind of a playground).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.