Skip to content

[ETCM-921] transaction with access list #1094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 23, 2021

Conversation

strauss-m
Copy link
Contributor

@strauss-m strauss-m commented Aug 11, 2021

Make SignedTransaction wrap Transaction to allow TypedTransactions.

This PR is split from #1061

Included in this branch are:

  • ETCM-911: new Typed Transaction envelop
  • ETCM-921: new Type 1 transaction (payload + rlp encoder/decoder)

Follow up tickets are expected:

  • ETCM-1095: receipt implementation
  • ETCM-1096: signature/validation process enhancement for EIP-2930

.fromBytes(
ByteString(
Hex.decode(
"c9519f4f2b30335884581971573fadf60c6204f59a911df35ee8a540456b266032f1e8e2c5dd761f9e4f88f41c8310aeaba26a8bfcdacfedfa12ec3862d3752101"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we know this value is correct? Is this specified somewhere in the EIP?

Copy link
Contributor Author

@strauss-m strauss-m Aug 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! It would probably make sense to add a github link to those tests for posterity in a comment (pointing to a concrete commit, rather than master, in case they get moved)

case r: RLPList if r.items.isEmpty => AccessListItem(null, List.empty)

case RLPList(rlpAddress, rlpStorageKeys: RLPList) =>
val address = rlpAddress.decodeAs[Address]("address ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a space in "address "

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, fixed

@strauss-m strauss-m force-pushed the feature/etcm-921_transaction_with_access_list branch 5 times, most recently from 8217580 to 8e3dbef Compare August 17, 2021 19:16
@lukasz-golebiewski lukasz-golebiewski self-requested a review August 17, 2021 21:23
Copy link
Contributor

@lukasz-golebiewski lukasz-golebiewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall, aside from a few remarks

* @param prefixedRLPEncodeable the RLPEncodable to prefix with
*/
case class PrefixedRLPEncodable(prefix: Byte, prefixedRLPEncodeable: RLPEncodeable) extends RLPEncodeable {
require(prefix <= 0x07f, "prefix should be lower than 0x7f")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scala> 0x07f.toByte
val res0: Byte = 127

scala> 128.toByte <= 0x7f.toByte
val res3: Boolean = true

Looks like all Bytes are smaller than 0x7f so it makes more sense to check whether prefix is larger than 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, I'll change the check and add proper testing

def toTypedRLPEncodables: Seq[RLPEncodeable] =
encodables match {
case Seq() => Seq()
case Seq(RLPValue(v), rlpList: RLPList, tail @ _*) if v.length == 1 && v.head < 0x7f =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would make sense not to repeat the magic 0x7f in multiple places but putting it for example in a wrapper value class for Byte?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, I've extracted the magic number and added the proposed wrapper

@strauss-m strauss-m force-pushed the feature/etcm-921_transaction_with_access_list branch from d54774a to d161ae4 Compare August 19, 2021 08:31
* @param prefixedRLPEncodeable the RLPEncodable to prefix with
*/
case class PrefixedRLPEncodable(prefix: Byte, prefixedRLPEncodeable: RLPEncodeable) extends RLPEncodeable {
require(prefix >= 0, "prefix should be in the range [0; 0x7f]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this up to 0xFF?

Copy link
Contributor Author

@strauss-m strauss-m Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0x7f is the limit for two reasons:

  • EIP-2718: TransactionType is a positive unsigned 8-bit number between 0 and 0x7f that represents the type of the transcation
  • rlp encoding spec: for a single byte whose value is in the [0x00, 0x7f] range, that byte is its own RLP encoding

That's what allows us to consider a single RLPValue [0; 0x7f] as a single raw byte transaction type (and vice-versa)

Since Byte is a signed type, the range [0; 0x7f] check become a simple positive condition.


case RLPList(rlpAddress, rlpStorageKeys: RLPList) =>
val address = rlpAddress.decodeAs[Address]("address")
val storageKeys = fromRlpList[BigInt](rlpStorageKeys).toList
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding this BigInt type - were you able to verify if this is good enough? maybe a block from ETC mainnet with a typed transaction and the access list populated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't try to find one, but it feel like a good real-life test case until we connect to mainnet.
I'll give it a look.

Concerning the StorageKey type, I've seen both BigInt and UInt256 in mantis code, as well as Hash (byte[32]) in go-ethereum. Maybe we should introduce (in another ticket ?) a specific StorageKey type similar to the Address one, with a 32 bytes length

case _ => throw new RuntimeException("Cannot decode SignedTransactions")
}
}

implicit class SignedTransactionRlpEncodableDec(val rlpEncodeable: RLPEncodeable) extends AnyVal {

// scalastyle:off method.length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a matching :on in the file? can't find it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I was thinking that the style annotation was on a per-method scope.
Maybe the best way is to actually split the method ?
I have mixed feeling about this: on one hand, the method is really long, but on the other one, it's quite straite-forward to read, as the lenght is due to the case class formatting, not actual statements.
However, once we start adding new transactions, we'll need to split it, so maybe doing it now is a good time. Do you have any preference (split vs scalastyle:off) ?

// TODO ReceiptSpec
// TODO decode string to case class
// TODO adjust runVM in ledger
// TODO align how geth and besu treat typed transactions when sent via rpc before magneto HF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe drop these? no need to have the plan in develop

Copy link
Contributor

@dzajkowski dzajkowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@strauss-m strauss-m force-pushed the feature/etcm-921_transaction_with_access_list branch from 11d736c to 46260ae Compare August 19, 2021 17:20
@strauss-m strauss-m force-pushed the feature/etcm-921_transaction_with_access_list branch from 46260ae to c52e95a Compare August 22, 2021 11:46
@strauss-m strauss-m merged commit 332959a into develop Aug 23, 2021
@strauss-m strauss-m deleted the feature/etcm-921_transaction_with_access_list branch August 23, 2021 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants