Commit graph

47 commits

Author SHA1 Message Date
Roman Khimov
d7502debba core: adjust storage update fees
Follow neo-project/neo#2033.
2020-11-03 22:50:40 +03:00
Roman Khimov
2924ecd453 core: use ic.SpawnVM() in tests, not vm.New()
vm.New() sets some arbitrary trigger while interop context always sets
something appropriate according to its state.
2020-10-29 19:17:07 +03:00
Anna Shaleva
5a15e6b54c core: add tests for CheckWitness
Close #1366
2020-10-26 20:30:45 +03:00
Anna Shaleva
fe1f0a7245 core: introduce CheckReturnState constants
At the moment we should have 3 possible options to check return state
during vm context unloading:
	* no check
	* ensure the stack is empty
	* ensure the stack is not empty

It is necessary to distinguish them because new _deploy method shouldn't
left anything on stack. Example: if we use _deploy method before some
ordinary contract method which returns one value. Without these changes
the contract invocation will fail due to 2 elements on stack left after
invocation (the first `null` element is from _deploy, the second element
is return-value from the ordinary contract method).
2020-10-13 19:14:44 +03:00
Anna Shaleva
6ce00fde82 vm, core: move invocation counter from InteropContext to VM 2020-10-08 11:33:26 +03:00
Anna Shaleva
45bfce60a5 core: remove error from runtime.GetInvocationCounter
close #1444
2020-10-08 11:32:00 +03:00
Roman Khimov
d6a1a22afa
Merge pull request #1452 from nspcc-dev/contract/deploy
Support `_deploy` method
2020-10-06 19:54:14 +03:00
Evgenii Stratonikov
2d9ef9219a core: call _deploy method during create/update 2020-10-06 18:03:25 +03:00
Evgenii Stratonikov
b71f9e296c core/tests: refactor contract creation a bit
Make it easier to add new methods.
2020-10-06 18:03:25 +03:00
Evgenii Stratonikov
0b76f875c7 core: allow Null in System.Contract.Update
Null means absense of script or manifest, empty
byte-slice is an error.

