From 6dda3ff03b7171449c926227936b196dd153d402 Mon Sep 17 00:00:00 2001 From: bianyuanop Date: Mon, 30 Dec 2024 16:33:21 -0500 Subject: [PATCH 1/3] auction update --- actions/auction.go | 20 +++++++++++++++----- go.mod | 2 +- go.sum | 4 ---- rpc/jsonrpc_server.go | 4 ++++ scripts/run.sh | 6 +++++- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/actions/auction.go b/actions/auction.go index 524a128..9052271 100644 --- a/actions/auction.go +++ b/actions/auction.go @@ -2,6 +2,7 @@ package actions import ( "context" + "crypto/sha256" "encoding/binary" "fmt" @@ -25,6 +26,14 @@ type AuctionInfo struct { BuilderSEQAddress codec.Address `json:"builderSEQAddress"` } +func (a *AuctionInfo) HashAuctionInfo() ([32]byte, error) { + msg := binary.BigEndian.AppendUint64(nil, a.EpochNumber) + msg = binary.BigEndian.AppendUint64(msg, a.BidPrice) + msg = append(msg, a.BuilderSEQAddress[:]...) + hash := sha256.Sum256(msg) + return hash, nil +} + func (info *AuctionInfo) Marshal(p *codec.Packer) { p.PackUint64(info.EpochNumber) p.PackUint64(info.BidPrice) @@ -90,17 +99,18 @@ func (a *Auction) Execute( return nil, fmt.Errorf("failed to parse public key: %w", err) } - msg := make([]byte, 16) - binary.BigEndian.PutUint64(msg[:8], a.AuctionInfo.EpochNumber) - binary.BigEndian.PutUint64(msg[8:], a.AuctionInfo.BidPrice) - msg = append(msg, a.AuctionInfo.BuilderSEQAddress[:]...) + digest, err := a.AuctionInfo.HashAuctionInfo() + if err != nil { + return nil, fmt.Errorf("unable to hash auction info") + } + sig, err := bls.SignatureFromBytes(a.BuilderSignature) if err != nil { return nil, fmt.Errorf("failed to parse signature: %w", err) } // Verify the signature. - if !bls.Verify(msg, pubkey, sig) { + if !bls.Verify(digest[:], pubkey, sig) { return nil, ErrInvalidBidderSignature } diff --git a/go.mod b/go.mod index 25f24fa..910cccc 100644 --- a/go.mod +++ b/go.mod @@ -173,4 +173,4 @@ require ( // replace github.com/ava-labs/coreth => github.com/AnomalyFi/coreth v0.12.5-rc.6.1 -// replace github.com/AnomalyFi/hypersdk => ../hypersdk +replace github.com/AnomalyFi/hypersdk => ../hypersdk diff --git a/go.sum b/go.sum index ea75598..c4e7b93 100644 --- a/go.sum +++ b/go.sum @@ -39,10 +39,6 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= -github.com/AnomalyFi/hypersdk v0.9.7-arcadia.13 h1:jZJXZpW6gQkfH0draUp5fQLwCfKzRYhNLHDxz33ncOs= -github.com/AnomalyFi/hypersdk v0.9.7-arcadia.13/go.mod h1:0Vj2PdwSFN7pat4Sno39IfmtOiv/gO9mxZXyRKnoKtI= -github.com/AnomalyFi/hypersdk v0.9.7-arcadia.14 h1:mDlxazNtWWHV4sb+j9G/Aw6DW4WA1zcNLM2B6ZoYA8s= -github.com/AnomalyFi/hypersdk v0.9.7-arcadia.14/go.mod h1:0Vj2PdwSFN7pat4Sno39IfmtOiv/gO9mxZXyRKnoKtI= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= diff --git a/rpc/jsonrpc_server.go b/rpc/jsonrpc_server.go index 8b5f12e..ae5eb97 100644 --- a/rpc/jsonrpc_server.go +++ b/rpc/jsonrpc_server.go @@ -399,6 +399,10 @@ func (j *JSONRPCServer) GetRollupInfo(req *http.Request, args *types.GetRollupIn if err != nil { return err } + if info == nil { + return fmt.Errorf("not such rollup in state") + } + reply.Info = *info return nil } diff --git a/scripts/run.sh b/scripts/run.sh index 1d2f2b5..7c6440b 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -136,11 +136,15 @@ find "${TMPDIR}"/avalanchego-"${VERSION}" # if you are starting your own devnet (otherwise anyone can access # funds using the included demo.pk) # Sum of balances should be less than max uint64. +# total stake can allocate: 10000000000000000000, make sure it is below this or genesis won't load +# builder address: seq1qxg2p2au72mweweuyu3dx8dhla6gyky630azwsvnc69tvg0m6qx9uqms9wx +# opnode address: seq1qy94dndd0wzru9gvq3ayw52ngcd2fuhyptt58f4a3eppjzpx573qg9cr7sm echo "creating allocations file" cat < "${TMPDIR}"/allocations.json [ {"address":"${ADDRESS}", "balance":1000000000000000000}, - {"address":"seq1qy94dndd0wzru9gvq3ayw52ngcd2fuhyptt58f4a3eppjzpx573qg9cr7sm", "balance":1000000000000000000} + {"address":"seq1qy94dndd0wzru9gvq3ayw52ngcd2fuhyptt58f4a3eppjzpx573qg9cr7sm", "balance":1000000000000000000}, + {"address":"seq1qxg2p2au72mweweuyu3dx8dhla6gyky630azwsvnc69tvg0m6qx9uqms9wx", "balance":1000000000000000000} ] EOF From 074b7c4a4948547b7a631308b23aaa0b3865116c Mon Sep 17 00:00:00 2001 From: bianyuanop Date: Wed, 8 Jan 2025 13:53:53 -0500 Subject: [PATCH 2/3] rollup registration, CreateRollup works for creation & update --- actions/rollup_register.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/actions/rollup_register.go b/actions/rollup_register.go index 29b6f6c..9a575c8 100644 --- a/actions/rollup_register.go +++ b/actions/rollup_register.go @@ -70,16 +70,25 @@ func (r *RollupRegistration) Execute( switch r.OpCode { case CreateRollup: - if contains(namespaces, r.Namespace) { - return nil, ErrNameSpaceAlreadyRegistered + if !contains(namespaces, r.Namespace) { + namespaces = append(namespaces, r.Namespace) + } else { + // only allow modifing informations that are not related to ExitEpoch or StartEpoch + if err := authorizationChecks(ctx, actor, namespaces, r.Namespace, mu); err != nil { + return nil, fmt.Errorf("authorization failed: %s", err.Error()) + } } if r.Info.StartEpoch < Epoch(hght, rules.GetEpochLength())+2 || r.Info.ExitEpoch != 0 { return nil, fmt.Errorf("epoch number is not valid, minimum: %d, actual: %d, exit: %d", Epoch(hght, rules.GetEpochLength())+2, r.Info.StartEpoch, r.Info.ExitEpoch) } - namespaces = append(namespaces, r.Namespace) + if r.Info.ExitEpoch != 0 { + return nil, fmt.Errorf("exit epoch not 0") + } + if err := storage.SetRollupInfo(ctx, mu, r.Namespace, &r.Info); err != nil { return nil, fmt.Errorf("unable to set rollup info(CREATE): %w", err) } + // TODO: not useful as CreateRollup now handle both creation and update case UpdateRollup: // only allow modifing informations that are not related to ExitEpoch or StartEpoch if err := authorizationChecks(ctx, actor, namespaces, r.Namespace, mu); err != nil { From 2cd08f322fd30815c1a91832d3284f6cc1ef04ba Mon Sep 17 00:00:00 2001 From: bianyuanop Date: Thu, 9 Jan 2025 09:35:29 -0500 Subject: [PATCH 3/3] update --- actions/rollup_register.go | 1 - go.mod | 4 ++-- go.sum | 2 ++ scripts/run.sh | 1 - 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/actions/rollup_register.go b/actions/rollup_register.go index 9a575c8..69298c7 100644 --- a/actions/rollup_register.go +++ b/actions/rollup_register.go @@ -88,7 +88,6 @@ func (r *RollupRegistration) Execute( if err := storage.SetRollupInfo(ctx, mu, r.Namespace, &r.Info); err != nil { return nil, fmt.Errorf("unable to set rollup info(CREATE): %w", err) } - // TODO: not useful as CreateRollup now handle both creation and update case UpdateRollup: // only allow modifing informations that are not related to ExitEpoch or StartEpoch if err := authorizationChecks(ctx, actor, namespaces, r.Namespace, mu); err != nil { diff --git a/go.mod b/go.mod index 910cccc..12e286e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/AnomalyFi/nodekit-seq go 1.21.12 require ( - github.com/AnomalyFi/hypersdk v0.9.7-arcadia.14 + github.com/AnomalyFi/hypersdk v0.9.7-arcadia.15 github.com/ava-labs/avalanche-network-runner v1.7.4-rc.0 github.com/ava-labs/avalanchego v1.11.10 github.com/ethereum/go-ethereum v1.13.14 @@ -173,4 +173,4 @@ require ( // replace github.com/ava-labs/coreth => github.com/AnomalyFi/coreth v0.12.5-rc.6.1 -replace github.com/AnomalyFi/hypersdk => ../hypersdk +// replace github.com/AnomalyFi/hypersdk => ../hypersdk diff --git a/go.sum b/go.sum index c4e7b93..6402b08 100644 --- a/go.sum +++ b/go.sum @@ -39,6 +39,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= +github.com/AnomalyFi/hypersdk v0.9.7-arcadia.15 h1:GKRJZn4O4+1HZID5uLzkUCSmfQ/he4zrQ3drPhuVfWQ= +github.com/AnomalyFi/hypersdk v0.9.7-arcadia.15/go.mod h1:0Vj2PdwSFN7pat4Sno39IfmtOiv/gO9mxZXyRKnoKtI= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= diff --git a/scripts/run.sh b/scripts/run.sh index 7c6440b..b9b4641 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -136,7 +136,6 @@ find "${TMPDIR}"/avalanchego-"${VERSION}" # if you are starting your own devnet (otherwise anyone can access # funds using the included demo.pk) # Sum of balances should be less than max uint64. -# total stake can allocate: 10000000000000000000, make sure it is below this or genesis won't load # builder address: seq1qxg2p2au72mweweuyu3dx8dhla6gyky630azwsvnc69tvg0m6qx9uqms9wx # opnode address: seq1qy94dndd0wzru9gvq3ayw52ngcd2fuhyptt58f4a3eppjzpx573qg9cr7sm echo "creating allocations file"