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

Fix/#82 restrict empty xudt or sudt cell creation #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions c/rce.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum ErrorCode {
ERROR_SCRIPT_TOO_LONG = -21,
ERROR_OVERFLOWING = -51,
ERROR_AMOUNT = -52,
ERROR_EMPTY_XUDT = -53,

// error code is starting from 40, to avoid conflict with
// common error code in other scripts.
Expand Down
5 changes: 5 additions & 0 deletions c/simple_udt.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define ERROR_SCRIPT_TOO_LONG -21
#define ERROR_OVERFLOWING -51
#define ERROR_AMOUNT -52
#define ERROR_EMPTY_SUDT -53

// We will leverage gcc's 128-bit integer extension here for number crunching.
typedef unsigned __int128 uint128_t;
Expand Down Expand Up @@ -179,6 +180,10 @@ int main() {
if (len < 16) {
return ERROR_ENCODING;
}
// disallow sudt cells with zero amount
if (current_amount == 0) {
return ERROR_EMPTY_SUDT;
}
output_amount += current_amount;
// Like any serious smart contract out there, we will need to check for
// overflows.
Expand Down
4 changes: 4 additions & 0 deletions c/xudt_rce.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ int simple_udt(int owner_mode) {
if (len < 16) {
return ERROR_ENCODING;
}
// disallow sudt cells with zero amount
if (current_amount == 0) {
return ERROR_EMPTY_XUDT;
}
output_amount += current_amount;
// Like any serious smart contract out there, we will need to check for
// overflows.
Expand Down