statechannels / dispute-game

A prototype of the dispute game in typescript and solidity.
MIT License
9 stars 0 forks source link

Use only index and node hashes for a witness proof #28

Closed lalexgap closed 3 years ago

lalexgap commented 3 years ago

The proof format we're using from merkle-tools currently encodes the path directions in the proof data. RIght now that's :

[{right: 'f9e2eaaa42d9fe9e558a9b8ef1bf366f190aacaa83bad2641ee106e9041096e4'},
{left: '29df505440ebe180c00857e92b0694c56a33762b08944472492b0cbf6ec607e3'}]

but we could also get it in binary which looks like:

// With asBinary set to true, an array of Buffers is returned 
// 0x00 indicated 'left', 0x01 indicates 'right'
// example: 
// proof == [
//   <Buffer 01>,
//   <Buffer 09096dbc49b7909917e13b795ebf289ace50b870440f10424af8845fb7761ea5>,
//   <Buffer 01>
//   <Buffer ed2456914e48c1e17b7bd922177291ef8b7f553edf1b1f66b6fc1a076524b22f>,
//   <Buffer 00>
//   <Buffer eac53dde9661daf47a428efea28c81a021c06d64f98eeabbdcff442d992153a8>
// ]

Instead of having a left/right property (or a boolean flag) I think our proof could just be

WitnessProof = {
  witness: Hash;
  nodes: Hash[];
  index: number;
};

We can use the index to calculate the path which is just the path information expressed as a uint. I think this would be more efficient than accepting an array of directions or some other format?

That does mean converting to and from the format for merkle-tools but it was pretty easy to handle that.

andrewgordstewart commented 3 years ago

As mentioned in Slack, we would want to use a type like this when passing data to a solidity contract, for efficiency.

WitnessProof = {
  witness: Hash;
  nodes: Hash[];
  index: number;
};

so I give a 👍 to this idea