Skip to content

mini-rollup of several issues #498

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 6 commits into from
Mar 23, 2022
Merged

mini-rollup of several issues #498

merged 6 commits into from
Mar 23, 2022

Conversation

mloit
Copy link
Contributor

@mloit mloit commented Mar 23, 2022

I've consolidated a number of smaller issues into one here, for ease

  1. Re-instates PR Fix decoding dynamic tuples and arrays with dynamic subtypes within tuples #440
  2. Patches 440 so that it doesn't break by replacing the fallthrough with the expected result
    -- closes ABIDecoder.decodeSignleType() [sic] fails to decode dynamic arrays in structs #429
  3. Fixes function name typo identified in 440 (all calling instances fixed as well)
  4. fixes TransactionOptions using the wrong key to decode callOnBlock (was using nonce)
    -- this exposed a bug in the TransactionOptions decoding
  5. fixes decode logic in TransactionOptions to properly work if a given key is not present
    -- as it was it would throw an invalid value error, instead of falling to the provided default in the if let
    -- consequently this probably fixes Invalid value from Ethereum node #469
  6. fixes an unsafe forced unwrap in the signing routines in EthereumTransaction

mloit added 6 commits March 22, 2022 15:49
… falling through caused erroneous decoding.
As it was it would throw a decode error instead of returning nil
this was exposed when I fixed the coding key for callOnBlock, which typically isn't present
changed 'Signle' to 'Single'
corrected all calling occurences
@@ -117,7 +117,7 @@ extension ABIDecoder {
var subpointer: UInt64 = 32;
var toReturn = [AnyObject]()
for _ in 0 ..< length {
let (v, c) = decodeSignleType(type: subType, data: elementItself, pointer: subpointer)
let (v, c) = decodeSingleType(type: subType, data: elementItself, pointer: subpointer)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it just me, or these lines are equal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

spelling correction from gn to ng in Single. it's hard to spot

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, now i see

@@ -52,13 +52,13 @@ extension TransactionOptions: Decodable {

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
if let gasLimit = try decodeHexToBigUInt(container, key: .gas) {
if let gasLimit = try decodeHexToBigUInt(container, key: .gas, allowOptional:true) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

While working with Web3+structures source i'm kind of confused:

As i see this lib took it's struct from web3.js, where some struct fields are optional. But at the same time i've found Eth JSON-RPC specification Transaction scheme where none of that are optional. It looks kind official tho. I've lack of experience in Ethereum itself, so maybe you're could explain to me why there's such ignorance of specification happening even in kind of it's official implementation like web3.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the problem here is that to code expects to drop down to provide a default if the call to decodeHexToBigUInt returns with nil. decodeHexToBigUInt will throw Web3Error.dataError instead of return nil unless allowOptional is set to true. So this if let is meaningless without the allowOptional: true.

On a larger scope, yes nonce should never be optional, I was not trying to address that issue. That should be handled at a higher level. The input here could come from a number of sources, where nonce may no be known yet. The same goes for the various gas values, as if this is a 1559 transaction those values may not exist. Furthermore, if the transaction is pending and not mined yet, those values may also not be present, as they are not known yet. Issue #469

self.gasLimit = .manual(gasLimit)
} else {
self.gasLimit = .automatic
}

if let gasPrice = try decodeHexToBigUInt(container, key: .gasPrice) {
if let gasPrice = try decodeHexToBigUInt(container, key: .gasPrice, allowOptional:true) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here's i see that optionality happening since this struct should work with both EIP-1559 Transactions and legacy transaction where the first one don't have that field already, am i correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as my previous comment

@yaroslavyaroslav yaroslavyaroslav merged commit 0016aee into web3swift-team:develop Mar 23, 2022
@mloit mloit deleted the feature/bug-fix-rollup branch March 23, 2022 17:03
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.

Invalid value from Ethereum node ABIDecoder.decodeSignleType() [sic] fails to decode dynamic arrays in structs
2 participants