Skip to content

Commit

Permalink
Next into curr (#147)
Browse files Browse the repository at this point in the history
* Initial commit

* Create check.yml (#2)

Defines the 'complete' status check.

* populate (#1)

* Incorporate CAP-42 changes (#3)

* Pick up Stellar-internal.x (#4)

* add .gitignore (#5)

* Absorb changes from rs-stellar-xdr repo (#7)

* Flatten contract spec discriminants (#8)

* Namespace the contract spec types (#9)

* Delete Stellar-contract-meta.x (#12)

* CAP-0047 - update names (#6)

* Fix contract spec definitions after rename (#13)

* Add contract meta types (#10)

* Rename BINARY to BYTES (#16)

* Add SCContractCode and update related types (#17)

* Add names to function inputs in contract spec (#18)

* Pick up persistent state changes (#19)

* Fix repeated errorCode in SCStatus (#20)

* Pick up changes incorrectly committed to rs-stellar-xdr (#21)

* Add rest of CAP-0056 (#22)

* Add BytesN as type (#23)

* Add Val as a spec type (#25)

* Add name of lib to struct and union spec entries (#26)

* Add adverts & demands to StellarMessage (#24)

* Add SST_CONTRACT_ERROR to SCStatusType (#29)

* Remove `ScHash` and `PublicKey` from object type. (#31)

* Add enum as a contract spec type (#34)

* Add error enum as a distinct UDT type from enum (#35)

* Add SCVal success to INVOKE_HOST_FUNCTION_SUCCESS, fix stellar/stellar-protocol#1307 (#36)

* Updated xdr for token wrapper and source auth (#37)

* add ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET

* add new HostFunction type and HashIDPreimage for using the source account in the host

* add missing enum value (#38)

* rename HOST_FN_CREATE_CONTRACT (#39)

* Add invoker to contract spec (#40)

* Add account id as object type (#41)

* Rename HOST_FN_CREATE_CONTRACT_WITH_SOURCE to HOST_FN_CREATE_CONTRACT_WITH_SOURCE_ACCOUNT (#42)

* Rename ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE to ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT (#43)

* Rename sourceContractID to sourceAccountContractID (#44)

* Add AccountID as type to contract spec (#45)

* move AccountID to avoid circular reference (#46)

* Add new host functions to xdr (#47)

* Add new host functions to xdr

* rename

* Trivial whitespace changes to Stellar-overlay.x to sync with curr (#50)

* XDR side of the contract deployment changes specified in CAP-46-02. (#51)

* XDR side of the contract deployment changes specified in CAP-46-02.

This introduces the ledger entries to store the wasm code and also changes the host functions to support creating/installing the contracts.

* Remove option to create and install contract in the same operation.

This relies on the ability to include multiple Soroban operations in the transaction. We can bring this back if we decide against that.

* Replace BigInt object with {iu}128 (#57)

* Bigint to int128 cont'd -- spec changes (#58)

* Migrate SC_SPEC from BIG_INT to {IU}128

* Make events a list of lists so we can associate events with their operation (#59)

* Make events a list of lists so we can associate events with their operation

* Add a OperationEvents struct

* Update overlay XDR (#62)

* XDR changes for Auth Next. (#65)

- Introduce the `ScAddress` type to generically represent the address in contracts
- Introduce structured authorization data and structured signature payload to use for auth in contracts

* Add fields for docs to the contract spec (#66)

* Make unit/void case explicit and support more tuples in union spec (#67)

* Make unit/void case explicit and support more tuples in union spec

* avoid void

* Fix syntax (#68)

* Add auth errors (#69)

* Add auth errors

* fixup! Add auth errors

* Add nonce to the signature payload (#71)

* Preliminary "remove objects from XDR" change (#70)

* Add diagnosticEvents (#74)

* XDR for upgradeable config entries (#75)

* Generalize configuration-related XDR.

The changes here are summarized in proposed updated to CAP-47 (stellar/stellar-protocol#1291).

- Use unique keys to identify settings
- Only distribute a hash for config upgrades in `StellarValue`
- Add SCP messages for exchanging config upgrade sets

* Remove unused ConfigSetting

---------

Co-authored-by: Dmytro Kozhevin <[email protected]>

* Fix U/I128 and U/I256 number representation for consistent sorting (#78)

* Fix 128 and 256 bits number representation

* fixup! Fix 128 and 256 bits number representation

* Add fee and limit-related configuration XDR based on CAP-0046-07. (#79)

Co-authored-by: Graydon Hoare <[email protected]>

* add config setting for host logic version (#80)

* Meta xdr (#82)

* Add XDR types for contract meta

* generic

* Update Stellar-contract-meta.x

Co-authored-by: Leigh McCulloch <[email protected]>

* Update Stellar-contract-meta.x

* Update Stellar-contract-meta.x

---------

Co-authored-by: Leigh McCulloch <[email protected]>

* Define config settings for contract costs (#81)

* Define cost parameters

* fixup! Define cost parameters

* Move config settings to separate file

* Remove spaces

* Add stellar namespace

* Transaction changes to support Soroban fee model. (#84)

* Transaction changes to support Soroban fee model.

- Moved all the resources (including the footprint) to the transaction level.
- Added host fn batching to compensate for removal of multi-operation tx support
- Did some passing-by naming cleanup (as we never really have time for that)

* Back out the host logic version config setting, will not use it (#85)

* Change cost param type to int64 (#87)

* Add config settings for contract data limits (#90)

* Add `txSOROBAN_RESOURCE_LIMIT_EXCEEDED` to the respective structs. (#91)

* Remove all TransactionResultSetV2 related changes and puts the hash of the events and return values in InvokeHostFunctionResult (#83)

* Remove all TransactionResultSetV2 related changes and puts the hash of TxHashOfMetaHashesSet in the new LedgerHeaderExtensionV2

* Remove hashing of tx meta components

* Remove nested events now that we only have one op per tx

* Return hash of events and return values in InvokeHostFunctionResult

* Err reform (#92)

* Remove comment with improbable suggestion

* Simplify error codes

* update overlay xdr (#94)

* update overlay xdr

* Add comment

* Replace ContractAuth addressWithNonce option with explicit union (#88)

* Replace ContractAuth addressWithNonce option with explicit union (#88)

* Move ContractAuth signatureArgs into Authorization (#89)

* Remove trailing , (#97)

* Changes to auth-related XDR and a bit of cleanup. (#95)

* Changes to auth-related XDR and a bit of cleanup.

- Prepare create contract host fn for using auth next
- Get rid of unnecessary envelopes
- Passing-by cleanup: get rid of `SCVAL_LIMIT`.

* Rename `HostFunctionArgs` back to just `HostFunction`.

* Use `ScAddress` to identify contracts in auth payload.

* Revert invoke host fn return value to be a single value. (#98)

* One more update to return value. (#99)

* State expiration (#93)

* Adds support for state expiration

* Cleanup and refactoring

* Added rent fees and revert footprint changes

* Get rid of floating point math for rent fees

* Add changes for env

* Adapt names to recent consensus on state expiration terminology

* Add state expiration related entries to LedgerCloseMeta as v2

* Move extension point to front of structure.

---------

Co-authored-by: Graydon Hoare <[email protected]>
Co-authored-by: Siddharth Suresh <[email protected]>

* Make `returnValue` optional in meta. (#100)

* Make `returnValue` optional in meta.

This is meaningless for non-Soroban txs.

* Make whole soroban tx meta optional.

Also did some small extension point cleanup.

* Add execution lanes config (#101)

* Add tx limit

* Minor naming tweak

* Small XDR fix. (#102)

* Add costs for new cryptography host functions (#105)

* Switch Soroban nonces from autoincrement to random values with signature expiration. (#103)

* Expiration bump op (#106)

* bump op

* Update thresholds

* Remove mergeable (#108)

* back out ContractCostType::VerifyEcdsaSecp256k1Sig, keeping Recover (#109)

* Add cost types for int256 arithmetics (#110)

* Add footprint to bump expiration name (#111)

* Remove Op postfix for result code (#113)

* Add support for contract instance storage. (#115)

- Store contract instance that includes executable and storage map under a special key
- Make contract executable separate from ScVal

* Add `VmCachedInstantiation` for future use (#116)

* Update XDR comments (#117)

* Remove ContractDataType from ScVal and rename (#118)

* Adds expiration iterator (#104)

* Adds expiration iterator

* Add BucketList size window and remove eviction iterator

* XDR for RestoreFootprintOp (#120)

* XDR for RestoreFootprintOp

* Use extension point instead

* Replace 'restorable' -> 'persistent' for state expiration config to match new terminology (#114)

* Fix comment (#121)

* Add error when accessing expired entry (#122)

* Refactor config XDR to account for dynamic write fees. (#123)

- Remove the flat fee
- Rename the fields that contribute to the write fee for clarity

* Soroban tx set size upgrade support and XDR cleanup. (#124)

- Use dedicated struct for `InvokeContract` host fn
- Replace `ScVec` with `SCVal` or `SCVal<>` depending on the context

* Make SCError into a union to allow user errors to be u32 (#125)

* Remove incorrect comment about Soroban u256 representation (#126)

* Change metadata fee config to only account for contract events. (#127)

Also renamed a couple tx-size related fields for clarity.

* Update `SorobanResources` for consistency with config update. (#128)

* One more metadata->events rename. (#129)

* Adds eviction iterator (#130)

* Remove `ContractCostType::GuardFrame` (#131)

* Clean up and clearify some `ContractCostType`s (#133)

* Add an error for exceeding refundable fee. (#134)

* Add errors for exceeding the refundable fee.

These have to be operation errors, as core is hard-wired to only return `txFAILED` on transaction failure and modifying this behavior is risky/slow.

* Remove `contractEventsSizeBytes` from `SorobanResources`.

This field is almost redundant and only helps to avoid apply-time error in the rare cases when the user sets the events resource, but forgets to set high enough refundable fee. It does, on the other hand, introduce another apply-time failure condition if the contracts emits a bit more events than expected (even if the refundable fee is high enough to cover that).

The total size of the events emitted is still governed by the network setting.

* Remove ScSpecTypeSet and SC_SPEC_TYPE_SET (#136)

* Expiration Entry rework (#137)

* typo (#139)

* expand SCError comments, no functional change (#140)

* expand SCError comments, no functional change

* Update Stellar-contract.x

Co-authored-by: Siddharth Suresh <[email protected]>

---------

Co-authored-by: Siddharth Suresh <[email protected]>

* rename txSOROBAN_RESOURCE_LIMIT_EXCEEDED to more general txSOROBAN_INVALID (#143)

* Update .github/workflows/check.yml

Co-authored-by: Graydon Hoare <[email protected]>

---------

Co-authored-by: stellar-terraform <[email protected]>
Co-authored-by: Graydon Hoare <[email protected]>
Co-authored-by: Leigh McCulloch <[email protected]>
Co-authored-by: jonjove <[email protected]>
Co-authored-by: mlo <[email protected]>
Co-authored-by: Hidenori <[email protected]>
Co-authored-by: Jay Geng <[email protected]>
Co-authored-by: Dmytro Kozhevin <[email protected]>
Co-authored-by: Paul Bellamy <[email protected]>
Co-authored-by: mlo <[email protected]>
Co-authored-by: Garand Tyson <[email protected]>
Co-authored-by: Jay Geng <[email protected]>
Co-authored-by: Brian Anderson <[email protected]>
  • Loading branch information
14 people authored Sep 8, 2023
1 parent b438d51 commit 9ac0264
Show file tree
Hide file tree
Showing 10 changed files with 1,310 additions and 16 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events for main, curr or next.
push:
branches: [ "curr", "next" ]
pull_request:
branches: [ "curr", "next" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "complete"
complete:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Runs a single command using the runners shell
- name: No-op
run: echo success
246 changes: 246 additions & 0 deletions Stellar-contract-config-setting.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
%#include "xdr/Stellar-types.h"

namespace stellar {
// General “Soroban execution lane” settings
struct ConfigSettingContractExecutionLanesV0
{
// maximum number of Soroban transactions per ledger
uint32 ledgerMaxTxCount;
};

// "Compute" settings for contracts (instructions and memory).
struct ConfigSettingContractComputeV0
{
// Maximum instructions per ledger
int64 ledgerMaxInstructions;
// Maximum instructions per transaction
int64 txMaxInstructions;
// Cost of 10000 instructions
int64 feeRatePerInstructionsIncrement;

// Memory limit per transaction. Unlike instructions, there is no fee
// for memory, just the limit.
uint32 txMemoryLimit;
};

// Ledger access settings for contracts.
struct ConfigSettingContractLedgerCostV0
{
// Maximum number of ledger entry read operations per ledger
uint32 ledgerMaxReadLedgerEntries;
// Maximum number of bytes that can be read per ledger
uint32 ledgerMaxReadBytes;
// Maximum number of ledger entry write operations per ledger
uint32 ledgerMaxWriteLedgerEntries;
// Maximum number of bytes that can be written per ledger
uint32 ledgerMaxWriteBytes;

// Maximum number of ledger entry read operations per transaction
uint32 txMaxReadLedgerEntries;
// Maximum number of bytes that can be read per transaction
uint32 txMaxReadBytes;
// Maximum number of ledger entry write operations per transaction
uint32 txMaxWriteLedgerEntries;
// Maximum number of bytes that can be written per transaction
uint32 txMaxWriteBytes;

int64 feeReadLedgerEntry; // Fee per ledger entry read
int64 feeWriteLedgerEntry; // Fee per ledger entry write

int64 feeRead1KB; // Fee for reading 1KB

// The following parameters determine the write fee per 1KB.
// Write fee grows linearly until bucket list reaches this size
int64 bucketListTargetSizeBytes;
// Fee per 1KB write when the bucket list is empty
int64 writeFee1KBBucketListLow;
// Fee per 1KB write when the bucket list has reached `bucketListTargetSizeBytes`
int64 writeFee1KBBucketListHigh;
// Write fee multiplier for any additional data past the first `bucketListTargetSizeBytes`
uint32 bucketListWriteFeeGrowthFactor;
};

// Historical data (pushed to core archives) settings for contracts.
struct ConfigSettingContractHistoricalDataV0
{
int64 feeHistorical1KB; // Fee for storing 1KB in archives
};

// Contract event-related settings.
struct ConfigSettingContractEventsV0
{
// Maximum size of events that a contract call can emit.
uint32 txMaxContractEventsSizeBytes;
// Fee for generating 1KB of contract events.
int64 feeContractEvents1KB;
};

// Bandwidth related data settings for contracts.
// We consider bandwidth to only be consumed by the transaction envelopes, hence
// this concerns only transaction sizes.
struct ConfigSettingContractBandwidthV0
{
// Maximum sum of all transaction sizes in the ledger in bytes
uint32 ledgerMaxTxsSizeBytes;
// Maximum size in bytes for a transaction
uint32 txMaxSizeBytes;

// Fee for 1 KB of transaction size
int64 feeTxSize1KB;
};

enum ContractCostType {
// Cost of running 1 wasm instruction
WasmInsnExec = 0,
// Cost of growing wasm linear memory by 1 page
WasmMemAlloc = 1,
// Cost of allocating a chuck of host memory (in bytes)
HostMemAlloc = 2,
// Cost of copying a chuck of bytes into a pre-allocated host memory
HostMemCpy = 3,
// Cost of comparing two slices of host memory
HostMemCmp = 4,
// Cost of a host function dispatch, not including the actual work done by
// the function nor the cost of VM invocation machinary
DispatchHostFunction = 5,
// Cost of visiting a host object from the host object storage. Exists to
// make sure some baseline cost coverage, i.e. repeatly visiting objects
// by the guest will always incur some charges.
VisitObject = 6,
// Cost of serializing an xdr object to bytes
ValSer = 7,
// Cost of deserializing an xdr object from bytes
ValDeser = 8,
// Cost of computing the sha256 hash from bytes
ComputeSha256Hash = 9,
// Cost of computing the ed25519 pubkey from bytes
ComputeEd25519PubKey = 10,
// Cost of accessing an entry in a Map.
MapEntry = 11,
// Cost of accessing an entry in a Vec
VecEntry = 12,
// Cost of verifying ed25519 signature of a payload.
VerifyEd25519Sig = 13,
// Cost of reading a slice of vm linear memory
VmMemRead = 14,
// Cost of writing to a slice of vm linear memory
VmMemWrite = 15,
// Cost of instantiation a VM from wasm bytes code.
VmInstantiation = 16,
// Cost of instantiation a VM from a cached state.
VmCachedInstantiation = 17,
// Cost of invoking a function on the VM. If the function is a host function,
// additional cost will be covered by `DispatchHostFunction`.
InvokeVmFunction = 18,
// Cost of computing a keccak256 hash from bytes.
ComputeKeccak256Hash = 19,
// Cost of computing an ECDSA secp256k1 pubkey from bytes.
ComputeEcdsaSecp256k1Key = 20,
// Cost of computing an ECDSA secp256k1 signature from bytes.
ComputeEcdsaSecp256k1Sig = 21,
// Cost of recovering an ECDSA secp256k1 key from a signature.
RecoverEcdsaSecp256k1Key = 22,
// Cost of int256 addition (`+`) and subtraction (`-`) operations
Int256AddSub = 23,
// Cost of int256 multiplication (`*`) operation
Int256Mul = 24,
// Cost of int256 division (`/`) operation
Int256Div = 25,
// Cost of int256 power (`exp`) operation
Int256Pow = 26,
// Cost of int256 shift (`shl`, `shr`) operation
Int256Shift = 27
};

struct ContractCostParamEntry {
// use `ext` to add more terms (e.g. higher order polynomials) in the future
ExtensionPoint ext;

int64 constTerm;
int64 linearTerm;
};

struct StateExpirationSettings {
uint32 maxEntryExpiration;
uint32 minTempEntryExpiration;
uint32 minPersistentEntryExpiration;

// rent_fee = wfee_rate_average / rent_rate_denominator_for_type
int64 persistentRentRateDenominator;
int64 tempRentRateDenominator;

// max number of entries that emit expiration meta in a single ledger
uint32 maxEntriesToExpire;

// Number of snapshots to use when calculating average BucketList size
uint32 bucketListSizeWindowSampleSize;

// Maximum number of bytes that we scan for eviction per ledger
uint64 evictionScanSize;

// Lowest BucketList level to be scanned to evict entries
uint32 startingEvictionScanLevel;
};

struct EvictionIterator {
uint32 bucketListLevel;
bool isCurrBucket;
uint64 bucketFileOffset;
};

// limits the ContractCostParams size to 20kB
const CONTRACT_COST_COUNT_LIMIT = 1024;

typedef ContractCostParamEntry ContractCostParams<CONTRACT_COST_COUNT_LIMIT>;

// Identifiers of all the network settings.
enum ConfigSettingID
{
CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES = 0,
CONFIG_SETTING_CONTRACT_COMPUTE_V0 = 1,
CONFIG_SETTING_CONTRACT_LEDGER_COST_V0 = 2,
CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0 = 3,
CONFIG_SETTING_CONTRACT_EVENTS_V0 = 4,
CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 = 5,
CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS = 6,
CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES = 7,
CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES = 8,
CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES = 9,
CONFIG_SETTING_STATE_EXPIRATION = 10,
CONFIG_SETTING_CONTRACT_EXECUTION_LANES = 11,
CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW = 12,
CONFIG_SETTING_EVICTION_ITERATOR = 13
};

union ConfigSettingEntry switch (ConfigSettingID configSettingID)
{
case CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES:
uint32 contractMaxSizeBytes;
case CONFIG_SETTING_CONTRACT_COMPUTE_V0:
ConfigSettingContractComputeV0 contractCompute;
case CONFIG_SETTING_CONTRACT_LEDGER_COST_V0:
ConfigSettingContractLedgerCostV0 contractLedgerCost;
case CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0:
ConfigSettingContractHistoricalDataV0 contractHistoricalData;
case CONFIG_SETTING_CONTRACT_EVENTS_V0:
ConfigSettingContractEventsV0 contractEvents;
case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0:
ConfigSettingContractBandwidthV0 contractBandwidth;
case CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS:
ContractCostParams contractCostParamsCpuInsns;
case CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES:
ContractCostParams contractCostParamsMemBytes;
case CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES:
uint32 contractDataKeySizeBytes;
case CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES:
uint32 contractDataEntrySizeBytes;
case CONFIG_SETTING_STATE_EXPIRATION:
StateExpirationSettings stateExpirationSettings;
case CONFIG_SETTING_CONTRACT_EXECUTION_LANES:
ConfigSettingContractExecutionLanesV0 contractExecutionLanes;
case CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW:
uint64 bucketListSizeWindow<>;
case CONFIG_SETTING_EVICTION_ITERATOR:
EvictionIterator evictionIterator;
};
}
23 changes: 23 additions & 0 deletions Stellar-contract-env-meta.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2022 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

// The contract spec XDR is highly experimental, incomplete, and still being
// iterated on. Breaking changes expected.

% #include "xdr/Stellar-types.h"
namespace stellar
{

enum SCEnvMetaKind
{
SC_ENV_META_KIND_INTERFACE_VERSION = 0
};

union SCEnvMetaEntry switch (SCEnvMetaKind kind)
{
case SC_ENV_META_KIND_INTERFACE_VERSION:
uint64 interfaceVersion;
};

}
29 changes: 29 additions & 0 deletions Stellar-contract-meta.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2022 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

// The contract meta XDR is highly experimental, incomplete, and still being
// iterated on. Breaking changes expected.

% #include "xdr/Stellar-types.h"
namespace stellar
{

struct SCMetaV0
{
string key<>;
string val<>;
};

enum SCMetaKind
{
SC_META_V0 = 0
};

union SCMetaEntry switch (SCMetaKind kind)
{
case SC_META_V0:
SCMetaV0 v0;
};

}
Loading

0 comments on commit 9ac0264

Please sign in to comment.