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

Clarity Wasm Next #4093

Closed
wants to merge 176 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
410da86
chore: move sha2 compile flags from inner lib
Jan 11, 2023
9586022
chore: remove serde_stacker from stacks-node
Jan 11, 2023
8f638bb
chore: update rusqlite
Jan 11, 2023
3b2600d
chore: rebase clarinet wasm changes onto next
obycode Nov 27, 2023
4298625
feat(WIP): integrate wasm runtime
obycode Aug 24, 2023
4da3bcf
feat(clarity): integrate wasm runtime
obycode Aug 25, 2023
2fdccac
feat(clar2wasm): add interface to call a function
obycode Aug 25, 2023
6214d95
feat(clar2wasm-runtime): args and return values
obycode Aug 28, 2023
86f5588
feat(clar2wasm-runtime): remove `ContractAnalysis` from runtime
obycode Aug 30, 2023
a5624e4
chore: refactor away 'hooks lifetime
cylewitruk Aug 31, 2023
5d0f539
fix: missed a couple of 'hooks in impl blocks
cylewitruk Aug 31, 2023
bf1e572
feat(clar2wasm-runtime): add host interface for function definitions
obycode Aug 31, 2023
30ac232
fix: fix Cargo.lock after rebase
obycode Aug 31, 2023
ce32380
fix: update the order of high/low integer parts
obycode Sep 1, 2023
2798a7a
chore: add comment to `initialize_contract` method
obycode Sep 1, 2023
f311e7e
chore: add comments and delete unused function
obycode Sep 1, 2023
6341fdf
fix: handle wasm generator errors cleanly
obycode Sep 1, 2023
58ce017
chore: remove all panics from clarity_wasm
obycode Sep 1, 2023
80072e4
chore: use exhaustive match blocks
cylewitruk Sep 3, 2023
a9729e1
chore: make return type optional in `DefinedFunction`
obycode Sep 5, 2023
d3ee920
chore: formatting
obycode Sep 5, 2023
671c53e
fix: resolve recursive dependency
obycode Sep 7, 2023
1e9ab26
feat: pre-compile Wasm module during initialization
obycode Sep 8, 2023
5e2d5d2
chore: fix warnings
obycode Sep 8, 2023
0e1b918
chore: improve error handling
obycode Sep 8, 2023
f84198f
feat: add support for passing `list` values into a contract
obycode Sep 10, 2023
d9adb1f
feat: add support for builtin variables in Wasm runtime
obycode Sep 12, 2023
e7af505
chore: update path for clar2wasm
obycode Sep 13, 2023
88d7503
fix: relax ownership in `ClarityWasmContext`
obycode Sep 13, 2023
0c05ed3
feat(wasm): add support for `as-contract`
obycode Sep 15, 2023
4c11262
feat: add support for `stx-get-balance` and `stx-account`
obycode Sep 19, 2023
62e18e7
refactor: separate init and runtime contexts
obycode Sep 19, 2023
680cd58
refactor: reorder functions for better visibility
obycode Sep 19, 2023
1660dab
feat: implement `stx-burn`
obycode Sep 19, 2023
4fc9b09
feat: implement `stx-transfer?`
obycode Sep 19, 2023
5cf8600
refactor: reorganize the context passed to the Wasm runtime
obycode Sep 21, 2023
0f4aee8
feat: add better support for buffers
obycode Sep 22, 2023
ad07436
refactor: revert changes to split `define-data-var` into two host-calls
obycode Sep 22, 2023
6599b9e
feat(clarity-wasm): add support for `define-map`
obycode Sep 22, 2023
15e363f
feat: add support for `ft-get-balance`
obycode Sep 22, 2023
8df2cab
feat: add support for `ft-burn?`
obycode Sep 22, 2023
8f96e89
feat: add support for `ft-mint?`
obycode Sep 22, 2023
8c3b27c
feat: add support for `ft-transfer?`
obycode Sep 23, 2023
3a5f621
feat: add support for `nft-get-owner?`
obycode Sep 25, 2023
108654f
feat: add support for `nft-burn?`
obycode Sep 25, 2023
9ae99cf
feat: add support for `ft-mint?`
obycode Sep 25, 2023
4c3e194
feat: add support for `nft-transfer?`
obycode Sep 25, 2023
fac7687
fix: bug in `ft_mint` host-interface function
obycode Sep 25, 2023
b98c46e
docs: add comment about `expect`
obycode Sep 25, 2023
648ef86
docs: add todo for runtime error handling
obycode Sep 25, 2023
a19324a
feat: implement `Copy` for length types
obycode Sep 27, 2023
2c6cb5f
fix: wasm_to_clarity_value
obycode Sep 27, 2023
693f1a7
chore: upgrade to wasmtime 13.0
obycode Sep 28, 2023
c5acce5
feat(wasm): add host-functions for `map-*` expressions
obycode Sep 28, 2023
d2ecd03
feat(wasm): add support for `get-block-info?`
obycode Sep 29, 2023
187aa0c
feat: simple `contract-call?` implementation
obycode Oct 10, 2023
06b3a81
feat: improve handling of passing in-memory values
obycode Oct 11, 2023
6d9aff2
feat: improve `get_type_in_memory_size`
obycode Oct 11, 2023
f8f0297
chore: add function doc comment
obycode Oct 13, 2023
5e6ae9d
feat(wasm): print support
zone117x Sep 21, 2023
f2161f9
feat(wasm): finish `print` implementation
obycode Oct 14, 2023
58a7e64
feat(wasm): improve support for principals
obycode Oct 15, 2023
ae537a9
feat(wasm): return a value from contract initialization
obycode Oct 16, 2023
eb3d15c
feat: better support for lists (and refactoring)
obycode Oct 17, 2023
12701e0
feat(wasm): add support for reading `bool` values
obycode Oct 19, 2023
59074d6
fix(wasm): wrong conversion from (i64, i64) to i128 or u128 in wasm_t…
Acaccia Oct 25, 2023
c4a5558
feat(wasm): add host functions for trait functions
obycode Nov 3, 2023
19ebf5f
feat(wasm): update contract call host function to support dynamic calls
obycode Nov 4, 2023
4ac52ff
feat(wasm): add host function for `get-burn-block-info?`
obycode Nov 7, 2023
3f4935f
feat(wasm): add support for `at-block` and unit tests for read/write
obycode Nov 9, 2023
288824a
feat(wasm): add host-interface functions for crypto operations
obycode Nov 9, 2023
982f7e6
feat(wasm): add host-interface functions for `secp256k1-*`
obycode Nov 9, 2023
4ebd123
refactor(wasm): make wasm_module public in ContractContext
hugocaillard Nov 8, 2023
7c137a6
fix: change module for imported `log` function
obycode Nov 13, 2023
cf6433d
feat(wasm): add `principal_of` host function
obycode Nov 20, 2023
f9bb197
fix: resolve issues after merge and re-format
obycode Nov 28, 2023
1c2d541
fix: fix build
hugocaillard Nov 28, 2023
d01715e
fix: gate `slog` code with `log` feature
obycode Nov 28, 2023
3217b45
fix(wasm): feature flag wasmtime usage
hugocaillard Nov 29, 2023
6b33a8d
fix(wasm): resolve issues with wasm version of secp256k1
obycode Nov 29, 2023
00a158d
fix: remove serde_stacker for wasm
hugocaillard Nov 29, 2023
90ea3c4
chore(wasm): fix wasm gating and formatting
obycode Nov 30, 2023
83b5054
feat(wasm): include proper rollback handling for contract-calls
obycode Nov 30, 2023
9d106b1
feat(wasm): handle commit and rollback for local calls
obycode Dec 1, 2023
59e58ae
fix(wasm): gate wasm specific behavior
obycode Dec 1, 2023
1bf9c57
feat(wasm): gate wasm compilation on epoch >= 3.0
obycode Dec 1, 2023
8aac6d0
Merge pull request #4110 from stacks-network/feat/clarity-wasm-next-c…
obycode Dec 4, 2023
6434c1e
chore: load clar2wasm from github
hugocaillard Dec 4, 2023
ef195fa
--wip-- [skip ci]
hugocaillard Dec 4, 2023
d7715e8
fix: rebase error
hugocaillard Dec 4, 2023
f0d9456
fix: update cargo.lock
hugocaillard Dec 4, 2023
db71709
fix: update cargo.lock
hugocaillard Dec 4, 2023
498e00d
feat: read string-utf8 types from wasm memory as 32-bit unicode scala…
zone117x Dec 6, 2023
5d07706
Merge branch 'feat/clarity-wasm-utf8' into feat/clarity-wasm-next
zone117x Dec 6, 2023
87940b9
fix: use compile-time macro for `wasm` feature isolation
obycode Dec 6, 2023
fa5071b
fix: tuple "wasm_to_clarity" returns index instead of increment
Acaccia Dec 7, 2023
4e5cd21
Merge pull request #4132 from stacks-network/fix/wrong-tuple-incremen…
Acaccia Dec 7, 2023
7fe76d0
fix: handle epochs 2.5 and 3.0 correctly
obycode Dec 8, 2023
47b47b0
Merge branch 'next' into feat/clarity-wasm-next
obycode Dec 8, 2023
d8c58b1
feat: handle clar2wasm/developer-mode
hugocaillard Dec 8, 2023
3966aa0
refactor: use 1 byte for contract name length in principals
obycode Dec 13, 2023
82aeb7d
Merge branch 'next' into feat/clarity-wasm-next
obycode Dec 14, 2023
fc18932
chore: fix issues after merge
obycode Dec 15, 2023
4b7c875
fix: cargo check
hugocaillard Dec 15, 2023
4196a6d
Merge pull request #4175 from stacks-network/feat/clarity-wasm-next-m…
obycode Dec 15, 2023
f2d9719
Merge branch 'next' into feat/clarity-wasm-next
obycode Dec 21, 2023
9c781a7
chore: use git branch for all local dependencies
obycode Dec 22, 2023
98b3c5c
chore: fix warnings
obycode Dec 22, 2023
e9d9c3c
fix: add missing dependencies in Dockerfile
obycode Dec 22, 2023
d5b5cda
fix: disable `developer-mode` by default
obycode Dec 22, 2023
52680af
chore: update Cargo.lock
obycode Dec 22, 2023
e7c57e8
fix: replace all uses of `span` with method calls
obycode Sep 20, 2023
88a068b
chore: update Cargo.lock
obycode Dec 22, 2023
9884895
fix: fix issues with `span`
obycode Dec 23, 2023
c8db64c
chore: update Cargo.lock
obycode Dec 23, 2023
35b4e27
fix: handle trait references correctly
obycode Jan 2, 2024
7f64b0f
fix: handle trait references correctly everywhere
obycode Jan 2, 2024
6b05151
fix: fix typo from last commit
obycode Jan 2, 2024
ab4b6e0
fix: don't check type when building a list from buffer
obycode Jan 3, 2024
fd73fd5
chore: update Cargo.lock
obycode Jan 3, 2024
f100ae1
fix: pre-expr span in comments
hugocaillard Jan 12, 2024
25b82d1
chore: update clar2wasm
hugocaillard Jan 12, 2024
06bc351
docs: add patch for local development to .cargo/config
obycode Jan 16, 2024
05dcc6b
Merge branch 'next' into feat/clarity-wasm-next
obycode Jan 18, 2024
f10ed80
chore: update Cargo.lock
obycode Jan 18, 2024
d604de7
fix(clarity-wasm): define-variable should dereference in-memory type …
Acaccia Jan 18, 2024
41f07b7
fix(clarity-wasm): writing of optional value should add placeholders …
Acaccia Jan 18, 2024
4246314
fix(clarity-wasm): wrong spacing in writing of list
Acaccia Jan 18, 2024
7bb0311
chore(clarity-wasm): remove useless mut
Acaccia Jan 18, 2024
863707b
Merge pull request #4259 from stacks-network/fix/read-and-write-wasm-…
Acaccia Jan 18, 2024
aeb0c9c
chore: remove commented packages from Cargo.tomls
obycode Jan 18, 2024
4c2df36
fix(clarity-wasm): read value in linked set-var should dereference in…
Acaccia Jan 22, 2024
5956df3
Merge pull request #4275 from stacks-network/fix/set-variable-in-memory
Acaccia Jan 22, 2024
03fc717
feat: tweak next_initiative delay value
hugocaillard Jan 24, 2024
a1c4e3f
Revert "feat: tweak next_initiative delay value"
hugocaillard Jan 24, 2024
d1aab28
fix: include vrf feature in wasm
hugocaillard Jan 25, 2024
d199dc5
Revert "fix: include vrf feature in wasm"
hugocaillard Jan 25, 2024
7f52960
fix: make wsts optional for wasm build
hugocaillard Jan 26, 2024
a3e0aff
fix: wsts build
hugocaillard Jan 31, 2024
fcee50d
fix: wsts build
hugocaillard Jan 31, 2024
4584351
chore: update dependencies
hugocaillard Jan 31, 2024
1a555e4
fix(clarity-wasm): wasm-to-clarity-value of principal returns 2 Val
Acaccia Feb 2, 2024
83673bd
feat(typechecker): add a concretize method to TypeMap
Acaccia Feb 2, 2024
db25308
refactor(clarity): move the concretize_deep function inside TypeSigna…
Acaccia Feb 6, 2024
3f18dfd
refactor(clarity): concretize_deep has an easier process for TupleType
Acaccia Feb 6, 2024
5ab6364
refactor(clarity): concretize_deep has an easier process for ListType…
Acaccia Feb 6, 2024
3455533
Merge pull request #4338 from stacks-network/fix/wasm-principal
Acaccia Feb 6, 2024
75ee771
feat: for top-level expressions, return the last result
obycode Feb 21, 2024
115fc39
feat(clarity-wasm): add support for writing to wasm string-utf8
Acaccia Feb 21, 2024
de3e3c6
Merge pull request #4410 from stacks-network/feat/write-to-wasm-strin…
Acaccia Feb 22, 2024
5d7821c
chore: updated time dependency
hugocaillard Feb 23, 2024
2221c70
chore: update dependencies targetting the stacks-core repo
hugocaillard Feb 23, 2024
d84cee6
chore: remove unused time dependency from clarity
hugocaillard Feb 23, 2024
1e9df56
chore: update dependencies targetting the stacks-core repo
hugocaillard Feb 23, 2024
22344bb
chore: specify rev for pox-locking's clarity dependency
MicaiahReid Feb 29, 2024
6377198
Merge branch 'next' into feat/clarity-wasm-next
obycode Feb 29, 2024
d1ce196
chore: update dependencies and pox-locking
hugocaillard Mar 5, 2024
1e24853
chore: update clarity version
hugocaillard Mar 5, 2024
5b20b33
fix: feature flag bitvec.rs for wasm-build
hugocaillard Mar 5, 2024
7880b9d
chore: update stacks-common
hugocaillard Mar 5, 2024
eaa7c95
chore: update clarity
hugocaillard Mar 5, 2024
a435e7e
chore: update pox-locking
hugocaillard Mar 5, 2024
14732c0
chore: update dependency using branch
hugocaillard Mar 6, 2024
2ab366d
chore: update cargo.lock
hugocaillard Mar 6, 2024
d6bfaf8
fix(clarity-wasm): map-type functions should read indirectly key/valu…
Acaccia Mar 12, 2024
b68e5ed
fix(clarity-wasm): fix mistakes in type size in memory computation
Acaccia Mar 12, 2024
5e8310b
fix(clarity-wasm): remove useless parentheses
Acaccia Mar 12, 2024
b006cd6
feat: enable private function call to return any type in developer mode
hugocaillard Mar 12, 2024
82d7bc3
Merge pull request #4523 from stacks-network/fix/clarity-wasm-map-type
Acaccia Mar 12, 2024
a76dcdc
fix(clarity-wasm): write to memory of values include space for value …
Acaccia Mar 14, 2024
96aba47
Merge pull request #4540 from stacks-network/fix/clarity-wasm-write-t…
obycode Mar 14, 2024
d4e6210
chore: upgrade time dependency in stacklibs
hugocaillard Mar 19, 2024
1173e5a
chore: update cargo.lock
hugocaillard Mar 19, 2024
5eb967c
chore: remove unused dependecy p256k1@5.5.0
hugocaillard Mar 20, 2024
ddf2dc8
chore: update clar2wasm
hugocaillard Mar 22, 2024
35cce11
chore: upgrade dependencies
hugocaillard Mar 22, 2024
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
Prev Previous commit
Next Next commit
feat(clar2wasm-runtime): add host interface for function definitions
  • Loading branch information
