Skip to content

Commit

Permalink
solution: make sure it produces a valid signature for a Sepolia tx
Browse files Browse the repository at this point in the history
  • Loading branch information
splix committed Apr 17, 2024
1 parent 75affa4 commit 89f42a6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,44 @@ class SignerSpec extends Specification {
Hex.encodeHexString(rlp) == "02f876018204d2843b9aca008504a817c800830249f0943535353535353535353535353535353535353535881121d3359738400080c001a0f0b3347ec48e78bf5ef6075b332334518ebc2f90d2bf0fea080623179936382ea05c58c5beeafb2398d5e79b40b320421112a9672167f27e7fc55e76d2d7d11062"
}

def "Sign Sepolia"() {
setup:
TransactionWithGasPriority tx = new TransactionWithGasPriority()
tx.tap {
chainId = 11155111
nonce = 0x0123
maxGasPrice = Wei.ofUnits(20, Wei.Unit.GWEI)
priorityGasPrice = Wei.ofUnits(1, Wei.Unit.GWEI)
gas = 150_000 // 0x0249F0
to = Address.from("0x3535353535353535353535353535353535353535")
value = Wei.ofEthers(1)
accessList = []
}
PrivateKey pk = PrivateKey.create("0x4646464646464646464646464646464646464646464646464646464646464646")

when:
def hash = signer.hash(tx)

then:
Hex.encodeHexString(hash) == "c8dc2cc014237c5a09db43f575b41f89f4f55e4160a3a0e118250f102aec61ab"

when:
def act = signer.sign(tx, pk)
then:
act instanceof SignatureEIP2930
with((SignatureEIP2930)act) {
r.toString(16) == "ea3705d1137256ba5078c2d97a8886ea78e3c9ea4d3ffaa4985220705fdf02e1"
s.toString(16) == "f05771ac81ddb47283f592790db1205c6b321c3cdc5164b16d89898d0802647"
YParity == 1
}

when:
tx.signature = act
def rlp = encoder.encode(tx, true)
then:
Hex.encodeHexString(rlp) == "02f87983aa36a7820123843b9aca008504a817c800830249f0943535353535353535353535353535353535353535880de0b6b3a764000080c001a0ea3705d1137256ba5078c2d97a8886ea78e3c9ea4d3ffaa4985220705fdf02e1a00f05771ac81ddb47283f592790db1205c6b321c3cdc5164b16d89898d0802647"
}

def "extract pubkey from base tx - 0x19442f"() {
setup:
Signature signature = new Signature()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,42 @@ class TransactionEncoderSpec extends Specification {
then:
Hex.encodeHexString(act) == "02f8b101819684ee6b280085134062da9b82c79d947bebd226154e865954a87650faefa8f485d3608180b844095ea7b300000000000000000000000003f7724180aa6b939894b5ca4314783b0b36b329ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc001a0d978ed98e78dd480b2aec86d1521962a8fe4009e44fb19f45b70d8005e602182a0347c933f78131995c1abd07c1d0be67d8f04c2cf99cd79510657e97ead8c1a9f"
}

def "Encode sepolia EIP-1559"() {
setup:
TransactionWithGasPriority tx = new TransactionWithGasPriority()
tx.tap {
chainId = 11155111 // 0xAA36A7
nonce = 0x0123
maxGasPrice = Wei.ofUnits(20, Wei.Unit.GWEI) // 0x04A817C800
priorityGasPrice = Wei.ofUnits(1, Wei.Unit.GWEI) // 0x3B9ACA00
gas = 150_000 // 0x0249F0
to = Address.from("0x3535353535353535353535353535353535353535")
value = Wei.ofEthers(1) // 0x0DE0B6B3A7640000
accessList = []
}
def exp = "" +
"02" + // type
"f6" +
"83" +
"aa36a7" + // chain id
"82" +
"0123" + // nonce
"84" +
"3b9aca00" + // priority gas price
"85" +
"04a817c800" + // max gas price
"83" +
"0249f0" + // gas
"94" +
"3535353535353535353535353535353535353535" + // to
"88" +
"0de0b6b3a7640000" + // value
"80" +
"c0"
when:
def act = encoder.encode(tx, false)
then:
Hex.encodeHexString(act) == exp
}
}

0 comments on commit 89f42a6

Please sign in to comment.