Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Handling of parameter name in expansion #454

Closed
jeromesimeon opened this issue Sep 17, 2018 · 1 comment
Closed

Handling of parameter name in expansion #454

jeromesimeon opened this issue Sep 17, 2018 · 1 comment
Assignees
Labels
Type: Bug 🐛 Something isn't working

Comments

@jeromesimeon
Copy link
Member

This is a critical compiler bug, Ergo expansion does not handle the name of parameters in clauses correctly.

This can be seen easily when executing a template in Cicero. For:

contract IOUContract over IOUContractModel {
  clause verify(request : IOURequest) : Response {
    // IOU-sepcific contraints
    enforce contract.lender != contract.borrower
      else throw ErgoErrorResponse{ message: "The lender and the borrower cannot be the same entity." };
    enforce request.value > 0.0
      else throw ErgoErrorResponse{ message: "The IOU's value must be non-negative." };

    return Response{}
  }
}

You get the expected result:

bash-3.2$ cicero execute 
11:15:39 - info: Using current directory as template folder
11:15:39 - info: Loading a default sample.txt file.
11:15:39 - info: Loading a single default request.json file.
11:15:39 - info: Loading a default state.json file.
11:15:40 - info: Compiling Ergo logic
11:15:40 - info:
{
  "clause": "corda-iou@0.0.0-b08d8a3de8d0e3836fb2fca95a287c081f5dfac0499151e5a51de1e4a3d7871c",
  "request": {
    "$class": "org.accordproject.sample.corda.iou.IOURequest",
    "value": 10
  },
  "response": {
    "$class": "org.accordproject.cicero.runtime.Response",
    "transactionId": "4106a771-4095-4ff2-b224-cf636402c8d1",
    "timestamp": "2018-09-17T15:15:40.611Z"
  },
  "state": {
    "$class": "org.accordproject.cicero.contract.AccordContractState",
    "stateId": "1"
  },
  "emit": []
}

But if you change the name of the parameter (e.g., from request to tx):

contract IOUContract over IOUContractModel {
  clause verify(tx : IOURequest) : Response {
    // IOU-sepcific contraints
    enforce contract.lender != contract.borrower
      else throw ErgoErrorResponse{ message: "The lender and the borrower cannot be the same entity." };
    enforce tx.value > 0.0
      else throw ErgoErrorResponse{ message: "The IOU's value must be non-negative." };

    return Response{}
  }
}

The compiler generates wrong code which does not execute properly:

bash-3.2$ cicero execute 
11:16:35 - info: Using current directory as template folder
11:16:35 - info: Loading a default sample.txt file.
11:16:35 - info: Loading a single default request.json file.
11:16:35 - info: Loading a default state.json file.
11:16:35 - info: Compiling Ergo logic
11:16:36 - error: undefined
11:16:36 - info: undefined
@jeromesimeon jeromesimeon added the Type: Bug 🐛 Something isn't working label Sep 17, 2018
@jeromesimeon jeromesimeon self-assigned this Sep 17, 2018
@jeromesimeon
Copy link
Member Author

Addressed in PR #455

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant