Skip to content

Commit

Permalink
Add ContractCodeCostInputs and new cost types (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon authored Mar 22, 2024
1 parent df96ebc commit fbc5373
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
44 changes: 43 additions & 1 deletion Stellar-contract-config-setting.x
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,49 @@ enum ContractCostType {
// Cost of int256 shift (`shl`, `shr`) operation
Int256Shift = 21,
// Cost of drawing random bytes using a ChaCha20 PRNG
ChaCha20DrawBytes = 22
ChaCha20DrawBytes = 22,

// Cost of parsing wasm bytes that only encode instructions.
ParseWasmInstructions = 23,
// Cost of parsing a known number of wasm functions.
ParseWasmFunctions = 24,
// Cost of parsing a known number of wasm globals.
ParseWasmGlobals = 25,
// Cost of parsing a known number of wasm table entries.
ParseWasmTableEntries = 26,
// Cost of parsing a known number of wasm types.
ParseWasmTypes = 27,
// Cost of parsing a known number of wasm data segments.
ParseWasmDataSegments = 28,
// Cost of parsing a known number of wasm element segments.
ParseWasmElemSegments = 29,
// Cost of parsing a known number of wasm imports.
ParseWasmImports = 30,
// Cost of parsing a known number of wasm exports.
ParseWasmExports = 31,
// Cost of parsing a known number of data segment bytes.
ParseWasmDataSegmentBytes = 32,

// Cost of instantiating wasm bytes that only encode instructions.
InstantiateWasmInstructions = 33,
// Cost of instantiating a known number of wasm functions.
InstantiateWasmFunctions = 34,
// Cost of instantiating a known number of wasm globals.
InstantiateWasmGlobals = 35,
// Cost of instantiating a known number of wasm table entries.
InstantiateWasmTableEntries = 36,
// Cost of instantiating a known number of wasm types.
InstantiateWasmTypes = 37,
// Cost of instantiating a known number of wasm data segments.
InstantiateWasmDataSegments = 38,
// Cost of instantiating a known number of wasm element segments.
InstantiateWasmElemSegments = 39,
// Cost of instantiating a known number of wasm imports.
InstantiateWasmImports = 40,
// Cost of instantiating a known number of wasm exports.
InstantiateWasmExports = 41,
// Cost of instantiating a known number of data segment bytes.
InstantiateWasmDataSegmentBytes = 42
};

struct ContractCostParamEntry {
Expand Down
26 changes: 25 additions & 1 deletion Stellar-ledger-entries.x
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,32 @@ struct ContractDataEntry {
SCVal val;
};

struct ContractCodeEntry {
struct ContractCodeCostInputs {
ExtensionPoint ext;
uint32 nInstructions;
uint32 nFunctions;
uint32 nGlobals;
uint32 nTableEntries;
uint32 nTypes;
uint32 nDataSegments;
uint32 nElemSegments;
uint32 nImports;
uint32 nExports;
uint32 nDataSegmentBytes;
};

struct ContractCodeEntry {
union switch (int v)
{
case 0:
void;
case 1:
struct
{
ExtensionPoint ext;
ContractCodeCostInputs costInputs;
} v1;
} ext;

Hash hash;
opaque code<>;
Expand Down

0 comments on commit fbc5373

Please sign in to comment.