sigma-rust icon indicating copy to clipboard operation
sigma-rust copied to clipboard

Transaction Validation

Open sethdusek opened this issue 1 year ago • 2 comments

Initial stateless validation work (things we can validate without needing blockchain context). Also includes a fix where we were allowing as many as u16::MAX inputs/outputs (65535) when ergo only allows i16::MAX (Short.MaxValue in scala) which is (32767). https://github.com/ergoplatform/ergo/blob/48239ef98ced06617dc21a0eee5670235e362933/ergo-core/src/main/scala/org/ergoplatform/modifiers/mempool/ErgoTransaction.scala#L93

Currently looking into how to source blockchain parameters (storage rent, max TX cost, etc). I don't believe node/explorer has any API for this. To fully validate a TX we also need to allow storage rent transactions which don't seem to be supported yet

sethdusek avatar Dec 28 '23 23:12 sethdusek

Pull Request Test Coverage Report for Build 8953175335

Details

  • 165 of 228 (72.37%) changed or added relevant lines in 15 files are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.1%) to 80.473%

Changes Missing Coverage Covered Lines Changed/Added Lines %
ergo-lib/src/chain/transaction/ergo_transaction.rs 28 29 96.55%
ergotree-interpreter/src/eval/error.rs 0 2 0.0%
ergotree-interpreter/src/eval/scontext.rs 3 5 60.0%
ergotree-interpreter/src/eval/scoll.rs 8 11 72.73%
ergotree-ir/src/mir/value.rs 3 6 50.0%
ergo-lib/src/chain/transaction.rs 7 11 63.64%
ergo-lib/src/chain/transaction/storage_rent.rs 7 21 33.33%
ergo-lib/src/chain/parameters.rs 12 28 42.86%
ergo-lib/src/wallet/tx_context.rs 73 91 80.22%
<!-- Total: 165 228
Files with Coverage Reduction New Missed Lines %
ergotree-interpreter/src/eval/error.rs 2 21.88%
ergotree-ir/src/serialization/types.rs 6 83.28%
<!-- Total: 8
Totals Coverage Status
Change from base Build 8951357735: 0.1%
Covered Lines: 10723
Relevant Lines: 13325

💛 - Coveralls

coveralls avatar Dec 29 '23 00:12 coveralls

Should be good to go now! Some notes:

  • This PR despite the usual unit tests was tested using ergovalidation which downloads transactions from node (requires extra indexing to be enabled) and validates them. After fixing some script bugs we're now down to 15 transactions on mainnet that sigma-rust rejects, all of which rely on buggy behavior from v4.0 that no longer holds in v5.0, including CONTEXT.selfBoxIndex being -1 and sigmaProp(sigmaProp(true)) being allowed. I believe fixing these (and adding version-specific actions to ergotree-interpreter) is out of scope for this PR. Gist of failing transactions

  • I had to bump rust version since sigma-rust no longer builds as some dependencies don't support rust 1.64 anymore. Clippy rejection seems to be related and should be ignored for now

  • There are some limitations still in interpreter. The biggest one is that atLeast(0, ...) isn't supported (I plan on addressing this separately in another PR, but I fixed atLeast(1, ...) not being supported in this PR).

  • There are some breaking changes in this PR, namely ErgoStateContext now also requiring Parameters. I believe this is an acceptable trade-off even if parameters aren't needed for signing. Later when sigma-rust adds support for costing we could use Parameters to calculate costs during signing

  • Also fixed quadratic scaling in TransactionContext::new old: txcontextold new: txcontextnew

sethdusek avatar Mar 18 '24 11:03 sethdusek

Please fix linter issues

kushti avatar Apr 26 '24 11:04 kushti