From 2a76ef85702ba52da635b8057b8105ff684a9d2d Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Sun, 20 Nov 2022 13:08:29 -0800 Subject: [PATCH 1/3] Replace BigInt object with {iu}128 --- Stellar-contract.x | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/Stellar-contract.x b/Stellar-contract.x index d7f34b4..4dadc99 100644 --- a/Stellar-contract.x +++ b/Stellar-contract.x @@ -213,10 +213,11 @@ enum SCObjectType SCO_MAP = 1, SCO_U64 = 2, SCO_I64 = 3, - SCO_BYTES = 4, - SCO_BIG_INT = 5, - SCO_CONTRACT_CODE = 6, - SCO_ACCOUNT_ID = 7 + SCO_U128 = 4, + SCO_I128 = 5, + SCO_BYTES = 6, + SCO_CONTRACT_CODE = 7, + SCO_ACCOUNT_ID = 8 // TODO: add more }; @@ -232,22 +233,6 @@ const SCVAL_LIMIT = 256000; typedef SCVal SCVec; typedef SCMapEntry SCMap; -enum SCNumSign -{ - NEGATIVE = -1, - ZERO = 0, - POSITIVE = 1 -}; - -union SCBigInt switch (SCNumSign sign) -{ -case ZERO: - void; -case POSITIVE: -case NEGATIVE: - opaque magnitude<256000>; -}; - enum SCContractCodeType { SCCONTRACT_CODE_WASM_REF = 0, @@ -262,6 +247,14 @@ case SCCONTRACT_CODE_TOKEN: void; }; +struct Int128Parts { + // Both signed and unsigned 128-bit ints + // are transported in a pair of uint64s + // to reduce the risk of sign-extension. + uint64 lo; + uint64 hi; +}; + union SCObject switch (SCObjectType type) { case SCO_VEC: @@ -272,10 +265,12 @@ case SCO_U64: uint64 u64; case SCO_I64: int64 i64; +case SCO_U128: + Int128Parts u128; +case SCO_I128: + Int128Parts i128; case SCO_BYTES: opaque bin; -case SCO_BIG_INT: - SCBigInt bigInt; case SCO_CONTRACT_CODE: SCContractCode contractCode; case SCO_ACCOUNT_ID: From 50a7c9008178ac9dd8fec5a11e86742856f610f7 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Sun, 20 Nov 2022 15:19:58 -0800 Subject: [PATCH 2/3] Try fixing automation --- .github/workflows/check.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 3ed265c..99fb6f0 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -4,11 +4,11 @@ name: CI # Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the "main" branch + # Triggers the workflow on push or pull request events for main, curr or next. push: - branches: [ "main" ] + branches: [ "main", "curr", "next" ] pull_request: - branches: [ "main" ] + branches: [ "main", "curr", "next" ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: From e200763e88c147e2ac4b3bc1c6076c4bbc35af81 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Sun, 20 Nov 2022 15:27:10 -0800 Subject: [PATCH 3/3] Migrate SC_SPEC from BIG_INT to {IU}128 --- Stellar-contract-spec.x | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Stellar-contract-spec.x b/Stellar-contract-spec.x index 2e18755..31ce93d 100644 --- a/Stellar-contract-spec.x +++ b/Stellar-contract-spec.x @@ -19,14 +19,15 @@ enum SCSpecType SC_SPEC_TYPE_I32 = 2, SC_SPEC_TYPE_U64 = 3, SC_SPEC_TYPE_I64 = 4, - SC_SPEC_TYPE_BOOL = 5, - SC_SPEC_TYPE_SYMBOL = 6, - SC_SPEC_TYPE_BITSET = 7, - SC_SPEC_TYPE_STATUS = 8, - SC_SPEC_TYPE_BYTES = 9, - SC_SPEC_TYPE_BIG_INT = 10, - SC_SPEC_TYPE_INVOKER = 11, - SC_SPEC_TYPE_ACCOUNT_ID = 12, + SC_SPEC_TYPE_U128 = 5, + SC_SPEC_TYPE_I128 = 6, + SC_SPEC_TYPE_BOOL = 7, + SC_SPEC_TYPE_SYMBOL = 8, + SC_SPEC_TYPE_BITSET = 9, + SC_SPEC_TYPE_STATUS = 10, + SC_SPEC_TYPE_BYTES = 11, + SC_SPEC_TYPE_INVOKER = 12, + SC_SPEC_TYPE_ACCOUNT_ID = 13, // Types with parameters. SC_SPEC_TYPE_OPTION = 1000, @@ -88,6 +89,8 @@ union SCSpecTypeDef switch (SCSpecType type) case SC_SPEC_TYPE_VAL: case SC_SPEC_TYPE_U64: case SC_SPEC_TYPE_I64: +case SC_SPEC_TYPE_U128: +case SC_SPEC_TYPE_I128: case SC_SPEC_TYPE_U32: case SC_SPEC_TYPE_I32: case SC_SPEC_TYPE_BOOL: @@ -95,7 +98,6 @@ case SC_SPEC_TYPE_SYMBOL: case SC_SPEC_TYPE_BITSET: case SC_SPEC_TYPE_STATUS: case SC_SPEC_TYPE_BYTES: -case SC_SPEC_TYPE_BIG_INT: case SC_SPEC_TYPE_INVOKER: case SC_SPEC_TYPE_ACCOUNT_ID: void;