Skip to content
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

Fix the decoding of unsigned transactions #243

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/eth/tx/eip1559.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,16 @@ def decode(hex)
# last but not least, set the type.
@type = TYPE_1559

# recover sender address
v = Chain.to_v recovery_id, chain_id
public_key = Signature.recover(unsigned_hash, "#{r.rjust(64, "0")}#{s.rjust(64, "0")}#{v.to_s(16)}", chain_id)
address = Util.public_key_to_address(public_key).to_s
@sender = Tx.sanitize_address address
unless recovery_id.nil?
# recover sender address
v = Chain.to_v recovery_id, chain_id
public_key = Signature.recover(unsigned_hash, "#{r.rjust(64, "0")}#{s.rjust(64, "0")}#{v.to_s(16)}", chain_id)
address = Util.public_key_to_address(public_key).to_s
@sender = Tx.sanitize_address address
else
# keep the 'from' field blank
@sender = Tx.sanitize_address nil
end
end

# Creates an unsigned copy of a transaction payload.
Expand Down
15 changes: 10 additions & 5 deletions lib/eth/tx/eip2930.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,16 @@ def decode(hex)
# last but not least, set the type.
@type = TYPE_2930

# recover sender address
v = Chain.to_v recovery_id, chain_id
public_key = Signature.recover(unsigned_hash, "#{r.rjust(64, "0")}#{s.rjust(64, "0")}#{v.to_s(16)}", chain_id)
address = Util.public_key_to_address(public_key).to_s
@sender = Tx.sanitize_address address
unless recovery_id.nil?
# recover sender address
v = Chain.to_v recovery_id, chain_id
public_key = Signature.recover(unsigned_hash, "#{r.rjust(64, "0")}#{s.rjust(64, "0")}#{v.to_s(16)}", chain_id)
address = Util.public_key_to_address(public_key).to_s
@sender = Tx.sanitize_address address
else
# keep the 'from' field blank
@sender = Tx.sanitize_address nil
end
end

# Creates an unsigned copy of a transaction payload.
Expand Down
2 changes: 0 additions & 2 deletions lib/eth/tx/legacy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,11 @@ def decode(hex)
_set_signature(v, r, s)

unless chain_id.nil?

# recover sender address
public_key = Signature.recover(unsigned_hash, "#{r.rjust(64, "0")}#{s.rjust(64, "0")}#{v}", chain_id)
address = Util.public_key_to_address(public_key).to_s
@sender = Tx.sanitize_address address
else

# keep the 'from' field blank
@sender = Tx.sanitize_address nil
end
Expand Down
13 changes: 13 additions & 0 deletions spec/eth/tx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,17 @@
expect(tx.chain_id).to eq 56
end
end

describe '.decode an unsigned transaction' do
it "keeps the 'from' field blank" do
raw = "0x02f0050584b2d05e00851010b872008303841494caedbd63fb25c3126bfe96c1af208e4688e9817e87f6a3d9c63df00080c0"
tx = Tx.decode raw

expect(tx.signature_y_parity).to eq nil
expect(tx.signature_r).to eq 0
expect(tx.signature_s).to eq 0

expect(tx.sender).to eq ""
end
end
end