obycode committed Nov 28, 2023
commit bf1e5720b5e5cd4d650f6ed461cac36abe696594
55 changes: 2 additions & 53 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 80 additions & 4 deletions clarity/src/vm/clarity_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ use wasmtime::{AsContextMut, Caller, Engine, Linker, Memory, Module, Store, Trap

use super::{
analysis::CheckErrors,
callables::{DefineType, DefinedFunction},
contracts::Contract,
costs::CostTracker,
database::{clarity_db::ValueResult, ClarityDatabase, DataVariableMetadata},
errors::RuntimeErrorType,
types::{CharType, FixedFunction, FunctionType, QualifiedContractIdentifier, SequenceData},
SymbolicExpression,
};

trait ClarityWasmContext {
Expand Down Expand Up @@ -280,11 +282,85 @@ fn link_define_function_fn(linker: &mut Linker<ClarityWasmInitContext>) {
"clarity",
"define_function",
|mut caller: Caller<'_, ClarityWasmInitContext>,
identifier: i32,
kind: i32,
name_offset: i32,
name_length: i32,
value_offset: i32,
value_length: i32| {},
name_length: i32| {
// Read the variable name string from the memory
let function_name =
read_identifier_from_wasm(&mut caller, name_offset, name_length)?;
let function_cname = ClarityName::try_from(function_name.clone())?;

// Retrieve the kind of function
let (define_type, function_type) = match kind {
0 => (
DefineType::ReadOnly,
caller
.data()
.contract_analysis
.get_read_only_function_type(&function_name)
.ok_or(Error::Unchecked(CheckErrors::UnknownFunction(
function_name.clone(),
)))?,
),
1 => (
DefineType::Public,
caller
.data()
.contract_analysis
.get_public_function_type(&function_name)
.ok_or(Error::Unchecked(CheckErrors::UnknownFunction(
function_name.clone(),
)))?,
),
2 => (
DefineType::Private,
caller
.data()
.contract_analysis
.get_private_function(&function_name)
.ok_or(Error::Unchecked(CheckErrors::UnknownFunction(
function_name.clone(),
)))?,
),
_ => Err(Error::Wasm(WasmError::InvalidFunctionKind(kind)))?,
};

let fixed_type = match function_type {
FunctionType::Fixed(fixed_type) => fixed_type,
_ => Err(Error::Unchecked(CheckErrors::DefineFunctionBadSignature))?,
};

let function = DefinedFunction::new(
fixed_type
.args
.iter()
.map(|arg| (arg.name.clone(), arg.signature.clone()))
.collect(),
// TODO: We don't actually need the body here, so we
// should be able to remove it. For now, this is a
// placeholder.
SymbolicExpression::literal_value(Value::Int(0)),
define_type,
&function_cname,
&caller
.data()
.run_context
.contract_context
.contract_identifier
.to_string(),
fixed_type.returns.clone(),
);

// Insert this function into the context
caller
.data_mut()
.run_context
.contract_context
.functions
.insert(function_cname, function);

Ok(())
},
)
.unwrap();
}
Expand Down
2 changes: 2 additions & 0 deletions clarity/src/vm/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub enum WasmError {
StackPointerNotFound,
UnableToWriteStackPointer(wasmtime::Error),
InvalidNoTypeInValue,
InvalidFunctionKind(i32),
Runtime(wasmtime::Error),
}

Expand All @@ -151,6 +152,7 @@ impl fmt::Display for WasmError {
write!(f, "Unable to write stack pointer: {e}")
}
WasmError::InvalidNoTypeInValue => write!(f, "Invalid no type in value"),
WasmError::InvalidFunctionKind(kind) => write!(f, "Invalid function kind: {kind}"),
WasmError::Runtime(e) => write!(f, "Runtime error: {e}"),
}
}
Expand Down