bigchaindb / bigchaindb/bigchaindb

Conditional storing of asset could be problematic (?)

Open
#2,008 4 comments 0 reactions 2 assignees Claimed by @kansi View on GitHub
BUG question
Dominant language
Python
Stars
4k
Forks
758
PR merge metrics
No merged PRs in 30d

Description

_Noting this issue now as a reminder to verify this via a test. The test(s) should verify that upon storing transactions with asset data evaluating to `False` (e.g.: `{}`, `None`), the original transaction is accurately re-constructed._

I wonder whether not storing the asset on the basis of the `data` field evaluating to `False` can be problematic, since multiple values evaluate to `False` and these different values would yield different transactions with respect to cryptographic fields (hash, fulfillments).

https://github.com/bigchaindb/bigchaindb/blob/tendermint/bigchaindb/tendermint/lib.py#L51-L52:

```python
class BigchainDB(Bigchain):

def store_transaction(self, transaction):
if transaction['operation'] == 'CREATE':
asset = transaction.pop('asset')
asset['id'] = transaction['id']
if asset['data']:
backend.query.store_asset(self.connection, asset)
```

As an example, two transactions only differing with the asset data being `None` versus `{}` will have different hashes and fulfillments.

```python
In [28]: tx1.to_dict()
Out[28]:
{'asset': {'data': None},
'id': '3babb208ffc9b0c4fe64e3c04e9fe21173b55f5cbb6c4665323a4d3d7abe8762',
'inputs': [{'fulfillment': 'pGSAIL0E1ugBe3C7J6W3dcUf16B3OQD4UtE6ycCbeITQWibygUCGcb4Ckp7jeTbLbYdvuDEJ3uIzM35Q0j9KrrrToC2bN9ihikZOEDQakpuuI00vyDC0eclKm3y8kft2owxrPpsD',
'fulfills': None,
'owners_before': ['DirLRivNZcokoLS2y5pxEH2AFjrAjboPcrKFRd1LvS5F']}],
'metadata': None,
'operation': 'CREATE',
'outputs': [{'amount': '1',
'condition': {'details': {'public_key': 'DirLRivNZcokoLS2y5pxEH2AFjrAjboPcrKFRd1LvS5F',
'type': 'ed25519-sha-256'},
'uri': 'ni:///sha-256;UyhI2q3RmSrtB92pizff6TprpJm1nA7B9Q_m41GXgrY?fpt=ed25519-sha-256&cost=131072'},
'public_keys': ['DirLRivNZcokoLS2y5pxEH2AFjrAjboPcrKFRd1LvS5F']}],
'version': '1.0'}
```

```python
In [29]: tx2.to_dict()
Out[29]:
{'asset': {'data': {}},
'id': 'cd65c741815f4af62d482ee9b0af11fefe5a4f5c2e45e834f937dc38b163afec',
'inputs': [{'fulfillment': 'pGSAIL0E1ugBe3C7J6W3dcUf16B3OQD4UtE6ycCbeITQWibygUBWKBW5XVyd-EQeq5cfaXe2dCvammK5mskH7cDvduHtU3tEW2TxQWnJpSQZWdQz7mtex57dZ5wyddm9fsqDos0A',
'fulfills': None,
'owners_before': ['DirLRivNZcokoLS2y5pxEH2AFjrAjboPcrKFRd1LvS5F']}],
'metadata': None,
'operation': 'CREATE',
'outputs': [{'amount': '1',
'condition': {'details': {'public_key': 'DirLRivNZcokoLS2y5pxEH2AFjrAjboPcrKFRd1LvS5F',
'type': 'ed25519-sha-256'},
'uri': 'ni:///sha-256;UyhI2q3RmSrtB92pizff6TprpJm1nA7B9Q_m41GXgrY?fpt=ed25519-sha-256&cost=131072'},
'public_keys': ['DirLRivNZcokoLS2y5pxEH2AFjrAjboPcrKFRd1LvS5F']}],
'version': '1.0'}
```
```python
In [34]: tx1.id == tx2.id
Out[34]: False

In [35]: tx1.inputs[0].fulfillment == tx2.inputs[0].fulfillment
Out[35]: False

In [36]: tx1.id
Out[36]: '3babb208ffc9b0c4fe64e3c04e9fe21173b55f5cbb6c4665323a4d3d7abe8762'

In [37]: tx2.id
Out[37]: 'cd65c741815f4af62d482ee9b0af11fefe5a4f5c2e45e834f937dc38b163afec'

In [39]: tx1.inputs[0].fulfillment.serialize_uri()
Out[39]: 'pGSAIL0E1ugBe3C7J6W3dcUf16B3OQD4UtE6ycCbeITQWibygUCGcb4Ckp7jeTbLbYdvuDEJ3uIzM35Q0j9KrrrToC2bN9ihikZOEDQakpuuI00vyDC0eclKm3y8kft2owxrPpsD'

In [40]: tx2.inputs[0].fulfillment.serialize_uri()
Out[40]: 'pGSAIL0E1ugBe3C7J6W3dcUf16B3OQD4UtE6ycCbeITQWibygUBWKBW5XVyd-EQeq5cfaXe2dCvammK5mskH7cDvduHtU3tEW2TxQWnJpSQZWdQz7mtex57dZ5wyddm9fsqDos0A'
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.