Comments (11)
@debris can you have a look at this when you have a free moment. thanks
from parity-bridge.
bytes message
is always:
32 bytes - length of the content
20 bytes - address
32 bytes - uint
32 bytes - hash
mload(add(message, 0x20))
just skips the length (since we know it anyway)
The error is in:
value := mload(add(message, 0x40))
actually, cause we skip len (32b) and address (32b instead of 20b) unless we expect address to be padded to 32bytes (which seems to be missing in docs).
from parity-bridge.
address is currently not padded to 32bytes. see
from parity-bridge.
@tomusdrw thanks for taking a look at this!
i didn't know that the first 32bytes of a bytes
represent the length. makes total sense.
what confuses me is that this test
parity-bridge/truffle/test/home.js
Line 85 in b796746
only works if i modify the assembly to this:
parity-bridge/contracts/bridge.sol
Line 119 in b796746
if i modify the assembly to:
assembly {
// skip 32 bytes message length
recipient := mload(add(message, 32))
value := mload(add(message, 52))
hash := mload(add(message, 84))
}
which i'd expect to be correct
then what gets loaded into recipient
is wrong and the test fails at:
parity-bridge/truffle/test/home.js
Line 129 in b796746
from parity-bridge.
i think we need to pad address to 32 bytes since mload
seems to always load 32 bytes
from parity-bridge.
what happens here is probably that bytes 20-32 are all 0 since length is 84
.
thus reading recipient from bytes 20-52 (32 bytes starting at 20) reads 12 zero bytes followed by the 20 recipient bytes which get correctly read as the recipient address.
we could leave it like this since length is always 84
but it would probably be cleaner to pad recipient to 32
from parity-bridge.
Right. That's correct. mload
loads 32 bytes and just uses last 20 for address.
// skip 32 bytes message length
recipient := mload(add(message, 20))
value := mload(add(message, 52))
hash := mload(add(message, 84))
That should work, right? We re-use some bytes from length, but it doesn't matter cause they are discarded anyway.
Otherwise we need to pad address to 32-bytes.
from parity-bridge.
That should work, right? We re-use some bytes from length, but it doesn't matter cause they are discarded anyway.
yes, that works!
Otherwise we need to pad address to 32-bytes.
that would be a bit clearer imho
from parity-bridge.
how should we resolve this?
- re-use some bytes from length and document it thoroughly
- pad address to 32-bytes
fine with both. i like 2 a bit more
from parity-bridge.
I prefer the first one to reduce the gas cost by a tiny bit. That said we should heavily test that function to make sure it's correct. I would also add length assertion at the top if it's not there yet, so that a padded address is not accepted.
from parity-bridge.
I prefer the first one to reduce the gas cost by a tiny bit. That said we should heavily test that function to make sure it's correct. I would also add length assertion at the top if it's not there yet, so that a padded address is not accepted.
ok!
already added a length assertion
from parity-bridge.
Related Issues (20)
- 'ethereum-based blockchain' HOT 1
- build failed on windows 10 HOT 4
- build failed on Ubuntu 16.04 HOT 4
- No example directory in the repository HOT 1
- Compiling Bugs: mismatched compiled_contracts file name HOT 3
- wrong assumption HOT 1
- Impossible to deploy the bridge HOT 6
- Update documentation of the bridge
- MainBridge's withdraw funcion can lead to bridge funds drainage HOT 2
- send_transaction_with_confirmation fails at parity-bridge-deploy HOT 2
- Arbitrary message passing HOT 2
- after installing solc having the error solc --version failed to run HOT 2
- Ubuntu 16.04 compilation issue HOT 3
- build failed (bridge contracts v0.5.0) HOT 1
- Blocknumber polling appears to be broken? HOT 1
- Update dependencies HOT 1
- replace `error-chain`
- SendTransactionWithReceipt: sending transaction failed due to timeout HOT 1
- Stop relying on parity-ethereum's key management HOT 1
- Testing Bridge HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parity-bridge.