Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add NervosDAO as a CKB VM script #21

Merged
merged 9 commits into from
Jun 27, 2019
Merged

feat: Add NervosDAO as a CKB VM script #21

merged 9 commits into from
Jun 27, 2019

Conversation

xxuejie
Copy link
Collaborator

@xxuejie xxuejie commented Jun 21, 2019

TODO:

  • tests

@xxuejie
Copy link
Collaborator Author

xxuejie commented Jun 22, 2019

@doitian I'm running into a recursive dependency problem: in order to add tests for this repo, we need to update the main CKB repo since data structures are changed. However in order to update the main repo, we also need the updated contracts here, and since the main repo can only rely on published crates of ckb-system-scripts, we cannot do that either.

So as a result, what about we merge this PR first. I will finish the PR in the main repo, then we can go back and add missing DAO tests in this repo?

EDIT: we tried a different route: an RC version is first published to use in the CKB main repo PR, which can solve the problem.

@xxuejie xxuejie force-pushed the nervos-dao-script branch from 0005da6 to 137d76d Compare June 22, 2019 01:43
@xxuejie
Copy link
Collaborator Author

xxuejie commented Jun 22, 2019

Tests for NervosDAO are included here

unsigned char witness[WITNESS_SIZE];

len = WITNESS_SIZE;
ret = ckb_load_witness(witness, &len, 0, input_index, CKB_SOURCE_INPUT);
Copy link
Member

@doitian doitian Jun 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐞Check that len <= WITNESS_SIZE

Copy link
Member

@doitian doitian Jun 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️Review Information

Each withdraw consumes a former deposited cell as an input. The corresponding witnesses contain two arguments:

  • The first is intended to be consumed by the lock script to prove the user owns the cell.
  • The second one is a u64 encoded in little endian, it is the index into the transaction deps, which references an anchor header. We assume that the cell is withdraw from that anchor header. Transaction submitter should use the most recent block as the anchor header. The interest between anchor header to the block really commit the withdraw transaction is an implicit cost of the withdraw.

c/dao.c Show resolved Hide resolved
@doitian
Copy link
Member

doitian commented Jun 24, 2019

Could you please provide a brief description in the PR about:

  • What is stored in the field dao in the block header.
  • How a user deposits CKB into DAO and how to withdraw.

return ERROR_INVALID_WITHDRAW_BLOCK;
}

unsigned char deposit_dao[DAO_SIZE];
Copy link
Member

@doitian doitian Jun 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add a comment at the top of the script document everything.

c/dao.c Show resolved Hide resolved
c/dao.c Show resolved Hide resolved
unsigned char witness[WITNESS_SIZE];

len = WITNESS_SIZE;
ret = ckb_load_witness(witness, &len, 0, input_index, CKB_SOURCE_INPUT);
Copy link
Member

@doitian doitian Jun 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️Review Information

Each withdraw consumes a former deposited cell as an input. The corresponding witnesses contain two arguments:

  • The first is intended to be consumed by the lock script to prove the user owns the cell.
  • The second one is a u64 encoded in little endian, it is the index into the transaction deps, which references an anchor header. We assume that the cell is withdraw from that anchor header. Transaction submitter should use the most recent block as the anchor header. The interest between anchor header to the block really commit the withdraw transaction is an implicit cost of the withdraw.

c/dao.c Show resolved Hide resolved
c/dao.c Show resolved Hide resolved
}

uint64_t counted_capacity = 0;
if (__builtin_usubl_overflow(original_capacity, occupied_capacity,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️Review Information

Occupied capacity does not count when calculating interest.

dao_input = 1;
}
} else if (ret == CKB_ITEM_MISSING) {
/* DAO Issuing input here, we can just skip it */
Copy link
Member

@doitian doitian Jun 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️Review Information

Issuing input is a special OutPoint which is used as an indicator to tells the transaction verifier that the rule outputs total capacity <= inputs total capacity is handled in this script, dao.c.

https://github.com/nervosnetwork/ckb/blob/d470e5d804f3669d54ed53262a9a002d078a9984/core/src/transaction.rs#L162

Copy link
Member

@doitian doitian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes are marked with 🐞

@xxuejie xxuejie force-pushed the nervos-dao-script branch from be5317d to 14f4e3f Compare June 27, 2019 06:09
@xxuejie xxuejie requested a review from doitian June 27, 2019 06:09
@xxuejie xxuejie merged commit 66d7da8 into master Jun 27, 2019
@xxuejie xxuejie deleted the nervos-dao-script branch June 27, 2019 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants