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 bug: keccak256(rlpTx) for signing eip-155 #16

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion ci-test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

set -ex
nohup anvil --balance 1000000 &
nohup anvil --base-fee=0 --balance=1000000 &
dub test
dub run deth:devtest
5 changes: 5 additions & 0 deletions source/deth/rpcconnector.d
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ unittest

Transaction tx = {
to: bob,
gas: 21_000.wei,
gasPrice: 0.wei,
value: 16.wei,
data: cast(bytes) "\xdd\xdd\xdd\xdd Dlang - Fast code, fast.",
};
Expand Down Expand Up @@ -332,7 +334,10 @@ unittest
assert(conn.accounts[0] == alice);

Transaction tx = {
from: alice,
to: bob,
gas: 21_000.wei,
gasPrice: 0.wei,
value: 16.wei,
data: cast(bytes) "\xdd\xdd\xdd\xdd Dlang - Fast code, fast.",
chainid: conn.net_version.to!ulong,
Expand Down
9 changes: 5 additions & 4 deletions source/deth/wallet.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ module deth.wallet;

import std.experimental.logger;
import std.exception : enforce;
import secp256k1 : secp256k1;
import deth.util : Address, Hash, bytes, convTo, Transaction, ox;
import deth.util.rlp : rlpEncode, cutBytes;
import deth.util.types;
import keccak : keccak256;
import secp256k1 : secp256k1;

/// struct to store several private keys in a single wallet
struct Wallet
Expand Down Expand Up @@ -58,8 +60,6 @@ struct Wallet
/// Returns: rlp encoded signed transaction
bytes signTransaction(const Transaction tx, Address signer = Address.init) @safe pure
{
import keccak : keccak256;
import deth.util.types;

if (!tx.from.isNull)
{
Expand All @@ -73,10 +73,10 @@ struct Wallet
auto c = addrs[signer];
bytes rlpTx = tx.serialize.rlpEncode;
debug logf("Rlp encoded tx %s", rlpTx.toHexString.ox);
auto signature = c.sign(rlpTx);
bytes rawTx;
if (tx.chainid.isNull)
{
auto signature = c.sign(rlpTx);
ulong v = 27 + signature.recid;
rawTx = rlpEncode(
tx.serialize ~ v.convTo!bytes.cutBytes
Expand All @@ -85,6 +85,7 @@ struct Wallet
else
{
/// eip 155 signing
auto signature = c.sign(keccak256(rlpTx));
ulong v = signature.recid + tx.chainid.get * 2 + 35;
rawTx = rlpEncode(tx.serialize[0 .. $ - 3] ~ [
v.convTo!bytes.cutBytes, signature.r.cutBytes,
Expand Down
Loading