Skip to content

Commit

Permalink
Merge pull request #7 from hotid/master
Browse files Browse the repository at this point in the history
fix address crc16 calculation
  • Loading branch information
xssnick authored May 5, 2022
2 parents da63e99 + 60557b3 commit a2f2d13
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
9 changes: 4 additions & 5 deletions address/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package address
import (
"encoding/base64"
"encoding/binary"

"github.com/howeyc/crc16"
"errors"
"github.com/sigurn/crc16"
)

type Address struct {
Expand Down Expand Up @@ -37,9 +37,8 @@ func ParseAddr(addr string) (*Address, error) {
}

checksum := data[len(data)-2:]
if crc16.ChecksumCCITTFalse(data[:len(data)-2]) != binary.LittleEndian.Uint16(checksum) {
// TODO: correct crc
// return nil, errors.New("invalid address")
if crc16.Checksum(data[:len(data)-2], crc16.MakeTable(crc16.CRC16_XMODEM)) != binary.BigEndian.Uint16(checksum) {
return nil, errors.New("invalid address")
}

return a, nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/xssnick/tonutils-go
go 1.18

require (
github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6
github.com/oasisprotocol/curve25519-voi v0.0.0-20220328075252-7dd334e3daae
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3
)

require (
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6 h1:IIVxLyDUYErC950b8kecjoqDet8P5S4lcVRUOM6rdkU=
github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6/go.mod h1:JslaLRrzGsOKJgFEPBP65Whn+rdwDQSk0I0MCRFe2Zw=
github.com/oasisprotocol/curve25519-voi v0.0.0-20220328075252-7dd334e3daae h1:7smdlrfdcZic4VfsGKD2ulWL804a4GVphr4s7WZxGiY=
github.com/oasisprotocol/curve25519-voi v0.0.0-20220328075252-7dd334e3daae/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s=
github.com/xssnick/tonutils-go v0.0.0-20220428130111-4d7ef664ac5c h1:hUYe6h+g9yqGBu2DpNC0DbAXKnaHKY7Ka/9A/rk/1Dk=
github.com/xssnick/tonutils-go v0.0.0-20220428130111-4d7ef664ac5c/go.mod h1:7ZlB7UxmA9SOfa5ZuPsSzysA9UriYds3WCgJk4WZOWI=
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 h1:aQKxg3+2p+IFXXg97McgDGT5zcMrQoi0EICZs8Pgchs=
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3/go.mod h1:9/etS5gpQq9BJsJMWg1wpLbfuSnkm8dPF6FdW2JXVhA=
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 h1:S25/rfnfsMVgORT4/J61MJ7rdyseOZOyvLIrZEZ7s6s=
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/sys v0.0.0-20220325203850-36772127a21f h1:TrmogKRsSOxRMJbLYGrB4SBbW+LJcEllYBLME5Zk5pU=
Expand Down
4 changes: 2 additions & 2 deletions ton/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"math/big"

"github.com/howeyc/crc16"
"github.com/sigurn/crc16"
"github.com/xssnick/tonutils-go/address"
"github.com/xssnick/tonutils-go/liteclient"
"github.com/xssnick/tonutils-go/liteclient/tlb"
Expand Down Expand Up @@ -64,7 +64,7 @@ func (c *APIClient) RunGetMethod(ctx context.Context, blockInfo *tlb.BlockInfo,

// https://github.com/ton-blockchain/ton/blob/24dc184a2ea67f9c47042b4104bbb4d82289fac1/crypto/smc-envelope/SmartContract.h#L75
mName := make([]byte, 8)
crc := uint64(crc16.Checksum([]byte(method), crc16.CCITTFalseTable)) | 0x10000
crc := uint64(crc16.Checksum([]byte(method), crc16.MakeTable(crc16.CRC16_XMODEM))) | 0x10000
binary.LittleEndian.PutUint64(mName, crc)
data = append(data, mName...)

Expand Down

0 comments on commit a2f2d13

Please sign in to comment.