Xahau / xahaud

Codebase for Xahaud - The consensus, RPC & blockchain app for the Xahau network.
https://xahau.network
ISC License
23 stars 11 forks source link

Buffer crashes QUICKJS #314

Closed WietseWind closed 4 months ago

WietseWind commented 4 months ago

When doing anything with Buffer no Hook tx can't be executed anymore.

Once this happened, no further HookSet without the Buffer... code works anymore.

E.g.:

trace("aaaa", Buffer.from('abc').toString('hex'), false)

TX error:

    engine_result: 'tecHOOK_REJECTED',
    engine_result_code: 153,
    engine_result_message: 'Rejected by hook on sending or receiving account.',

Trace log:

Could not create QUICKJS instance (expr eval failure). `Hook(0)` [size=7]. [function bytecode]
sublimator commented 4 months ago

Ah yeah, Buffer is nodejs only, right, but its attempted usage will be a common occurrence ?

tequdev commented 4 months ago

We can use Uint8Array, ArrayBuffer, DataView, etc instead of Buffer.

WietseWind commented 4 months ago

@tequdev We can, but we're trying to create an environment most devcs will be able to use, and using Buffer is much more straight forward for most than for us more experienced node/backend/frontend/bin/hex/... devs.

You'll see any dev use Buffer.from(something, someencoding).toString(someotherencoding) before you'll see them use any of the alternatives.

I think when looking at these issues/findings/supported methods/classes/... we should always consider the third party dev workflow. We started this to offer a (more expensive in terms of computation and fees, but...) simple way for the average dev to get started with Hooks and some logic. Which means asking them to make the least amount of possible changes to their workflow / the least amount of Hook specific things learn about the JS environment.

So unless if something is too expensive / dangerous / tricky (eval, defining FNs, yielding, async) - in which case we shouldn't offer support, we should always consider the random-dev workflow over possible available workarounds.

WietseWind commented 4 months ago

Closing, Buffer not part of QuickJS