dusk-blockchain icon indicating copy to clipboard operation
dusk-blockchain copied to clipboard

Store transaction outputs with correct `pos`

Open vlopes11 opened this issue 2 years ago • 0 comments

Describe what you want implemented The transaction outputs should be stored in the chain with their correct post-execution position index.

Describe "Why" this is needed This is needed to increase the clarity of the protocol and decouple the chain from implementation details of Rusk.

Currently, we are using u64::MAX in the stored positions, expecting these to be replaced by Rusk.

Creating the note https://github.com/dusk-network/phoenix-core/blob/efdbc4adbaad7c9234dbd81977ad0dc69f36600f/src/note.rs#L169-L170

Replacing the index https://github.com/dusk-network/Poseidon252/blob/f6c1e914956d115858cc796fbaaa3063e763de56/src/tree.rs#L85

This is an implementation detail. Whatever is stored in the blockchain should reflect its state. Meaning: the outputs in the block should be in the same state that composes the state root (e.g. final index in the tree).

As result, the block payload contains outputs with masked positions, when these are intended to be public (and easily checked by third parties).

This implementation detail had some implications on the general design. Currently we are using this magic constant u64::MAX as part of the txid:

https://github.com/dusk-network/wallet-core/blob/42c86072f71fd8c8303d7ba2b5c1068fe0ef4e0f/src/tx.rs#L260-L262

https://github.com/dusk-network/phoenix-core/blob/efdbc4adbaad7c9234dbd81977ad0dc69f36600f/src/note.rs#L356

The txid is committed to the block, and uses an information that doesn't belong to the block (u64::MAX). This greatly couples the protocol to the implementation details of Rusk, and can be easily fixed by removing pos from txid arguments.

Describe alternatives you've considered Leaving u64::MAX in the block will make the protocol less clear, will show bogus data on the block explorer and will couple its logic to implementation details.

Additional context A block verification should rely only in its data, and nothing external. If we are to depend on coupled logic, we cannot query the outputs of a block from a state and expect them exactly as they were inserted.

vlopes11 avatar Mar 23 '22 15:03 vlopes11