Related #1459.
2020-10-06 10:34:45 +03:00
Evgenii Stratonikov
833bbb1d35 core: calculate gas for System.Storage.Put correctly
If `Put` creates new key, its length should contribute
to a GAS cost of the syscall.
2020-10-05 13:03:44 +03:00
Evgenii Stratonikov
877b8ece63 core: move contractCall* to a separate package 2020-09-25 16:32:10 +03:00
Roman Khimov
a2d9b89964 dao: reuse buffers when storing blocks, txes and aers
Reduce memory allocation pressure.
2020-09-09 20:46:31 +03:00
Roman Khimov
a7670303e8 stackitem: change Bool() to TryBool(), prepare for its failures 2020-08-21 20:55:20 +03:00
Roman Khimov
8e619cc671
Merge pull request #1318 from nspcc-dev/fix/verifytests
Add tests for `verifyTx` and `verifyHeader`
2020-08-14 17:24:03 +03:00
Roman Khimov
e7d13e6db2 *: fix misspellings found in Go Report Card 2020-08-14 12:16:24 +03:00
Roman Khimov
f6a308f7f6 *: fix ineffassign where the value should really be used
Found with GoReportCard.
2020-08-14 12:08:57 +03:00
Evgenii Stratonikov
1eb9a4c6c6 core: allow to use verification contracts
In NEO3 we can't just appcall hash, as verification script has no access
to state. Instead we use `verify` method of an arbitrary contract.
2020-08-14 09:40:34 +03:00
Evgenii Stratonikov
bf01599430 vm: check return value on context unload
When calling external contracts we expect exactly 1 value to be on
stack. For methods returning nothing, `Null` value is pushed, otherwise
it is an error.`
2020-08-10 11:52:33 +03:00
Anna Shaleva
995053f2eb core: add VM into interop context 2020-08-07 16:15:24 +03:00
Anna Shaleva
90825efa16 core: move transaction's sender to cosigners
Closes #1184

Ported changes from https://github.com/neo-project/neo/pull/1752
2020-08-04 17:33:50 +03:00
Evgenii Stratonikov
3c99393bef core: simplify System.Contract.Call* parameter handling 2020-07-30 12:37:32 +03:00
Evgenii Stratonikov
f40aba4cd0 vm: convert items to UTF-8 strings
Add `stackitem.ToString` for seamless string conversion.
2020-07-30 12:37:31 +03:00
Evgenii Stratonikov
23a1430395 core: allow to restrict creating callbacks from syscalls
Specify DisallowCallback flag if syscall is not allowed to be used in a
callback.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
99b0397a61 core: implement System.Callback.CreateFromSyscall interop
Allow to create callbacks from syscalls.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
c54b45e76d core: implement System.Callback.CreateFromMethod interop
Support creating callbacks from contract methods.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
f96c217aba core/tests: refactor getting contract state
Get 2 contracts in pair which is useful everytime we need to test
syscall with one contract calling the other.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
e654d22991 core/tests: introduce loadScript helper
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
382a7f5b3e core: implement System.Callback.* interops
Support creating callbacks from pointers.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
685d44dbc1 *: support _initialize method in contracts
Invoke `_initialize` method on every call if present.
In NEO3 there is no entrypoint and methods are invoked by offset,
thus `Main` function is no longer required.
We still have special `Main` method in tests to simplify them.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
466af55dea vm: isolate stack in LoadScript
When calling contract it must be provided with a new stack containing
only it's arguments. The result is then copied back on RET.

Fix #1220.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
d2ddf7b7cb *: support invoking methods by offset
Allow to invoke methods by offset:
1. Every invoked contract must have manifest.
2. Check arguments count on invocation.
3. Change AppCall to a regular syscall.
4. Add test suite for `System.Contract.Call`.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
e52c39ae7e manifest: remove EntryPoint from manifest 2020-07-27 11:08:01 +03:00
Evgenii Stratonikov
3d7fa9de93 *: make Notify interop accept event name 2020-07-20 13:33:32 +03:00
Anna Shaleva
f31ce9289d core: add System.Contract.GetCallFlags interop
Part of #1055.

It returns calling flags of the current context.
2020-07-17 12:35:02 +03:00
Anna Shaleva
842feb2533 core: adjust System.Contract.Update interop
Part of #1055.

We should check contract scripthash against the one provided in manifest
and manifest groups. We shouldn't put on stack anything after return.
And ofcourse, we mast not destroy the old contract at the end, as
`contractDestroy` removes all storage items associated with the
old contract ID (which equals to the new contract ID). We just remove
old contract state - it's enough.
2020-07-17 12:33:44 +03:00
Anna Shaleva
fddad0b475 core: adjust System.Contract.Create interop
Part of #1055.

It should check given scripthash against manifest groups and return the
contract state as a struct (not interop interface).
2020-07-17 09:28:52 +03:00
Anna Shaleva
d2ec0fed3d core: adjust System.Blockchain.GetContract interop
Part of #1055.

It should put on stack an array instead of interop interface.
2020-07-17 09:28:52 +03:00
Anna Shaleva
1a5fb01e61 core: adjust System.Contract.IsStandard interop
Part of #1055.

It should check not only stored contracts, but also interop context
script container in case if it's a transaction.
2020-07-17 08:19:43 +03:00
Evgenii Stratonikov
3762ebdd08 core: implement System.Runtime.GetInvocationCounter syscall 2020-06-17 11:24:11 +03:00
Evgenii Stratonikov
75e597f880 core: implement System.Runtime.GetNotifications syscall 2020-06-17 11:24:11 +03:00
Evgenii Stratonikov
a4e4439967 core,vm: implement System.Runtime.GasLeft syscall 2020-06-17 11:24:11 +03:00
Evgenii Stratonikov
52a27e9be4 core: implement System.Contract.CreateStandardAccount syscall 2020-06-16 12:12:29 +03:00
Evgenii Stratonikov
5b4f38d717 core: implement System.Contract.IsStandard syscall 2020-06-16 12:12:27 +03:00
Anna Shaleva
7a2d37cf7e core: update System.Blockchain.GetBlock interop
closes #1025

Now we put on stack stackitem.Array instead of Interop, so we're able to
use all available block properties without extra interop getters.
Removed Neo.Blockchain.GetBlock interop as we don't need it anymore.
2020-06-09 23:24:04 +03:00
Anna Shaleva
d692de5ea4 core: add System.Blockchain.GetTransactionFromBlock interop 2020-06-09 22:54:16 +03:00
Anna Shaleva
53655c5ac2 core: implement new System.Blockchain.GetTransaction interop
closes #1023

Now we put on stack stackitem.Array instead of Interop, so we don't
need old transaction-related interops anymore. Removed the following
interops:
	System.Transaction.GetHash
	Neo.Transaction.GetAttributes
	Neo.Transaction.GetHash
	Neo.Transaction.GetWitnesses
	Neo.Attribute.GetData
	Neo.Attribute.GetUsage

Also removed the following duplicated NEO interop:
	Neo.Blockchain.GetTransaction
2020-06-09 22:04:13 +03:00