3
0
mirror of https://github.com/Qortal/AT.git synced 2025-01-29 02:22:13 +00:00
Commit Graph

48 Commits

Author SHA1 Message Date
CalDescent
9de6eccc0e
Merge pull request #1 from catbref/master
Improve documentation and test support
2022-11-05 11:12:04 +00:00
catbref
836ef215d4 Minor JavaDoc fix-up, in particular the wrong explanation for SLP_VAL OpCode 2021-12-02 21:10:11 +00:00
catbref
ae23aac716 Improvements to TestAPI and ExecutableTest to help testing external ATs like lottery, etc.
No changes to core AT.
2021-11-28 13:42:42 +00:00
catbref
e522fb312d Improved test support:
* pom.xml now builds JavaDoc, sources and test JARs
* more descriptive output from test classes to aid debugging
* actually add/collate AT-generated transactions to test blockchain for analysis
* test block period changed from 10 minutes to 1 minute
* 'quiet' logger aded that doesn't emit DEBUG log entries
2021-11-20 15:22:50 +00:00
catbref
0a16696352 New OpCodes:
SLP_DAT addr: fixed to work as advertised
SLP_VAL value: sleeps for <value> blocks
SHL_VAL addr value: left-shifts the contents of addr by value bits
SHR_VAL addr value: right-shifts the contents of addr by value bits

EXT_FUN_VAL func value: pass a value to a function instead of fetching via addr
This allows new functions GET_A_DAT to take data segment address,
instead of convoluted GET_A_IND which requires an address stored in the data segment (like a pointer).

New FunctionCodes:
GET_A_DAT, GET_B_DAT, SET_A_DAT, SET_B_DAT (see above)
UNSIGNED_COMPARE_A_WITH_B, SIGNED_COMPARE_A_WITH_B

Add branch offset bounds checking to OpCode.calcOffset method (throws if out of bounds). Added test to cover.

Tidied up JavaDoc, which is now also generated by pom.xml!
Added JavaDoc comments to OpCodeParam enum entries.
Corrected some inaccurate descriptions.
Converted obsolete <tt> tags to <code>.
Fixed some invalid HTML, converted raw characters like &, <, >, etc. to HTML entites like &amp;, &gt; and &rarr;

Bumped version to 1.4.0
2021-11-13 15:32:10 +00:00
catbref
2b116f41ce Change setSleepUntilHeight(int) to setSleepUntilHeight(Integer) to allow setting to null 2021-02-06 10:05:45 +00:00
catbref
f78ee39d8b v1.3.8: reduce byte array copying 2020-09-25 12:43:31 +01:00
catbref
4b65119831 Correct artifactId in maven-import.txt 2020-08-12 14:12:35 +01:00
catbref
2884b586d6 Try to reduce byte arrays being created/copied wherever possible. Also bump to v1.3.7 due to interface changes. 2020-08-12 14:07:56 +01:00
catbref
facb9c213f Convert logging to lambda-based to reduce CPU load if logging disabled, also bump to v1.3.6 as interface changed 2020-08-12 14:06:56 +01:00
catbref
2b28cbe07b Bump to v1.3.5 2020-06-18 16:33:35 +01:00
catbref
e42d79c500 Remove extraneous imports to reduce compiler warnings 2020-06-18 16:32:40 +01:00
catbref
8ff61a6081 Add ADD/SUB/MUL/DIV_VAL opcodes + tests 2020-06-18 16:32:12 +01:00
catbref
09d2b5be1f Fix off-by-one error with data address bounds & unit test to cover 2020-06-09 10:57:39 +01:00
catbref
3c17db0c46 Bump to version v1.3.4 2020-04-14 17:25:35 +01:00
catbref
fa3760dafc Provide public static method for extracting data bytes from state data. 2020-04-14 17:16:41 +01:00
catbref
582921aa54 Avoid extra byte[] allocation and double-copy when constructing MachineState 2020-04-14 17:16:12 +01:00
catbref
6dc717f3de Store/use MSB of B for RMD160/HASH160 function codes.
Previously used LSB of B but wasn't updated since switch to big-endian.
2020-04-14 15:06:51 +01:00
catbref
aadf987514 Correct bounds check in FunctionCode.getHashData()
The test "functionData.value2 > state.numDataPages" was incorrect
because value2 contains a a BYTE count, so could be up to 8 times
bigger than state.numDataPages!

Reverted back to looser check of "functionData.value2 > Integer.MAX_VALUE"
2020-04-14 14:56:40 +01:00
catbref
b0370cc52d Better checking that correct opcode used with corresponding function code.
Added tests to cover above.
2020-04-14 09:25:21 +01:00
catbref
466ffa4d4d Improved logging support
We now use a logger factory, which means loggers can be created
per class.

This allows use of 'wrapped' Apache log4j2 loggers with the added
benefit of more accurate class/line-number reporting.
2020-04-14 09:22:21 +01:00
catbref
ee2a81430c Rename 'MachineState.getIsSleeping()', and similar, to proper 'isSleeping()'
Examples:

