diff --git a/c/rce.h b/c/rce.h index 7a0980c..116dc67 100644 --- a/c/rce.h +++ b/c/rce.h @@ -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. diff --git a/c/simple_udt.c b/c/simple_udt.c index aa4c48b..ab9bfe3 100644 --- a/c/simple_udt.c +++ b/c/simple_udt.c @@ -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; @@ -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. diff --git a/c/xudt_rce.c b/c/xudt_rce.c index b1c0110..3aa319b 100644 --- a/c/xudt_rce.c +++ b/c/xudt_rce.c @@ -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.