bitshares-core
bitshares-core copied to clipboard
sizeof() can return a platform-dependent result
As stated here: https://github.com/bitshares/bitshares-core/issues/995#issuecomment-450638713 , sizeof() can return a platform-dependent result. This can endanger consensus, if one node rejects a (block | transaction) due to size, but another accepts it.
In all code that limits or rejects due to size, a platform-independent size must be calculated.
Impacts
- [ ] API (the application programming interface)
- [ ] Build (the build process or something prior to compiled code)
- [ ] CLI (the command line wallet)
- [ ] Deployment (the deployment process after building such as Docker, Travis, etc.)
- [ ] DEX (the Decentralized EXchange, market engine, etc.)
- [x] P2P (the peer-to-peer network for transaction/block propagation)
- [ ] Performance (system or user efficiency, etc.)
- [x] Protocol (the blockchain logic, consensus, validation, etc.)
- [ ] Security (the security of system or user data, etc.)
- [ ] UX (the User Experience)
- [ ] Other (please add below)
Steps To Reproduce tbd
Expected Behavior Blocks or transactions should be accepted or rejected independent of the node platform.
CORE TEAM TASK LIST
- [ ] Evaluate / Prioritize Bug Report
- [ ] Refine User Stories / Requirements
- [ ] Define Test Cases
- [ ] Design / Develop Solution
- [ ] Perform QA/Testing
- [ ] Update Documentation
64bit Linux: The size of a(n) int is: 4 The size of a(n) long is: 8 The size of a(n) long long is: 8 The size of a(n) unsigned long is: 8 The size of a(n) void* is: 8 The size of a(n) std::string is: 32
64bit macOS: The size of a(n) int is: 4 The size of a(n) long is: 8 The size of a(n) long long is: 8 The size of a(n) unsigned long is: 8 The size of a(n) void* is: 8 The size of a(n) std::string is: 24
64bit WIndows 10 The size of a(n) int is: 4 The size of a(n) long is: 4 The size of a(n) long long is: 8 The size of a(n) unsigned long is: 4 The size of a(n) void* is: 4 The size of a(n) std::string is: 28
Related PR: https://github.com/bitshares/bitshares-fc/pull/100
From what I can see, blocks are rejected if fc::raw::pack_size is greater than global_properties.parameters.maximum_block_size. Need to verify that pack_size reports that the same block is the same size regardless of platform, which I believe to be the case, but will investigate.
Transactions can also be rejected if fc::raw::pack_size is greater than global_properties.maximum_transaction_size. As above, we need to verify that packed_size reports the same number regardless of platform. See #1573
E.G. code in memo.cpp
: https://github.com/bitshares/bitshares-core/blob/173ff3d27a4ca076a62bffdcd22d8f315b239a68/libraries/protocol/memo.cpp#L76-L90
BTW the combination of a (uint32_t &)
conversion and a native_to_little()
call looks suspicious.