getHadFatalError() to hadFatalError()
getIsSleeping() to isSleeping()
etc.
2020-04-14 09:10:29 +01:00
catbref
a58b4d4bec New OpCode.compile() to simplify compilation, with checking!
OpCode.compile(...) takes varargs as necessary, and returns byte[].
It will complain if the number of args is incorrect, or if any arg
cannot be coerced into the correct form (byte/int/short/long).
It will also complain if you try to use a branch offset that is too
big to fit into byte.

Two-pass compilation support added with OpCode.calcOffset(ByteBuffer, Integer)
where Integer is null during the first pass, but also set to ByteBuffer.position()
during first pass, so proper value can be calculated during second pass.

MachineState.disassemble() changed into a public static method,
requiring far less effort to call.

Checking of branch target bounds now done by each OpCode as
doing it in OpCodeParam wasn't reliable as PC wasn't available.

Yet more visibility tightening.

Improved comments.

Yet more tests.
2020-04-09 18:16:14 +01:00
catbref
d9338f31d3 More visibility tightening. Bump to v1.3.3 due to some method signature changes. 2020-04-09 12:59:23 +01:00
catbref
6e9198b226 More tests (now in org.ciyam.at), better exception messages, tidying, tightened visibilty.
Added unit test to cover branching to beyond end of code segment.
Added unit test to cover branching to before start of code segment.

Added very naive fuzzy disassembly test to see how it handles random, invalid code.

Refactored data address checking in FunctionCode.postCheckExecute() methods to
single FunctionCode.checkDataAddress method. New method includes FunctionCode's name
when throwing due to out-of-bounds address.

Tidied narrowing conversions by replacing literal 0x7fffffffL with Integer.MAX_VALUE.

Tightened OpCode methods visiblity from public to protected.
Added branch target checking to OpCode.executeBranchConditional but maybe this is
already covered by call to Utils.getCodeOffset() when assembling params in Opcode.execute().
Improved message in Utils.getCodeOffset() anyway.

Moved unit tests to org.ciyam.at package.
Moved unit test support classes from 'common' to org.ciyam.at.test.
2020-04-09 12:05:27 +01:00
catbref
36008bdeac Fix constructing MachineState from creationBytes. Bump to v1.3.2 2020-04-09 09:38:48 +01:00
catbref
3e0699f399 Fix constructing MachineState from creationBytes. Bump to v1.3.1
NOTE: this constructor's args have changed from:
  public MachineState(byte[] creationBytes)
to:
  public MachineState(API api, byte[] creationBytes)

The bug was miscalculating 'expectedLength'.

Added unit test to cover above.

Also added unit test to cover branching backwards.

Bumped version to 1.3.1 and also fixed pom.xml so it's possible
to call 'mvn clean package' from command line without errors.
2020-04-08 16:53:17 +01:00
catbref
b8311c36ea Bump to version 1.3 2020-04-08 08:15:45 +01:00
catbref
e0fe988b71 Added more blockchain-related FunctionCode tests & improved TestAPI accordingly. 2020-04-07 17:04:01 +01:00
catbref
ca7ec689f7 Pack/unpack MachineState between execution rounds for more realistic testing. Also, better debug output 2020-04-07 17:03:05 +01:00
catbref
f7e50e08cd Add slightly more coverage to OpCodeTests 2020-04-07 17:02:09 +01:00
catbref
0d5ff4de77 Add slightly more coverage to DataOpCodeTests 2020-04-07 17:01:40 +01:00
catbref
c9fdd424e4 Tidy MachineState.Flags class 2020-04-07 17:00:21 +01:00
catbref
18f679e6eb MachineState's initial previousBalance is set to AT's balance at deployment 2020-04-07 17:00:01 +01:00
catbref
d22e16e033 Improve comments in FunctionCode.java 2020-04-07 16:58:21 +01:00
catbref
36c63b0be0 Improved testing.
Rolled the superior blockchain simulating parts from ACCTAPI into
TestAPI.

Tried to replace literal test values with named constants from TestAPI
class, or derived values.

Added some more opcode tests to cover more cases.

Renamed some functions of the form "put something ... in A" to
"put something .. into A" to help distinguish them from
"get ... based on something in A".

Added {GET,SET}_[AB]_IND functions as an addition to the long-winded
GET_A1..A4, SET_B1..B4.

Added more function code tests and separated those tests out into 3
different test classes for manageability.

Possible logic error in PAY_TO_ADDRESS_IN_B and PAY_PREVIOUS_TO_ADDRESS_IN_B
but needs testing!

Improved comments.
2020-04-06 17:37:00 +01:00
catbref
92281a1d04 Conversion to big-endian. Hashing functions use 2 data, not A.
Conversion to big-endian to allow reuse of hash output without
having to swap endian. e.g. saving output of HASH160 into data
segment, and then hashing more of data segment to produce P2SH address.

Also changed hashing functions to fetch data start address and data
byte length from data segment, rather than loading values into A.

Tidied up some tests.
Remove obsolete ACCT test.
2020-03-09 13:29:34 +00:00
catbref
36029c132f Changed FunctionCodes that perform hashes to use variable-length data.
Before, hashing functions (e.g. MD5_A_INTO_B) would hash immediate
data stored in A, putting the result into B.

