-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Trajan0x <[email protected]>
- Loading branch information
Showing
28 changed files
with
4,931 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3,443 changes: 3,443 additions & 0 deletions
3,443
core/contracts/attestationcollector/attestationcollector.abigen.go
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
core/contracts/attestationcollector/attestationcollector.contractinfo.json
Large diffs are not rendered by default.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
core/contracts/attestationcollector/attestationcollector.metadata.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package attestationcollector | ||
|
||
//go:generate go run github.com/synapsecns/sanguine/tools/abigen generate --sol ../../../packages/contracts/flattened/AttestationCollector.sol --pkg attestationcollector --sol-version 0.8.13 --filename attestationcollector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package attestationcollector | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/vm" | ||
) | ||
|
||
// AttestationCollectorRef is a bound attestatoin collector contract that returns the address of the attestation collector contract. | ||
//nolint: golint | ||
type AttestationCollectorRef struct { | ||
*AttestationCollector | ||
address common.Address | ||
} | ||
|
||
// Address gets the address of the attestation contract. | ||
func (a AttestationCollectorRef) Address() common.Address { | ||
return a.address | ||
} | ||
|
||
// NewAttestationCollectorRef creates an attestation contract with a contract ref. | ||
func NewAttestationCollectorRef(address common.Address, backend bind.ContractBackend) (*AttestationCollectorRef, error) { | ||
attestationContract, err := NewAttestationCollector(address, backend) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &AttestationCollectorRef{ | ||
AttestationCollector: attestationContract, | ||
address: address, | ||
}, nil | ||
} | ||
|
||
var _ vm.ContractRef = AttestationCollectorRef{} |
848 changes: 848 additions & 0 deletions
848
core/contracts/test/attestationharness/attestationharness.abigen.go
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
core/contracts/test/attestationharness/attestationharness.contractinfo.json
Large diffs are not rendered by default.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
core/contracts/test/attestationharness/attestationharness.metadata.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package attestationharness | ||
|
||
//go:generate go run github.com/synapsecns/sanguine/tools/abigen generate --sol ../../../../packages/contracts/flattened/AttestationHarness.sol --pkg attestationharness --sol-version 0.8.13 --filename attestationharness | ||
// line after go:generate cannot be left blank |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package attestationharness | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/vm" | ||
) | ||
|
||
// AttestationHarnessRef is an attestation harness reference | ||
//nolint: golint | ||
type AttestationHarnessRef struct { | ||
*AttestationHarness | ||
address common.Address | ||
} | ||
|
||
// Address gets the address of the contract. | ||
func (a AttestationHarnessRef) Address() common.Address { | ||
return a.address | ||
} | ||
|
||
// NewAttestationHarnessRef creates a new attestation harness. | ||
func NewAttestationHarnessRef(address common.Address, backend bind.ContractBackend) (*AttestationHarnessRef, error) { | ||
contract, err := NewAttestationHarness(address, backend) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not create home harness: %w", err) | ||
} | ||
|
||
return &AttestationHarnessRef{ | ||
AttestationHarness: contract, | ||
address: address, | ||
}, nil | ||
} | ||
|
||
var _ vm.ContractRef = &AttestationHarnessRef{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package evm | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/synapsecns/sanguine/core/contracts/attestationcollector" | ||
"github.com/synapsecns/sanguine/core/domains" | ||
"github.com/synapsecns/sanguine/core/types" | ||
"github.com/synapsecns/sanguine/ethergo/signer/nonce" | ||
"github.com/synapsecns/sanguine/ethergo/signer/signer" | ||
"github.com/synapsecns/synapse-node/pkg/evm" | ||
) | ||
|
||
// NewAttestationCollectorContract returns a bound attestation collector contract. | ||
func NewAttestationCollectorContract(ctx context.Context, client evm.Chain, attestationAddress common.Address) (domains.AttestationCollectorContract, error) { | ||
boundCountract, err := attestationcollector.NewAttestationCollectorRef(attestationAddress, client) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not create %T: %w", &attestationcollector.AttestationCollectorRef{}, err) | ||
} | ||
|
||
nonceManager := nonce.NewNonceManager(ctx, client, client.GetBigChainID()) | ||
return attestationCollectorContract{ | ||
contract: boundCountract, | ||
client: client, | ||
nonceManager: nonceManager, | ||
}, nil | ||
} | ||
|
||
type attestationCollectorContract struct { | ||
// contract contains the conract handle | ||
contract *attestationcollector.AttestationCollectorRef | ||
// client contains the evm client | ||
client evm.Chain | ||
// nonceManager is the nonce manager used for transacting with the chain | ||
nonceManager nonce.Manager | ||
} | ||
|
||
// SubmitAttestation submits an attestation to the attestation collector. | ||
func (a attestationCollectorContract) SubmitAttestation(signer signer.Signer, attestation types.SignedAttestation) error { | ||
transactor, err := signer.GetTransactor(a.client.GetBigChainID()) | ||
if err != nil { | ||
return fmt.Errorf("could not sign tx: %w", err) | ||
} | ||
|
||
transactOpts, err := a.nonceManager.NewKeyedTransactor(transactor) | ||
if err != nil { | ||
return fmt.Errorf("could not create tx: %w", err) | ||
} | ||
|
||
encodedAttestation, err := types.EncodeSignedAttestation(attestation) | ||
if err != nil { | ||
return fmt.Errorf("could not get signed attestations: %w", err) | ||
} | ||
|
||
_, err = a.contract.SubmitAttestation(transactOpts, transactOpts.From, encodedAttestation) | ||
if err != nil { | ||
return fmt.Errorf("could not submit attestation: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package evm_test | ||
|
||
import ( | ||
"github.com/brianvoe/gofakeit/v6" | ||
"github.com/ethereum/go-ethereum/common" | ||
. "github.com/stretchr/testify/assert" | ||
"github.com/synapsecns/sanguine/core/agents/updater" | ||
pebble2 "github.com/synapsecns/sanguine/core/db/datastore/pebble" | ||
"github.com/synapsecns/sanguine/core/domains/evm" | ||
"github.com/synapsecns/sanguine/core/types" | ||
"math/big" | ||
) | ||
|
||
func (i ContractSuite) TestSubmitAttestation() { | ||
attestionCollector, err := evm.NewAttestationCollectorContract(i.GetTestContext(), i.attestationBackend, i.attestationContract.Address()) | ||
Nil(i.T(), err) | ||
|
||
localDomain := attestationDomain | ||
nonce := gofakeit.Uint32() | ||
root := common.BigToHash(new(big.Int).SetUint64(gofakeit.Uint64())) | ||
|
||
unsignedAttestation := types.NewAttestation(uint32(localDomain), nonce, root) | ||
hashedAttestation, err := updater.HashAttestation(unsignedAttestation) | ||
Nil(i.T(), err) | ||
|
||
signature, err := i.signer.SignMessage(i.GetTestContext(), pebble2.ToSlice(hashedAttestation), false) | ||
Nil(i.T(), err) | ||
|
||
signedAttestation := types.NewSignedAttestation(unsignedAttestation, signature) | ||
|
||
err = attestionCollector.SubmitAttestation(i.signer, signedAttestation) | ||
Nil(i.T(), err) | ||
|
||
// TODO retrieve once we have a way to | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.