Also, that hash function would only hash the same number of bits as
the hash output. For example, MD5_A_INTO_B would only hash the
16 bytes in A1 & A2.

Now, hash functions use data-page offset stored in A1 and byte-length
stored in A2.

Renamed HASH160 to RMD160 and created new HASH160 which performs
Bitcoin's double hash of RMD160(SHA256(data)).

Refactored & added tests to cover.
2020-02-28 17:11:53 +00:00
catbref
9a6b49970e Fix typo 2020-02-28 17:11:40 +00:00
catbref
436a65c281 Fix wrong operator when calculating creationBytesLength 2019-11-21 17:28:49 +00:00
catbref
00fd8b040d Updated for Java 11 & other improvements
API:
Added sample AT-emitted transaction types (payment/message).
Maximum number of steps per execution round no longer hard-coded.
API.putTransactionAfterTimestampInA() sets A to zero if no more transactions.
API.putMessageFromTransactionInAIntoB sets B to zero if not a message transaction.
Added some convenience methods.

MachineState:
Added support for minimum activation amount.
Added static method for packing AT into "creation bytes".
No need to store unchanging code in per-height AT state data.

Added support for multiple blockchains to "Timestamp".

General improvements based on Sonarlint suggestions.
General improvements to comments.
Replaced deprecated Byte/Short/Integer/Long constructor call with corresponding .valueOf() call.
Replaced some string concatenations with StringBuilder.

Moved Java-related .gitignore from root to /Java/

Removed .classpath and .project, and added same to .gitignore

Added info on how to add CIYAM AT JAR to other projects.

Updated pom.xml:
Bumped version to 1.2
Bumped Java version from 1.8 to 11
Bumped BouncyCastle from 1.60 to 1.64

Added more tests.
2019-11-20 11:06:57 +00:00
catbref
297ccbdaf6 Added support for execution steps/fees.
Two new API calls:
    getOpCodeSteps(OpCode) : int
    getFeePerStep() : long
This allows API to determine cost per "step" and charge more for (say) function opcodes.

MachineState knows the balance at the end of each execution round,
so now AT's previousBalance is managed by MachineState and added to serialized data.

API calls payCurrentBalanceToB and payPreviousBalanceToB are absorbed into payAmountToB,
and amounts passed are calculated by FunctionCode instead.

Added API call onFinished(long amount, MachineState state) for when AT has finished
so API can return remaining funds (amount) to creator.

Added API call isFirstOpCodeAfterSleeping() : boolean to replace dodgy test of
state.getSteps() == 0 in getRandomUsingTransactionInA().

The API call getCurrentBalance is now used by MachineState to find out AT's balance
at the beginning of execution round. After this, MachineState manages the balance until
the end of execution, whereby the caller can find out the new balance from MachineState.
Corrected some code in FunctionCode to get current balance from MachineState instead in
light of above. (Ditto previousBalance).

Added MAX_STEPS to MachineState to ATs can be made to sleep if they execute too many
steps in one execution round.

Added some pre-execution checks to MachineState.execute() to prevent execution in some
cases, like already finished, or not enough balance to un-freeze, or not reached
required block while sleeping, etc.

Unit tests pass, but there are no test for new steps/fee code yet!
2018-10-12 17:25:10 +01:00
catbref
454d4bed35 OpCode refactoring, versioned constants, refactored tests
API is now an abstract class instead of an Interface. This is to
allow protected methods that give access to package-scoped methods
and variables inside MachineState.

MachineState now supports a different set of constants based on AT
version.

MachineState's methods and variables have had their scopes tightened
up and getters/setters added where appropriate.

MachineState.parseHeader() inlined into the constructor that calls it
so it can set public final variables.

Some reordering and additional comments in MachineState.

OpCode enum entries refactored so that:
a) variables provided via MachineState "state" are not explicitly
passed as well

b) args to each opcode are pre-fetched from the codeByteBuffer before
calling and only need to be cast before use. this comes almost
"for free" thanks to OpCodeParam.fetch

Calling functions from OpCode now cleaner as there's no write-access
to programCounter, only changing codeByteBuffer's position.

Also in OpCode, state.getProgramCounter() now provides a consistent
before-opcode position for branches, jumps, etc.

Lots of repeated code refactored out of unit tests into ExecutableTest
class. ExecutableTest also provides helper methods for examining
post-execution data values, stack positions and entries.
2018-10-05 15:56:32 +01:00
catbref
f0e031599d Initial upload of Java re-implementation
Note that this is unfinished, requiring fee-per-opcode support
and some refactoring.
2018-09-27 13:59:43 +01:00
Ian Knowles
2d7555be98
Merge pull request #2 from spebern/master
correct test 3 output for bor dat
2018-08-26 07:44:53 +00:00
bold
b7aa79d00d correct test 3 output for bor dat 2018-08-26 15:11:59 +08:00
Ian Knowles
2e8cf285d3 Initial documentation added. 2016-02-15 00:44:59 +08:00
Ian Knowles
c7a515ef5e Initial commit 2016-02-15 00:34:00 +08:00